One of the many great uses for the WordPress REST API is improving your plugin or theme settings screens. Once you add custom REST API endpoints, getting saved settings via AJAX and saving it via AJAX — IE with no additional page loads — is simpler. Using the WordPress REST API instead of admin-ajax is not only more performant but also lets WordPress core do most of the heavy lifting in terms of sanitization and validation.
In this article, we will walk through each of the steps to create a settings form page and process that form using the WordPress REST API.
Adding Your Settings Page
Before we can get started designing our settings page, we will need to add a menu or submenu item to the WordPress dashboard that you can put a settings form on. On this page, you will need to load CSS and JavaScript files.
Here is a starter class for that:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<?phpclass Apex_Menu {/** * Menu slug * * @var string */protected $slug = ‘apex-menu’;/** * URL for assets * * @var string */protected $assets_url;/** * Apex_Menu constructor. * * @param string
Source: https://managewp.org/articles/15397/creating-a-wordpress-settings-page-using-the-wordpress-rest-api
source https://williechiu40.wordpress.com/2017/06/23/creating-a-wordpress-settings-page-using-the-wordpress-rest-api/
No comments:
Post a Comment