| 1 | Index: wp-admin/menu-header.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- wp-admin/menu-header.php (revision 15079) |
|---|
| 4 | +++ wp-admin/menu-header.php (working copy) |
|---|
| 5 | @@ -34,7 +34,6 @@ |
|---|
| 6 | */ |
|---|
| 7 | function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { |
|---|
| 8 | global $self, $parent_file, $submenu_file, $plugin_page, $pagenow, $typenow; |
|---|
| 9 | - |
|---|
| 10 | $first = true; |
|---|
| 11 | // 0 = name, 1 = capability, 2 = file, 3 = class, 4 = id, 5 = icon src |
|---|
| 12 | foreach ( $menu as $key => $item ) { |
|---|
| 13 | @@ -44,16 +43,16 @@ |
|---|
| 14 | $class[] = 'wp-first-item'; |
|---|
| 15 | $first = false; |
|---|
| 16 | } |
|---|
| 17 | - if ( !empty($submenu[$item[2]]) ) |
|---|
| 18 | + // Assignment to speedup array index lookups throughout this iteration. |
|---|
| 19 | + $submenu_items = $submenu[$item[2]]; |
|---|
| 20 | + |
|---|
| 21 | + if ( !empty($submenu_items) ) |
|---|
| 22 | $class[] = 'wp-has-submenu'; |
|---|
| 23 | |
|---|
| 24 | if ( ( $parent_file && $item[2] == $parent_file ) || ( false === strpos($parent_file, '?') && $self == $item[2] ) ) { |
|---|
| 25 | - if ( !empty($submenu[$item[2]]) ) |
|---|
| 26 | - $class[] = 'wp-has-current-submenu wp-menu-open'; |
|---|
| 27 | - else |
|---|
| 28 | - $class[] = 'current'; |
|---|
| 29 | + $class[] = (!empty($submenu_items)) ? 'wp-has-current-submenu wp-menu-open' : 'current'; |
|---|
| 30 | } |
|---|
| 31 | - |
|---|
| 32 | + |
|---|
| 33 | if ( ! empty($item[4]) ) |
|---|
| 34 | $class[] = $item[4]; |
|---|
| 35 | |
|---|
| 36 | @@ -62,48 +61,45 @@ |
|---|
| 37 | $id = ! empty($item[5]) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : ''; |
|---|
| 38 | $img = ''; |
|---|
| 39 | if ( ! empty($item[6]) ) { |
|---|
| 40 | - if ( 'div' === $item[6] ) |
|---|
| 41 | - $img = '<br />'; |
|---|
| 42 | - else |
|---|
| 43 | - $img = '<img src="' . $item[6] . '" alt="" />'; |
|---|
| 44 | + $img = ('div' === $item[6]) ? '<br />' : '<img src="' . $item[6] . '" alt="" />'; |
|---|
| 45 | } |
|---|
| 46 | $toggle = '<div class="wp-menu-toggle"><br /></div>'; |
|---|
| 47 | |
|---|
| 48 | $title = wptexturize($item[0]); |
|---|
| 49 | |
|---|
| 50 | echo "\n\t<li$class$id>"; |
|---|
| 51 | - |
|---|
| 52 | if ( false !== strpos($class, 'wp-menu-separator') ) { |
|---|
| 53 | echo '<a class="separator" href="?unfoldmenu=1"><br /></a>'; |
|---|
| 54 | - } elseif ( $submenu_as_parent && !empty($submenu[$item[2]]) ) { |
|---|
| 55 | - $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index. |
|---|
| 56 | - $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]); |
|---|
| 57 | - $menu_file = $submenu[$item[2]][0][2]; |
|---|
| 58 | - if ( false !== $pos = strpos($menu_file, '?') ) |
|---|
| 59 | + } elseif ( $submenu_as_parent && !empty($submenu_items) ) { |
|---|
| 60 | + $submenu_items = array_values($submenu_items); // Re-index. |
|---|
| 61 | + $menu_hook = get_plugin_page_hook($submenu_items[0][2], $item[2]); |
|---|
| 62 | + $menu_file = $submenu_items[0][2]; |
|---|
| 63 | + if ( false !== ($pos = strpos($menu_file, '?')) ) |
|---|
| 64 | $menu_file = substr($menu_file, 0, $pos); |
|---|
| 65 | - if ( ( ('index.php' != $submenu[$item[2]][0][2]) && file_exists(WP_PLUGIN_DIR . "/$menu_file") ) || !empty($menu_hook)) { |
|---|
| 66 | + if ( !empty($menu_hook) || ('index.php' != $submenu_items[0][2] && file_exists(WP_PLUGIN_DIR . "/$menu_file")) ) { |
|---|
| 67 | $admin_is_parent = true; |
|---|
| 68 | - echo "<div class='wp-menu-image'><a href='admin.php?page={$submenu[$item[2]][0][2]}'>$img</a></div>$toggle<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class$tabindex>$title</a>"; |
|---|
| 69 | + echo "<div class='wp-menu-image'><a href='admin.php?page={$submenu_items[0][2]}'>$img</a></div>$toggle<a href='admin.php?page={$submenu_items[0][2]}'$class$tabindex>$title</a>"; |
|---|
| 70 | } else { |
|---|
| 71 | - echo "\n\t<div class='wp-menu-image'><a href='{$submenu[$item[2]][0][2]}'>$img</a></div>$toggle<a href='{$submenu[$item[2]][0][2]}'$class$tabindex>$title</a>"; |
|---|
| 72 | + echo "\n\t<div class='wp-menu-image'><a href='{$submenu_items[0][2]}'>$img</a></div>$toggle<a href='{$submenu_items[0][2]}'$class$tabindex>$title</a>"; |
|---|
| 73 | } |
|---|
| 74 | } else if ( current_user_can($item[1]) ) { |
|---|
| 75 | $menu_hook = get_plugin_page_hook($item[2], 'admin.php'); |
|---|
| 76 | $menu_file = $item[2]; |
|---|
| 77 | - if ( false !== $pos = strpos($menu_file, '?') ) |
|---|
| 78 | + if ( false !== ($pos = strpos($menu_file, '?')) ) |
|---|
| 79 | $menu_file = substr($menu_file, 0, $pos); |
|---|
| 80 | - if ( ('index.php' != $item[2]) && file_exists(WP_PLUGIN_DIR . "/$menu_file") || !empty($menu_hook) ) { |
|---|
| 81 | + if ( !empty($menu_hook) || ('index.php' != $menu_file) && file_exists(WP_PLUGIN_DIR . "/$menu_file") ) { |
|---|
| 82 | $admin_is_parent = true; |
|---|
| 83 | - echo "\n\t<div class='wp-menu-image'><a href='admin.php?page={$item[2]}'>$img</a></div>$toggle<a href='admin.php?page={$item[2]}'$class$tabindex>{$item[0]}</a>"; |
|---|
| 84 | + echo "\n\t<div class='wp-menu-image'><a href='admin.php?page={$menu_file}'>$img</a></div>$toggle<a href='admin.php?page={$menu_file}'$class$tabindex>{$item[0]}</a>"; |
|---|
| 85 | } else { |
|---|
| 86 | - echo "\n\t<div class='wp-menu-image'><a href='{$item[2]}'>$img</a></div>$toggle<a href='{$item[2]}'$class$tabindex>{$item[0]}</a>"; |
|---|
| 87 | + echo "\n\t<div class='wp-menu-image'><a href='{$menu_file}'>$img</a></div>$toggle<a href='{$menu_file}'$class$tabindex>{$item[0]}</a>"; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | - |
|---|
| 91 | - if ( !empty($submenu[$item[2]]) ) { |
|---|
| 92 | + if ( !empty($submenu_items) ) { |
|---|
| 93 | echo "\n\t<div class='wp-submenu'><div class='wp-submenu-head'>{$item[0]}</div><ul>"; |
|---|
| 94 | $first = true; |
|---|
| 95 | - foreach ( $submenu[$item[2]] as $sub_key => $sub_item ) { |
|---|
| 96 | + foreach ( $submenu_items as $sub_key => $sub_item ) { |
|---|
| 97 | + |
|---|
| 98 | + // If the current user cannot perform this action then skip it. |
|---|
| 99 | if ( !current_user_can($sub_item[1]) ) |
|---|
| 100 | continue; |
|---|
| 101 | |
|---|
| 102 | @@ -115,29 +111,31 @@ |
|---|
| 103 | |
|---|
| 104 | $menu_file = $item[2]; |
|---|
| 105 | |
|---|
| 106 | - if ( false !== $pos = strpos($menu_file, '?') ) |
|---|
| 107 | + if ( false !== ($pos = strpos($menu_file, '?')) ) |
|---|
| 108 | $menu_file = substr($menu_file, 0, $pos); |
|---|
| 109 | |
|---|
| 110 | // Handle current for post_type=post|page|foo pages, which won't match $self. |
|---|
| 111 | - if ( !empty($typenow) ) |
|---|
| 112 | - $self_type = $self . '?post_type=' . $typenow; |
|---|
| 113 | - else |
|---|
| 114 | - $self_type = 'nothing'; |
|---|
| 115 | + $self_type = ( !empty($typenow) ) ? $self . '?post_type=' . $typenow : 'nothing'; |
|---|
| 116 | |
|---|
| 117 | if ( isset($submenu_file) ) { |
|---|
| 118 | if ( $submenu_file == $sub_item[2] ) |
|---|
| 119 | $class[] = 'current'; |
|---|
| 120 | // If plugin_page is set the parent must either match the current page or not physically exist. |
|---|
| 121 | // This allows plugin pages with the same hook to exist under different parents. |
|---|
| 122 | - } else if ( (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($menu_file) || ($item[2] == $self) || ($item[2] == $self_type))) || (!isset($plugin_page) && $self == $sub_item[2]) ) { |
|---|
| 123 | - $class[] = 'current'; |
|---|
| 124 | - } |
|---|
| 125 | + } else if ( |
|---|
| 126 | + (!isset($plugin_page) && $self == $sub_item[2]) || |
|---|
| 127 | + (isset($plugin_page) |
|---|
| 128 | + && $plugin_page == $sub_item[2] |
|---|
| 129 | + && (($item[2] == $self_type) || ($item[2] == $self) || file_exists($menu_file) === false) |
|---|
| 130 | + )) { |
|---|
| 131 | + $class[] = 'current'; |
|---|
| 132 | + } |
|---|
| 133 | |
|---|
| 134 | $class = $class ? ' class="' . join( ' ', $class ) . '"' : ''; |
|---|
| 135 | |
|---|
| 136 | $menu_hook = get_plugin_page_hook($sub_item[2], $item[2]); |
|---|
| 137 | $sub_file = $sub_item[2]; |
|---|
| 138 | - if ( false !== $pos = strpos($sub_file, '?') ) |
|---|
| 139 | + if ( false !== ($pos = strpos($sub_file, '?')) ) |
|---|
| 140 | $sub_file = substr($sub_file, 0, $pos); |
|---|
| 141 | |
|---|
| 142 | $title = wptexturize($sub_item[0]); |
|---|
| 143 | @@ -148,6 +146,7 @@ |
|---|
| 144 | $sub_item_url = add_query_arg( array('page' => $sub_item[2]), $item[2] ); |
|---|
| 145 | else |
|---|
| 146 | $sub_item_url = add_query_arg( array('page' => $sub_item[2]), 'admin.php' ); |
|---|
| 147 | + |
|---|
| 148 | $sub_item_url = esc_url($sub_item_url); |
|---|
| 149 | echo "<li$class><a href='$sub_item_url'$class$tabindex>$title</a></li>"; |
|---|
| 150 | } else { |
|---|