Edit: Q缩小到以下范围:
“如何一次检索所有管理UI屏幕的屏幕ID?”
<小时>Edit: 我添加了更多的全局插件。
<小时>Q 是否如下:检查which AdminUI submenu page/screen you\'re viewing 检查一下这个against some global var or some internal function.
// This helps you inspecting the data - just drop it in some functions.php file of a theme
function wpse_inspect_admin_screen_data()
{
echo \'<pre>\';
echo \'<h3>global <code>$menu</code></h3>\';
print_r( $GLOBALS[\'menu\'] );
echo \'<hr />\';
echo \'<h3>global <code>$submenu</code></h3>\';
print_r( $GLOBALS[\'submenu\'] );
echo \'<hr />\';
echo \'<h3>global <code>$self</code></h3>\';
print_r( $GLOBALS[\'self\'] );
echo \'<hr />\';
echo \'<h3>global <code>$parent_file</code></h3>\';
print_r( $GLOBALS[\'parent_file\'] );
echo \'<hr />\';
echo \'<h3>global <code>$submenu_file</code></h3>\';
print_r( $GLOBALS[\'submenu_file\'] );
echo \'<hr />\';
echo \'<h3>global <code>$plugin_page</code></h3>\';
print_r( $GLOBALS[\'plugin_page\'] );
echo \'<hr />\';
echo \'<h3>global <code>$admin_page_hooks</code></h3>\';
print_r( $GLOBALS[\'admin_page_hooks\'] );
echo \'<hr />\';
echo \'<h3>global <code>$_parent_pages</code></h3>\';
print_r( $GLOBALS[\'_parent_pages\'] );
echo \'<hr />\';
echo \'<h3>global <code>$_registered_pages</code></h3>\';
print_r( $GLOBALS[\'_registered_pages\'] );
echo \'<hr />\';
echo \'<h3>global <code>$title</code></h3>\';
print_r( $GLOBALS[\'title\'] );
echo \'<hr />\';
echo \'<h3>global <code>$_wp_real_parent_file</code></h3>\';
print_r( $GLOBALS[\'_wp_real_parent_file\'] );
echo \'<hr />\';
echo \'<h3>global <code>$_wp_menu_nopriv</code></h3>\';
print_r( $GLOBALS[\'_wp_menu_nopriv\'] );
echo \'<hr />\';
echo \'<h3>global <code>$_wp_submenu_nopriv</code></h3>\';
print_r( $GLOBALS[\'_wp_submenu_nopriv\'] );
echo \'<hr />\';
// built by set_current_screen() in /core_root/wp-admin/includes/template.php line 2085 (wp 3.2.x)
echo \'<h3>global <code>$current_screen</code></h3>\';
print_r( $GLOBALS[\'current_screen\'] );
echo \'<pre>\';
}
add_action( \'shutdown\', \'wpse_inspect_admin_screen_data\', 9999 );
我已经有了一个数组,其中包含父菜单项和子菜单项中的slug和Label。在这里,您可以看到我构建的阵列的一个示例部分
global $menu, $submenu;
我需要核对一下:
Array
(
[Appearance] => Array
(
[0] => Array
(
[label] => Themes
[slug] => themes.php
[parent_label] => Appearance
[parent_file] => themes.php
)
[1] => Array
(
[label] => Widgets
[slug] => widgets.php
[parent_label] => Appearance
[parent_file] => themes.php
)
[2] => Array
(
[label] => Editor
[slug] => theme-editor.php
[parent_label] => Appearance
[parent_file] => themes.php
)
)
[Pages] => Array
(
[0] => Array
(
[label] => All Pages
[slug] => edit.php?post_type=page
[parent_label] => Pages
[parent_file] => edit.php?post_type=page
)
[1] => Array
(
[label] => Add New
[slug] => post-new.php?post_type=page
[parent_label] => Pages
[parent_file] => edit.php?post_type=page
)
)
)
<小时>
Note: Q不是循环。我只能使用什么来检查当前正在查看的菜单项和子项。
SO网友:Rarst
由于管理菜单本身知道如何显示您所在的位置,因此查看负责该逻辑的代码是合理的。
菜单输出由生成_wp_menu_output()
in menu-header.php
. 它利用了全局变量的数量,即:
global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow;
实际的逻辑非常广泛,对于本机页面和插件页面自然会有所不同。查找的作业
\'current\'
到CSS类及其周围。