WordPress函数文档add_object_page()
后台管理界面中添加自定义页面 描述 Add a top level menu page at the ‘obj…
后台管理界面中添加自定义页面
描述
Add a top level menu page at the ‘object’ level. This new menu will appear in the group including the default WordPress Posts, Media, Links, Pages and Comments.
Specifically, creates a new top level menu section in the admin menu sidebar and registers a hook to callback your function for outputting the page content when the linked menu page is requested. Returns the $hookname.
This essentially does the exact same thing as add_menu_page(), but checks (and increments) the $_wp_last_object_menu global variable to add the menu item to the last position in the menu items. So, if $_wp_last_object_menu has already been incremented to 25, this call to add_object_page() will send 26 in the $position argument to the add_menu_page() function.
用法
<?php
add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url );
?>
参数
$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 on-screen name text for the menu.
默认值: None
$capability
(string) (必填) The capability required for this menu to be displayed to the user. User levels are deprecated and should not be used here!
默认值: None
$menu_slug
(string) (必填) The slug name to refer to this menu by (should be unique for this menu). Prior to Version 3.0 this was called the file (or handle) parameter. If the function parameter is omitted, the menu_slug should be the PHP file that handles the display of the menu page content.
默认值: None
$function
The function that displays the page content for the menu page. Technically, the function parameter is optional, but if it is not supplied, then WordPress will basically assume that including the PHP file will generate the administration screen, without calling a function. Most plugin authors choose to put the page-generating code in a function within their main plugin file.:In the event that the function parameter is specified, it is possible to use any string for the file parameter. This allows usage of pages such as ?page=my_super_plugin_page instead of ?page=my-super-plugin/admin-options.php.
The function must be referenced in one of two ways:
- if the function is a member of a class within the plugin it should be referenced as array( $this, ‘function_name’ ),
- in all other cases, using the function name itself is sufficient.
$icon_url
(string) (可选) The url to the icon to be used for this menu. This parameter is optional. Icons should be fairly small, around 20 x 20 pixels (?). You can use the WP_CONTENT_URL constant to help point to an image contained in your plugin folder.
默认值:
返回值
string
$hookname used internally to track menu page callbacks for outputting the page inside the global $menu array
注意
This function takes a ‘capability’ (see Roles and Capabilities) 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.
源文件
add_object_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
24
25
26
27
28
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* Add a top level menu page in the ‘objects’ section
*
* 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.
*
* @global int $_wp_last_object_menu
*
* @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.
* @param string $icon_url The url to the icon to be used for this menu
*
* @return string The resulting page’s hook_suffix
*/
function add_object_page( $page_title, $menu_title, $capability, $menu_slug, $function = ”, $icon_url = ”) {
global $_wp_last_object_menu;
$_wp_last_object_menu++;
return add_menu_page($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $_wp_last_object_menu);
}
|
- 原文:http://codex.wordpress.org/Function_Reference/add_object_page
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!