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