WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Function Reference/add options page"

(OO Usage: - deleted)
m (renamed Example to Examples)
Line 31: Line 31:
 
* The function handling the output of the options page should also verify the user's capabilities.
 
* The function handling the output of the options page should also verify the user's capabilities.
   
== Example ==
+
== Examples ==
   
 
Typical usage occurs in a function registered with the '[[Action_Reference#Actions_Run_During_an_Admin_Page_Request|admin_menu]]' hook (see [[Adding Administration Menus]]):
 
Typical usage occurs in a function registered with the '[[Action_Reference#Actions_Run_During_an_Admin_Page_Request|admin_menu]]' hook (see [[Adding Administration Menus]]):

Revision as of 12:04, 4 December 2012

This article is a ROUGH DRAFT. The author is still working on this document, so please do not edit this without the author's permission. The content within this article may not yet be verified or valid. This information is subject to change.

Description

Add sub menu page to the Settings menu.

Usage

 <?php
add_options_page
$page_title$menu_title$capability$menu_slug$function);
?> 

Parameters

$page_title
(string) (required) The text to be displayed in the title tags of the page when the menu is selected
Default: None
$menu_title
(string) (required) The text to be used for the menu
Default: None
$capability
(string) (required) The capability required for this menu to be displayed to the user.
Default: None
$menu_slug
(string) (required) The slug name to refer to this menu by (should be unique for this menu).
Default: None
$function
(callback) (optional) The function to be called to output the content for this page.
Default: ' '

Return Values

string 
The resulting page's hook_suffix (What add_submenu_page() returns)

Notes

  • This function is a simple wrapper for a call to add_submenu_page(), passing the received arguments and specifying 'options-general.php' as the $parent_slug argument. This means the new options page will be added as a sub menu to the Settings menu.
  • The $capability parameter is used to determine whether or not the page is included in the menu based on the Roles and Capabilities) of the current user.
  • The function handling the output of the options page should also verify the user's capabilities.

Examples

Typical usage occurs in a function registered with the 'admin_menu' hook (see Adding Administration Menus):

add_action('admin_menu', 'my_plugin_menu');

function my_plugin_menu() {
	add_options_page('My Options', 'My Plugin', 'manage_options', 'my-plugin.php', 'my_plugin_page');
}


Object Oriented options page helper / view:

class options_page {
	function __construct() {
		add_action('admin_menu', array(&$this, 'admin_menu'));
	}
	function admin_menu () {
		add_options_page('Page Title','Circle Tree Login','manage_options','options_page_slug',array($this, 'settings_page'));
	}
	function  settings_page () {
		echo 'This is the page content';
	}
}
new options_page;

Source File

add_options_page() is located in wp-admin/includes/plugin.php.

Related

Administration Menus: add_menu_page(), remove_menu_page(), add_submenu_page(), remove_submenu_page(), add_dashboard_page(), add_posts_page(), add_media_page(), add_links_page(), add_pages_page(), add_comments_page(), add_theme_page(), add_plugins_page(), add_users_page(), add_management_page(), add_options_page()

See also index of Function Reference and index of Template Tags.