mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Displays Administration Menu.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /**
mp-wp_genesis 10 * The current page.
mp-wp_genesis 11 *
mp-wp_genesis 12 * @global string $self
mp-wp_genesis 13 * @name $self
mp-wp_genesis 14 * @var string
mp-wp_genesis 15 */
mp-wp_genesis 16 $self = preg_replace('|^.*/wp-admin/|i', '', $_SERVER['PHP_SELF']);
mp-wp_genesis 17 $self = preg_replace('|^.*/plugins/|i', '', $self);
mp-wp_genesis 18
mp-wp_genesis 19 global $menu, $submenu, $parent_file; //For when admin-header is included from within a function.
mp-wp_genesis 20
mp-wp_genesis 21 get_admin_page_parent();
mp-wp_genesis 22
mp-wp_genesis 23 /**
mp-wp_genesis 24 * Display menu.
mp-wp_genesis 25 *
mp-wp_genesis 26 * @access private
mp-wp_genesis 27 * @since 2.7.0
mp-wp_genesis 28 *
mp-wp_genesis 29 * @param array $menu
mp-wp_genesis 30 * @param array $submenu
mp-wp_genesis 31 * @param bool $submenu_as_parent
mp-wp_genesis 32 */
mp-wp_genesis 33 function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
mp-wp_genesis 34 global $self, $parent_file, $submenu_file, $plugin_page, $pagenow;
mp-wp_genesis 35
mp-wp_genesis 36 $first = true;
mp-wp_genesis 37 // 0 = name, 1 = capability, 2 = file, 3 = class, 4 = id, 5 = icon src
mp-wp_genesis 38 foreach ( $menu as $key => $item ) {
mp-wp_genesis 39 $admin_is_parent = false;
mp-wp_genesis 40 $class = array();
mp-wp_genesis 41 if ( $first ) {
mp-wp_genesis 42 $class[] = 'wp-first-item';
mp-wp_genesis 43 $first = false;
mp-wp_genesis 44 }
mp-wp_genesis 45 if ( !empty($submenu[$item[2]]) )
mp-wp_remove-all-... 46 $class[] = 'wp-has-submenu wp-menu-open';
mp-wp_genesis 47
mp-wp_genesis 48 if ( ( $parent_file && $item[2] == $parent_file ) || strcmp($self, $item[2]) == 0 ) {
mp-wp_genesis 49 if ( !empty($submenu[$item[2]]) )
mp-wp_genesis 50 $class[] = 'wp-has-current-submenu wp-menu-open';
mp-wp_genesis 51 else
mp-wp_genesis 52 $class[] = 'current';
mp-wp_genesis 53 }
mp-wp_genesis 54
mp-wp_genesis 55 if ( isset($item[4]) && ! empty($item[4]) )
mp-wp_genesis 56 $class[] = $item[4];
mp-wp_genesis 57
mp-wp_genesis 58 $class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
mp-wp_genesis 59 $tabindex = ' tabindex="1"';
mp-wp_genesis 60 $id = isset($item[5]) && ! empty($item[5]) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : '';
mp-wp_genesis 61 $img = '';
mp-wp_genesis 62
mp-wp_genesis 63 echo "\n\t<li$class$id>";
mp-wp_genesis 64
mp-wp_genesis 65 if ( false !== strpos($class, 'wp-menu-separator') ) {
mp-wp_remove-all-... 66 echo '';
mp-wp_genesis 67 } elseif ( $submenu_as_parent && !empty($submenu[$item[2]]) ) {
mp-wp_genesis 68 $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
mp-wp_genesis 69 $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
mp-wp_genesis 70 if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook)) {
mp-wp_genesis 71 $admin_is_parent = true;
mp-wp_remove-all-... 72 echo "$img<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class$tabindex>{$item[0]}</a>";
mp-wp_genesis 73 } else {
mp-wp_remove-all-... 74 echo "\n\t$img<a href='{$submenu[$item[2]][0][2]}'$class$tabindex>{$item[0]}</a>";
mp-wp_genesis 75 }
mp-wp_genesis 76 } else if ( current_user_can($item[1]) ) {
mp-wp_genesis 77 $menu_hook = get_plugin_page_hook($item[2], 'admin.php');
mp-wp_genesis 78 if ( file_exists(WP_PLUGIN_DIR . "/{$item[2]}") || !empty($menu_hook) ) {
mp-wp_genesis 79 $admin_is_parent = true;
mp-wp_remove-all-... 80 echo "\n\t$img<a href='admin.php?page={$item[2]}'$class$tabindex>{$item[0]}</a>";
mp-wp_genesis 81 } else {
mp-wp_remove-all-... 82 echo "\n\t$img<a href='{$item[2]}'$class$tabindex>{$item[0]}</a>";
mp-wp_genesis 83 }
mp-wp_genesis 84 }
mp-wp_genesis 85
mp-wp_genesis 86 if ( !empty($submenu[$item[2]]) ) {
mp-wp_remove-all-... 87 echo "\n\t<div class='wp-submenu'><ul>";
mp-wp_genesis 88 $first = true;
mp-wp_genesis 89 foreach ( $submenu[$item[2]] as $sub_key => $sub_item ) {
mp-wp_genesis 90 if ( !current_user_can($sub_item[1]) )
mp-wp_genesis 91 continue;
mp-wp_genesis 92
mp-wp_genesis 93 $class = array();
mp-wp_genesis 94 if ( $first ) {
mp-wp_genesis 95 $class[] = 'wp-first-item';
mp-wp_genesis 96 $first = false;
mp-wp_genesis 97 }
mp-wp_genesis 98 if ( isset($submenu_file) ) {
mp-wp_genesis 99 if ( $submenu_file == $sub_item[2] )
mp-wp_genesis 100 $class[] = 'current';
mp-wp_genesis 101 // If plugin_page is set the parent must either match the current page or not physically exist.
mp-wp_genesis 102 // This allows plugin pages with the same hook to exist under different parents.
mp-wp_genesis 103 } else if ( (isset($plugin_page) && $plugin_page == $sub_item[2] && (!file_exists($item[2]) || ($item[2] == $self))) || (!isset($plugin_page) && $self == $sub_item[2]) ) {
mp-wp_genesis 104 $class[] = 'current';
mp-wp_genesis 105 }
mp-wp_genesis 106
mp-wp_genesis 107 $class = $class ? ' class="' . join( ' ', $class ) . '"' : '';
mp-wp_genesis 108
mp-wp_genesis 109 $menu_hook = get_plugin_page_hook($sub_item[2], $item[2]);
mp-wp_genesis 110
mp-wp_genesis 111 if ( file_exists(WP_PLUGIN_DIR . "/{$sub_item[2]}") || ! empty($menu_hook) ) {
mp-wp_genesis 112 // If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
mp-wp_genesis 113 $parent_exists = (!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/{$item[2]}") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}") ) || file_exists($item[2]);
mp-wp_genesis 114 if ( $parent_exists )
mp-wp_genesis 115 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
mp-wp_genesis 116 elseif ( 'admin.php' == $pagenow || !$parent_exists )
mp-wp_genesis 117 echo "<li$class><a href='admin.php?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
mp-wp_genesis 118 else
mp-wp_genesis 119 echo "<li$class><a href='{$item[2]}?page={$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
mp-wp_genesis 120 } else {
mp-wp_genesis 121 echo "<li$class><a href='{$sub_item[2]}'$class$tabindex>{$sub_item[0]}</a></li>";
mp-wp_genesis 122 }
mp-wp_genesis 123 }
mp-wp_genesis 124 echo "</ul></div>";
mp-wp_genesis 125 }
mp-wp_genesis 126 echo "</li>";
mp-wp_genesis 127 }
mp-wp_genesis 128 }
mp-wp_genesis 129
mp-wp_genesis 130 ?>
mp-wp_genesis 131
mp-wp_genesis 132 <ul id="adminmenu">
mp-wp_genesis 133
mp-wp_genesis 134 <?php
mp-wp_genesis 135
mp-wp_genesis 136 _wp_menu_output( $menu, $submenu );
mp-wp_genesis 137 do_action( 'adminmenu' );
mp-wp_genesis 138
mp-wp_genesis 139 ?>