Creating a WordPress settings page using the WordPress rest API

It is designed to provide the original translated (localized) strings in the browser. It is part of the method used to provide translatable success and error messages. However, it can also be used to pass the same dynamic value as the current site URL (in this case, rest API endpoint and nonce). JavaScript needs all this, but every site is different, so you must create it immediately using PHP. The
In addition, the root URL of the script is passed through the dependency of the class. Since this URL is likely to be used in other locations of the plug-in or theme, you like to perform this operation and want a location where you can change or filter the URL of the entire plug-in. When instantiating a class, you must specify its URL. Because the root plug-in file is the best place to do this, plugin\u dir\u url() will generate the correct URL. Let’s take a look at the main plug-in file for setting it: maleenqueue_assets();
? >
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male
Male \
\
);
\/**The
*Import saved settings
*The
*@Return array
*\/The
Public static function get\u settings(){
$saved = get\u option (self: $option\u key, array());
If (! Is_array ($saved) |! Empty ($saved){
Return self::$defaults;
}The
Return wp\u parse\u args ($saved, self:: $defaults);
}The
\/**The
*Save settings
*The
*The array key must be in the Allow List (ie must be the key of self::$defaults).
*The
*@Param array $settings
*\/The
Public static function save_settings (array $settings){
\/\/Delete disallowed indexes before saving.
Foreach ($settings as $i = > $setting){
If (! Array\u key\u exists ($setting, self:: $defaults)){
Not set ($set [$i]);
}The
}The
Update\u option (self: $option\u key, $settings);
}The
}The rest API path now has a way to read and write settings processed by all means, so we will create a rest API path that acts as a restful interface. This path has get and post endpoints. The
If you have never generated a custom rest API endpoint, it is best to read the manual. In addition, there is a filtered list of links, including theme torque articles and WordPress TV speeches. Rest API path classes are as follows: Male’post’,
\
\
\
\
\
‘sanitize_callback’= >’sanitize_text_field’
),
Amount = > array(
\
\
\
)The
),
\
)The
);
Register\u rest\u route (\
Sort(
\
\

Author:

Leave a Reply

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