3 * Displays Administration Menu.
6 * @subpackage Administration
12 * @global string $self
16 $self = preg_replace('|^.*/wp-admin/|i', '', $_SERVER['PHP_SELF']);
17 $self = preg_replace('|^.*/plugins/|i', '', $self);
19 global $menu, $submenu, $parent_file; //For when admin-header is included from within a function.
21 get_admin_page_parent();
30 * @param array $submenu
31 * @param bool $submenu_as_parent
33 function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
34 global $self, $parent_file, $submenu_file, $plugin_page, $pagenow;
37 // 0 = name, 1 = capability, 2 = file, 3 = class, 4 = id, 5 = icon src
38 foreach ( $menu as $key => $item ) {
39 $admin_is_parent = false;
42 $class[] = 'wp-first-item';
45 if ( !empty($submenu[$item[2]]) )
46 $class[] = 'wp-has-submenu';
48 if ( ( $parent_file && $item[2] == $parent_file ) || strcmp($self, $item[2]) == 0 ) {
49 if ( !empty($submenu[$item[2]]) )
50 $class[] = 'wp-has-current-submenu wp-menu-open';
55 if ( isset($item[4]) && ! empty($item[4]) )
58 $class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
59 $tabindex = ' tabindex="1"';
60 $id = isset($item[5]) && ! empty($item[5]) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
62 if ( isset($item[6]) && ! empty($item[6]) ) {
63 if ( 'div' === $item[6] )
64 $img = '<div class="wp-menu-image"><br /></div>';
66 $img = '<img class="wp-menu-image" src="' . $item[6] . '" alt="" />';
68 $toggle = '<div class="wp-menu-toggle"><br /></div>';
70 echo "\n\t<li$class$id>";
72 if ( false !== strpos($class, 'wp-menu-separator') ) {
74 } elseif ( $submenu_as_parent && !empty($submenu[$item[2]]) ) {
75 $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
76 $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
77 if ( ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") && ('index.php' != $submenu[$item[2]][0][2]) ) || !empty($menu_hook)) {
78 $admin_is_parent = true;
79 echo "$img$toggle<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class$tabindex>{$item[0]}</a>";
81 echo "\n\t$img$toggle<a href='{$submenu[$item[2]][0][2]}'$class$tabindex>{$item[0]}</a>";
83 } else if ( current_user_can($item[1]) ) {
84 $menu_hook = get_plugin_page_hook($item[2], 'admin.php');
85 if ( file_exists(WP_PLUGIN_DIR . "/{$item[2]}") || !empty($menu_hook) ) {
86 $admin_is_parent = true;
87 echo "\n\t$img$toggle<a href='admin.php?page={$item[2]}'$class$tabindex>{$item[0]}</a>";
89 echo "\n\t$img$toggle<a href='{$item[2]}'$class$tabindex>{$item[0]}</a>";
93 if ( !empty($submenu[$item[2]]) ) {
94 echo "\n\t<div class='wp-submenu'><div class='wp-submenu-head'>{$item[0]}</div><ul>";
96 foreach ( $submenu[$item[2]] as $sub_key => $sub_item ) {
97 if ( !current_user_can($sub_item[1]) )
102 $class[] = 'wp-first-item';
105 if ( isset($submenu_file) ) {
106 if ( $submenu_file == $sub_item[2] )
107 $class[] = 'current';
108 // If plugin_page is set the parent must either match the current page or not physically exist.
109 // This allows plugin pages with the same hook to exist under different parents.
110 } else if ( (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($item[2]) || ($item[2] == $self))) || (!isset($plugin_page) && $self == $sub_item[2]) ) {
111 $class[] = 'current';
114 $class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
116 $menu_hook = get_plugin_page_hook($sub_item[2], $item[2]);
118 if ( ( file_exists(WP_PLUGIN_DIR . "/{$sub_item[2]}") && ('index.php' != $sub_item[2]) ) || ! empty($menu_hook) ) {
119 // If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
120 $parent_exists = (!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/{$item[2]}") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}") ) || file_exists($item[2]);
121 if ( $parent_exists )
122 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
123 elseif ( 'admin.php' == $pagenow || !$parent_exists )
124 echo "<li$class><a href='admin.php?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
126 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
128 echo "<li$class><a href='{$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
143 _wp_menu_output( $menu, $submenu );
144 do_action( 'adminmenu' );