Creating WordPress options page in Dashboard for your own plugin is quite simple. Generally it is used to set global preferences for your plugin which you want to let the users customise as per their requirement.

We will create a settings screen by creating a class as that is the simplest way of creating your own options page for your custom plugin.

It can be done in 5 simple steps

  1. Declare Class for the settings Page
  2. Add the page in the settings menu
  3. Register your settings
  4. Create the backend options
  5. Finally generate the options page

Here is the entire code

Now we will discuss each function in detail

First of all we have named our class as someCustomPluginSettings

The constructor just calls the add_admin_menu function and initialises the settings registration

Below function creates the admin page.

Here we need to provide

  • Title of the settings page
  • Capability (this decides who will get access to this page). manage_options means editors and above can access this page.
  • Slug of the page

Below function registers the settings variables, description on the settings page, etc. The most important variable here is some_custom_plugin_settings. We will be using this variable to reference our stored data using the settings screen.

Below function creates the HTML objects to store our data. Please note that each field uses the same reference i.e.

some_custom_plugin_settings and stores the data in array i.e.

some_custom_plugin_settings[‘setting_1’], etc

Below function just renders the options page in a form

 

 

Leave a Reply

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