Creating an Options Page in WordPress by Website Design London

The Settings API introduced the WordPress 2.7 version, this Setting API will be using for all of the option methods you use in this section. By the API you can make saving options in WordPress easy and secure so this is very powerful set of functions. The security checks also handled by this API so this is the major benefits of the Settings API, it means that you don’t need to include a nonce in your form.

For creation an option page the first thing is that the option page method to create is a unique option page for your top-level menu. When using the add_submenu_page() and add_menu_page() functions remembers that, you defined your menu item function name to display your options page. You need to create this function to display your options, for create an options page.

The first set up will your plugin menu:

Creating an Options Page in WordPress by Website Design London.
Creating an Options Page in WordPress by Website Design London.

In the preceding example that you’ve added a new Action hook for admin_init to execute your copw_register_settings() function, you can see in the following code:

<?php
function copw_register_settings() {
//register our settings
register_setting( ‘copw-settings-group’, ‘copw_options’,’copw_sanitize_options’ );
}?>

The Setting API’s register_setting() function using, define the option you are going to offer on your plugin options page. There are three options of your settings page, and all these option you are going to store those in a single options array, that why you only need to register a single setting here. The options group name is the first parameter. It is required a group name to identify all options in this set. And the second parameter is the actual option name and must be unique. Last and the third parameter is a callback function to sanitize the option values. At this stage you have registered your options, now you need to build your options page.

For this, you’ll create the copw_settings_page() function as called from your menu: