get_plugin_page_hook()
云策文档标注
概述
get_plugin_page_hook() 函数用于获取插件管理页面所附加的 Hook。它通过检查 Hook 是否有注册的动作来确定是否返回 Hook 名称或 null。
关键要点
- 函数返回插件管理页面的 Hook 名称,若无动作注册则返回 null。
- 接受两个必需参数:$plugin_page(插件页面 slug)和 $parent_page(父菜单 slug 或标准 WordPress 管理页面文件名)。
- 内部调用 get_plugin_page_hookname() 获取 Hook 名称,并使用 has_action() 检查动作注册状态。
代码示例
function get_plugin_page_hook( $plugin_page, $parent_page ) {
$hook = get_plugin_page_hookname( $plugin_page, $parent_page );
if ( has_action( $hook ) ) {
return $hook;
} else {
return null;
}
}注意事项
- 此函数自 WordPress 1.5.0 版本引入。
- 相关函数包括 get_plugin_page_hookname() 和 has_action(),用于获取 Hook 名称和检查动作注册。
- 被 get_admin_page_title() 和 _wp_menu_output() 等函数使用,用于管理页面标题和菜单显示。
原文内容
Gets the hook attached to the administrative page of a plugin.
Parameters
$plugin_pagestringrequired-
The slug name of the plugin page.
$parent_pagestringrequired-
The slug name for the parent menu (or the file name of a standard WordPress admin page).
Source
function get_plugin_page_hook( $plugin_page, $parent_page ) {
$hook = get_plugin_page_hookname( $plugin_page, $parent_page );
if ( has_action( $hook ) ) {
return $hook;
} else {
return null;
}
}
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |