函数原型
add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $callback = ”, string $icon_url = ”, int|float $position = null ): string
函数描述
Adds a top-level menu page.
是否弃用
未弃用
函数参数
-
$page_title
string
Required - The text to be displayed in the title tags of the page when the menu is selected.
-
$menu_title
string
Required - The text to be used for the menu.
-
$capability
string
Required - The capability required for this menu to be displayed to the user.
-
$menu_slug
string
Required - The slug name to refer to this menu by. Should be unique for this menu page and only include lowercase alphanumeric, dashes, and underscores characters to be compatible with sanitize_key() .
-
$callback
callable
Optional - The function to be called to output the content for this page.
Default:
'' -
$icon_url
string
Optional - The URL to the icon to be used for this menu.
- Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. This should begin with
'data:image/svg+xml;base64,'. - Pass the name of a Dashicons helper class to use a font icon, e.g.
'dashicons-chart-pie'. - Pass
'none'to leave div.wp-menu-image empty so an icon can be added via CSS.
Default:
'' - Pass a base64-encoded SVG using a data URI, which will be colored to match the color scheme. This should begin with
-
$position
int|float
Optional - The position in the menu order this item should appear.
Default:
null
函数返回值
string The resulting page’s hook_suffix.
函数位置
File: wp-admin/includes/plugin.php.
函数源码
// Register settings using the Settings API
function wpdocs_register_my_setting() {
register_setting( 'my-options-group', 'my-option-name', 'intval' );
}
add_action( 'admin_init', 'wpdocs_register_my_setting' );
// Modify capability
function wpdocs_my_page_capability( $capability ) {
return 'edit_others_posts';
}
add_filter( 'option_page_capability_my-options-group', 'wpdocs_my_page_capability' );源码链接
变更日志
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |

