author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 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 |
*/ |
|
14 |
$self = preg_replace('|^.*/wp-admin/network/|i', '', $_SERVER['PHP_SELF']); |
|
15 |
$self = preg_replace('|^.*/wp-admin/|i', '', $self); |
|
16 |
$self = preg_replace('|^.*/plugins/|i', '', $self); |
|
17 |
$self = preg_replace('|^.*/mu-plugins/|i', '', $self); |
|
18 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* For when admin-header is included from within a function. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @global array $menu |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* @global array $submenu |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
* @global string $parent_file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
* @global string $submenu_file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
27 |
global $menu, $submenu, $parent_file, $submenu_file; |
5 | 28 |
|
29 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
30 |
* Filters the parent file of an admin menu sub-menu item. |
5 | 31 |
* |
32 |
* Allows plugins to move sub-menu items around. |
|
33 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* @since MU (3.0.0) |
5 | 35 |
* |
36 |
* @param string $parent_file The parent file. |
|
37 |
*/ |
|
38 |
$parent_file = apply_filters( 'parent_file', $parent_file ); |
|
0 | 39 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
* Filters the file of an admin menu sub-menu item. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
* @since 4.4.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
44 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
* @param string $submenu_file The submenu file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
46 |
* @param string $parent_file The submenu item's parent file. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
$submenu_file = apply_filters( 'submenu_file', $submenu_file, $parent_file ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
|
0 | 50 |
get_admin_page_parent(); |
51 |
||
52 |
/** |
|
53 |
* Display menu. |
|
54 |
* |
|
55 |
* @access private |
|
56 |
* @since 2.7.0 |
|
57 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
58 |
* @global string $self |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
* @global string $parent_file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
* @global string $submenu_file |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @global string $plugin_page |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* @global string $typenow |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* |
0 | 64 |
* @param array $menu |
65 |
* @param array $submenu |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
* @param bool $submenu_as_parent |
0 | 67 |
*/ |
68 |
function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) { |
|
69 |
global $self, $parent_file, $submenu_file, $plugin_page, $typenow; |
|
70 |
||
71 |
$first = true; |
|
5 | 72 |
// 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes, 5 = hookname, 6 = icon_url |
0 | 73 |
foreach ( $menu as $key => $item ) { |
74 |
$admin_is_parent = false; |
|
75 |
$class = array(); |
|
76 |
$aria_attributes = ''; |
|
5 | 77 |
$aria_hidden = ''; |
78 |
$is_separator = false; |
|
0 | 79 |
|
80 |
if ( $first ) { |
|
81 |
$class[] = 'wp-first-item'; |
|
82 |
$first = false; |
|
83 |
} |
|
84 |
||
5 | 85 |
$submenu_items = array(); |
0 | 86 |
if ( ! empty( $submenu[$item[2]] ) ) { |
87 |
$class[] = 'wp-has-submenu'; |
|
88 |
$submenu_items = $submenu[$item[2]]; |
|
89 |
} |
|
90 |
||
91 |
if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
if ( ! empty( $submenu_items ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
$class[] = 'wp-has-current-submenu wp-menu-open'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
95 |
$class[] = 'current'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
96 |
$aria_attributes .= 'aria-current="page"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
} |
0 | 98 |
} else { |
99 |
$class[] = 'wp-not-current-submenu'; |
|
100 |
if ( ! empty( $submenu_items ) ) |
|
101 |
$aria_attributes .= 'aria-haspopup="true"'; |
|
102 |
} |
|
103 |
||
104 |
if ( ! empty( $item[4] ) ) |
|
5 | 105 |
$class[] = esc_attr( $item[4] ); |
0 | 106 |
|
107 |
$class = $class ? ' class="' . join( ' ', $class ) . '"' : ''; |
|
108 |
$id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : ''; |
|
5 | 109 |
$img = $img_style = ''; |
110 |
$img_class = ' dashicons-before'; |
|
111 |
||
112 |
if ( false !== strpos( $class, 'wp-menu-separator' ) ) { |
|
113 |
$is_separator = true; |
|
114 |
} |
|
115 |
||
116 |
/* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
117 |
* If the string 'none' (previously 'div') is passed instead of a URL, don't output |
5 | 118 |
* the default menu image so an icon can be added to div.wp-menu-image as background |
119 |
* with CSS. Dashicons and base64-encoded data:image/svg_xml URIs are also handled |
|
120 |
* as special cases. |
|
121 |
*/ |
|
122 |
if ( ! empty( $item[6] ) ) { |
|
123 |
$img = '<img src="' . $item[6] . '" alt="" />'; |
|
124 |
||
125 |
if ( 'none' === $item[6] || 'div' === $item[6] ) { |
|
126 |
$img = '<br />'; |
|
127 |
} elseif ( 0 === strpos( $item[6], 'data:image/svg+xml;base64,' ) ) { |
|
128 |
$img = '<br />'; |
|
129 |
$img_style = ' style="background-image:url(\'' . esc_attr( $item[6] ) . '\')"'; |
|
130 |
$img_class = ' svg'; |
|
131 |
} elseif ( 0 === strpos( $item[6], 'dashicons-' ) ) { |
|
132 |
$img = '<br />'; |
|
133 |
$img_class = ' dashicons-before ' . sanitize_html_class( $item[6] ); |
|
134 |
} |
|
135 |
} |
|
0 | 136 |
$arrow = '<div class="wp-menu-arrow"><div></div></div>'; |
137 |
||
138 |
$title = wptexturize( $item[0] ); |
|
139 |
||
5 | 140 |
// hide separators from screen readers |
141 |
if ( $is_separator ) { |
|
142 |
$aria_hidden = ' aria-hidden="true"'; |
|
143 |
} |
|
0 | 144 |
|
5 | 145 |
echo "\n\t<li$class$id$aria_hidden>"; |
146 |
||
147 |
if ( $is_separator ) { |
|
0 | 148 |
echo '<div class="separator"></div>'; |
149 |
} elseif ( $submenu_as_parent && ! empty( $submenu_items ) ) { |
|
150 |
$submenu_items = array_values( $submenu_items ); // Re-index. |
|
151 |
$menu_hook = get_plugin_page_hook( $submenu_items[0][2], $item[2] ); |
|
152 |
$menu_file = $submenu_items[0][2]; |
|
153 |
if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) |
|
154 |
$menu_file = substr( $menu_file, 0, $pos ); |
|
155 |
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $submenu_items[0][2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) { |
|
156 |
$admin_is_parent = true; |
|
5 | 157 |
echo "<a href='admin.php?page={$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>$title</div></a>"; |
0 | 158 |
} else { |
5 | 159 |
echo "\n\t<a href='{$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>$title</div></a>"; |
0 | 160 |
} |
161 |
} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) { |
|
162 |
$menu_hook = get_plugin_page_hook( $item[2], 'admin.php' ); |
|
163 |
$menu_file = $item[2]; |
|
164 |
if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) |
|
165 |
$menu_file = substr( $menu_file, 0, $pos ); |
|
166 |
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $item[2] ) && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) ) { |
|
167 |
$admin_is_parent = true; |
|
5 | 168 |
echo "\n\t<a href='admin.php?page={$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>"; |
0 | 169 |
} else { |
5 | 170 |
echo "\n\t<a href='{$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>"; |
0 | 171 |
} |
172 |
} |
|
173 |
||
174 |
if ( ! empty( $submenu_items ) ) { |
|
175 |
echo "\n\t<ul class='wp-submenu wp-submenu-wrap'>"; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
echo "<li class='wp-submenu-head' aria-hidden='true'>{$item[0]}</li>"; |
0 | 177 |
|
178 |
$first = true; |
|
5 | 179 |
|
180 |
// 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes |
|
0 | 181 |
foreach ( $submenu_items as $sub_key => $sub_item ) { |
182 |
if ( ! current_user_can( $sub_item[1] ) ) |
|
183 |
continue; |
|
184 |
||
185 |
$class = array(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
$aria_attributes = ''; |
0 | 187 |
if ( $first ) { |
188 |
$class[] = 'wp-first-item'; |
|
189 |
$first = false; |
|
190 |
} |
|
191 |
||
192 |
$menu_file = $item[2]; |
|
193 |
||
194 |
if ( false !== ( $pos = strpos( $menu_file, '?' ) ) ) |
|
195 |
$menu_file = substr( $menu_file, 0, $pos ); |
|
196 |
||
197 |
// Handle current for post_type=post|page|foo pages, which won't match $self. |
|
198 |
$self_type = ! empty( $typenow ) ? $self . '?post_type=' . $typenow : 'nothing'; |
|
199 |
||
200 |
if ( isset( $submenu_file ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
if ( $submenu_file == $sub_item[2] ) { |
0 | 202 |
$class[] = 'current'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
$aria_attributes .= ' aria-current="page"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
} |
0 | 205 |
// If plugin_page is set the parent must either match the current page or not physically exist. |
206 |
// This allows plugin pages with the same hook to exist under different parents. |
|
5 | 207 |
} elseif ( |
0 | 208 |
( ! isset( $plugin_page ) && $self == $sub_item[2] ) || |
209 |
( isset( $plugin_page ) && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) ) |
|
210 |
) { |
|
211 |
$class[] = 'current'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
$aria_attributes .= ' aria-current="page"'; |
0 | 213 |
} |
214 |
||
5 | 215 |
if ( ! empty( $sub_item[4] ) ) { |
216 |
$class[] = esc_attr( $sub_item[4] ); |
|
217 |
} |
|
218 |
||
0 | 219 |
$class = $class ? ' class="' . join( ' ', $class ) . '"' : ''; |
220 |
||
221 |
$menu_hook = get_plugin_page_hook($sub_item[2], $item[2]); |
|
222 |
$sub_file = $sub_item[2]; |
|
223 |
if ( false !== ( $pos = strpos( $sub_file, '?' ) ) ) |
|
224 |
$sub_file = substr($sub_file, 0, $pos); |
|
225 |
||
226 |
$title = wptexturize($sub_item[0]); |
|
227 |
||
228 |
if ( ! empty( $menu_hook ) || ( ( 'index.php' != $sub_item[2] ) && file_exists( WP_PLUGIN_DIR . "/$sub_file" ) && ! file_exists( ABSPATH . "/wp-admin/$sub_file" ) ) ) { |
|
229 |
// If admin.php is the current page or if the parent exists as a file in the plugins or admin dir |
|
230 |
if ( ( ! $admin_is_parent && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! is_dir( WP_PLUGIN_DIR . "/{$item[2]}" ) ) || file_exists( $menu_file ) ) |
|
231 |
$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), $item[2] ); |
|
232 |
else |
|
233 |
$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' ); |
|
234 |
||
235 |
$sub_item_url = esc_url( $sub_item_url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
236 |
echo "<li$class><a href='$sub_item_url'$class$aria_attributes>$title</a></li>"; |
0 | 237 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
echo "<li$class><a href='{$sub_item[2]}'$class$aria_attributes>$title</a></li>"; |
0 | 239 |
} |
240 |
} |
|
241 |
echo "</ul>"; |
|
242 |
} |
|
243 |
echo "</li>"; |
|
244 |
} |
|
245 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
echo '<li id="collapse-menu" class="hide-if-no-js">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
'<button type="button" id="collapse-button" aria-label="' . esc_attr__( 'Collapse Main menu' ) . '" aria-expanded="true">' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
'<span class="collapse-button-icon" aria-hidden="true"></span>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
'<span class="collapse-button-label">' . __( 'Collapse menu' ) . '</span>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
'</button></li>'; |
0 | 251 |
} |
252 |
||
253 |
?> |
|
254 |
||
5 | 255 |
<div id="adminmenumain" role="navigation" aria-label="<?php esc_attr_e( 'Main menu' ); ?>"> |
256 |
<a href="#wpbody-content" class="screen-reader-shortcut"><?php _e( 'Skip to main content' ); ?></a> |
|
257 |
<a href="#wp-toolbar" class="screen-reader-shortcut"><?php _e( 'Skip to toolbar' ); ?></a> |
|
0 | 258 |
<div id="adminmenuback"></div> |
259 |
<div id="adminmenuwrap"> |
|
5 | 260 |
<ul id="adminmenu"> |
0 | 261 |
|
262 |
<?php |
|
263 |
||
264 |
_wp_menu_output( $menu, $submenu ); |
|
5 | 265 |
/** |
266 |
* Fires after the admin menu has been output. |
|
267 |
* |
|
268 |
* @since 2.5.0 |
|
269 |
*/ |
|
0 | 270 |
do_action( 'adminmenu' ); |
271 |
||
272 |
?> |
|
273 |
</ul> |
|
274 |
</div> |
|
5 | 275 |
</div> |