Skip to main content
Dublin Library

The Publishing Project

Plugin Topics: Adding Plugin Admin Pages

 

If we want to allow users to configure our plugin, we can add menus to the admin pages either as a top-level menu or a submenu of an existing menu. When used with the settings and options APIs we get control of how users configure the plugin from the admin area, assuming that they have permission to do so. ## Top Level Menus [Top-Level Menus](https://developer.wordpress.org/plugins/administration-menus/top-level-menus/) are what people see when they first view the admin area. This means that our admin page has more visibility but, depending on the plugin, it may be better to use a submenu The first step is to create a function that outputs the HTML. In this function, we will perform the necessary security checks and render the options we’ve registered using the Settings API. **Note:** Wrap your HTML using a `
` with a class of `wrap`. ```php

prefix}_options` table. You can add new sections on existing pages using [add\_settings\_section()](https://developer.wordpress.org/reference/functions/add_settings_section/). You can add new fields to existing sections using [add\_settings\_field()](https://developer.wordpress.org/reference/functions/add_settings_field/). **Alert:** `register_setting()` as well `add_settings_*()` functions should be added to the `admin_init` action hook. This is a full example of settings: ```php Rivendellweb Section Introduction.

'; } // field content cb function rivendellweb_settings_field_callback() { $setting = get_option('rivendellweb_setting_name'); ?> prefix}_options` table. `$wpdb->prefix` is defined by the `$table_prefix` variable set in the wp-config.php file. ### How Options are Stored? Options may be stored in the WordPress database in one of two ways: as a single value or as an array of values. #### Single Value When saved as a single value, the option name refers to a single value. ```php 'hello world!', 1, false ); // add a new option add_option('rivendellweb_custom_option', $data_r); // get an option $options_r = get_option('rivendellweb_custom_option'); // output the title echo esc_html($options_r['title']); ``` #### Available functions The following functions are available as part of the Options API. The difference between the `*_site_option` functions and their plain counterparts is that the `site` functions are meant for WordPress multi site networks where the other ones are meant for individual sites. * Add Option * [add\_option()](https://developer.wordpress.org/reference/functions/add_option/) * [add\_site\_option](https://developer.wordpress.org/reference/functions/add_site_option/) * Get Option * [get\_ottion()](https://developer.wordpress.org/reference/functions/get_option/) * [get\_site\_option()](https://developer.wordpress.org/reference/functions/get_site_option/) * Update Option * [update\_option()](https://developer.wordpress.org/reference/functions/update_option/) * [update\_site\_option()](https://developer.wordpress.org/reference/functions/update_site_option/) * Delete Option * [delete\_option()](https://developer.wordpress.org/reference/functions/delete_option/) * [delete\_site\_option()](https://developer.wordpress.org/reference/functions/delete_site_option/)

Edit on Github