您可以使用get_current_screen()
要检查您所在的页面,请重定向到特定的管理页面。
get_current_screen()
返回屏幕对象,如
WP_Screen Object
(
[action] =>
[base] => dashboard
[columns:WP_Screen:private] => 0
[id] => dashboard
[in_admin:protected] => site
[is_network] =>
[is_user] =>
[parent_base] =>
[parent_file] =>
[post_type] =>
[taxonomy] =>
[_help_tabs:WP_Screen:private] => Array
(
)
[_help_sidebar:WP_Screen:private] =>
[_screen_reader_content:WP_Screen:private] => Array
(
)
[_options:WP_Screen:private] => Array
(
)
[_show_screen_options:WP_Screen:private] =>
[_screen_settings:WP_Screen:private] =>
)
您可以使用
base
识别页面基础的键!
示例:-
add_action(\'current_screen\', \'wpse_225416_redirect_admin_page\');
/**
* Redirect specific admin page
*/
function wpse_225416_redirect_admin_page() {
$my_current_screen = get_current_screen();
if (isset($my_current_screen->base) && $my_current_screen->base == \'about\') {
wp_redirect(admin_url());
exit();
}
}
使用
current_screen
钩,因为在那之前
get_current_screen()
将不返回任何内容。