WordPress函数文档add_options_page()
在后台管理界面的“设置”菜单下增加二级菜单 描述 Add sub menu page to the Setti…
在后台管理界面的“设置”菜单下增加二级菜单
描述
Add sub menu page to the Settings menu.
用法
<?php
add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
?>
参数
$page_title
(string) (必填) The text to be displayed in the title tags of the page when the menu is selected
默认值: None
$menu_title
(string) (必填) The text to be used for the menu
默认值: None
$capability
(string) (必填) The capability required for this menu to be displayed to the user.
默认值: None
$menu_slug
(string) (必填) The slug name to refer to this menu by (should be unique for this menu).
默认值: None
$function
(callback) (可选) The function to be called to output the content for this page.
默认值: ‘ ‘
返回值
string
The resulting page’s hook_suffix (What add_submenu_page() returns)
示例
Typical usage occurs in a function registered with the ‘admin_menu‘ hook (see Adding Administration Menus):
1
2
3
4
5
6
7
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
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;
|
注意
- 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.
- If there are spaces in the slug, then these will be stripped out when the URL is generated. This will result in an error message telling you that you do not have sufficient permissions to view the page.
源文件
add_options_page() 函数的代码位于 wp-admin/includes/plugin.php
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Add sub menu page to the options main menu.
*
* This function takes a capability which will be used to determine whether
* or not a page is included in the menu.
*
* The function which is hooked in to handle the output of the page must check
* that the user has the required capability as well.
*
* @param string $page_title The text to be displayed in the title tags of the page when the menu is selected
* @param string $menu_title The text to be used for the menu
* @param string $capability The capability required for this menu to be displayed to the user.
* @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
* @param callback $function The function to be called to output the content for this page.
*
* @return false|string The resulting page’s hook_suffix, or false if the user does not have the capability required.
*/
function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function = ” ) {
return add_submenu_page( ‘options-general.php’, $page_title, $menu_title, $capability, $menu_slug, $function );
}
|
相关
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()
- 原文:http://codex.wordpress.org/Function_Reference/add_options_page
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!