Angular\/ionic 1 How to use X and word press to build programmable web applications

Authors are advised to \
WordPress stakeholders know that changes have taken place, so the rest API has been included in the core since version 4.5. More than 50% of WordPress sites use the latest CMS version, but 30% of WordPress installations will stop below version 4.4. This number can only be reduced forward. It is safe to say that the rest API can be used on most word press sites. In addition, it should be noted that the WordPress rest API is well documented and can be used in the path related to the site domain by default. The
The second is angularjs and ionic 1 on the WordPress rest API. We will show you how to build a default PWA using X. The simple word press web site settings exposed by the environment setting and rest API will be skipped. Even if you don’t know how to do it, there are countless good tutorials that show how to do it. Instead, angular js\/ionic 1 is used. I will concentrate on setting up the X app. After developing many applications in this framework, we have created commercial tools that include the following: Documentation about setting up the environment and configuring the application. Compile applications, production, and testing. Coding standards and printing. Unit and end-to-end testing. Although it may not seem important at first, you can write consistent, maintainable code through a structured work environment. The
Our business district also includes gulp jobs for generating documents using changes, printing, transferring files, ngdoc, testing (between units and terminals) and observing production. This project assumes that nodejs, NPM, power, gulp, and ioniccli are installed globally. Here you can find the complete documentation on how to set preferences. Please follow the steps at the beginning. Application Structuring uses the feature specific folder structure recommended in John Papa’s style guide. But we added our own twist using ES6. The
All application files are located in the SRC folder that contains the following: App – for each module. A folder containing JS files (controllers, modules), HTML templates, and SCSS files. Assets – folders for static assets, such as images, JSON files, and application global styles (SCSS files). Index HTML – all files in the application starting point SRC will perform the default \
Applications are automatically loaded into the default browser when using ioniserve. We have also added a global configuration file (src\/app\/config.json) that allows you to change API endpoints and add paths to other assets, such as application flags, icons, and so on. The configuration attribute is src\/app\/main running on init. The window object attached to the JS file. Const fetchconfig = () = >{
Const $initinjector = angular Injector ([‘ng’]);
Const $http = $initinjector Get (‘$http
Ig ([‘$stateprovider’,’$urlrouterprovider’, ($stateprovider, $urlrouterprovider) = >{
$stateprovider
State (\
URL: \
Controller: \
Template URL: \
});
$urlrouterprovider Otherwise (\
}]); In the controller, use the API service to read the post category. Category{
Created by ($log, application API){
Const populate categories= = >{
This Categories= results;
};
Appticlesapi Findcategories ({hide_empty: 1})
Then (populatecatecategories)
Catch ($log.error);
}The
}The
Categories$ Inject = [‘$log’,’appticlesapi’];
Angular Module (\
Controller (\
Male
Male
Male
Male male
Male
Male
Male
Data validation in this example, we blindly believe that the API will provide the data we need in the form we need. In real life, this method may make the situation worse rapidly. Although we can’t let the API provide the information we want, it can ensure that the application will not run as expected and conflict in a tragic way. To this end, an authentication service is added to the application. The purpose of this service is to obtain the original data from the API and verify it. If the field is required or the format verification fails, an error will be returned. Check the post category as follows: Angular Module (‘apps.validation’)
Factory (‘appticlesvalidation’, appiclesvalidation);
\/**The
*@Ngdoc service
*@name appticles Validation Appticlesvalidation
*The
*A service used to validate data from the @description API.
*\/The
Functions apps validation(){
Services={
Validatecategories: validatecategories,
And
};
Return Service
\/**The
*@Ngdoc function
*@name appticles Validation Appticlesvalidation\validatecategories
*@methodof appticles Validation Appticlesvalidation
*@Description category data verification
*The
*@Return{array} array of class objects
*The
*{@ link https:\/\/developer.wordpress.org\/rest-api\/reference\/categories\/#list -Categorys}
*\/The
Function validatecategories (input){
If (corner.Isobject (input) & &! Angular Isarray (input){
If (angular.isdefined (input.data)){
If (input.data.length = = = 0){
Returns
}The
Let validatedcategories = input Data Map (\u checkonec
Module (\
Controller (\
Male >
Male
Male
Male
Male
Male
Male
Male
Male
Male male
Male
Male \/style CSS \
Male
Male
Window__ Appticles_bootstrap_data\u ={
Config_path: ‘male \/config Json’
};
Male
Male \/js\/bundle JS \
Male
Male
Male male
Male
As you can see, this is. CSS This is a very simple setup for loading JS files and theme configurations. Config to dynamically map the API path according to the website address. JSON file. It can also be converted to PHP files. To load the PWA dedicated to mobile visitors, you can use the add\u filter() method to create a plug-in. Whenever a supported device is detected, you can handle the mobile detection and change the default theme folder. Note – please note when adding wp\u head(), wp\u footer() and other WordPress methods to PWA topics. All word press plug-ins and components will use it as a hook to add their own data. The content contained in this way may conflict with the code, especially when discussing javascript based components. With just a few adjustments to web push notifications, offline mode and other PWA enabled JavaScript applications, you can get a good PWA score (about 50-60%) on Chrome’s Lighthouse plug-in. One of the adjustments is the manifest file, where you can add a link to the application icon and change some simple things, such as the browser navigation bar color. If you want to go further, you need to add a service worker for offline mode and web push notifications. Fortunately, web push notifications have become much easier recently. You can find a free word press plug-in to handle notifications. The most popular is the one signal plug-in. Add the manifest file to the topic and request user permission before sending the notification. Note that the browser ignores the second manifest file and merges it with the existing manifest file. To implement offline mode, it is recommended that you view the following: SW proche – offline pre caching of static assets \/ application shells. SW toolbox – offline cache for dynamic \/ runtime requests. Conclusion this article only provides the basic PWA that is helpful for startup. The code sample is a version that greatly simplifies its own PWA. The complete PWA can be seen here. A repository includes services for inserting advertisements into content and translating application text.
This is not the last time, but it includes unit tests using karma and jasmine and end-to-end tests using protractor. Building a \

Author:

Leave a Reply

Your email address will not be published. Required fields are marked *