author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
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 |
*/ |
|
9 | 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 ); |
|
0 | 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 |
19 | 62 |
* @global string $typenow The post type of the current screen. |
7
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; |
|
16 | 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; |
|
9 | 75 |
$class = array(); |
0 | 76 |
$aria_attributes = ''; |
9 | 77 |
$aria_hidden = ''; |
78 |
$is_separator = false; |
|
0 | 79 |
|
80 |
if ( $first ) { |
|
81 |
$class[] = 'wp-first-item'; |
|
9 | 82 |
$first = false; |
0 | 83 |
} |
84 |
||
5 | 85 |
$submenu_items = array(); |
9 | 86 |
if ( ! empty( $submenu[ $item[2] ] ) ) { |
87 |
$class[] = 'wp-has-submenu'; |
|
88 |
$submenu_items = $submenu[ $item[2] ]; |
|
0 | 89 |
} |
90 |
||
16 | 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 { |
9 | 95 |
$class[] = 'current'; |
7
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'; |
|
9 | 100 |
if ( ! empty( $submenu_items ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
$aria_attributes .= 'data-ariahaspopup'; |
9 | 102 |
} |
0 | 103 |
} |
104 |
||
9 | 105 |
if ( ! empty( $item[4] ) ) { |
5 | 106 |
$class[] = esc_attr( $item[4] ); |
9 | 107 |
} |
0 | 108 |
|
18 | 109 |
$class = $class ? ' class="' . implode( ' ', $class ) . '"' : ''; |
9 | 110 |
$id = ! empty( $item[5] ) ? ' id="' . preg_replace( '|[^a-zA-Z0-9_:.]|', '-', $item[5] ) . '"' : ''; |
16 | 111 |
$img = ''; |
112 |
$img_style = ''; |
|
5 | 113 |
$img_class = ' dashicons-before'; |
114 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
if ( str_contains( $class, 'wp-menu-separator' ) ) { |
5 | 116 |
$is_separator = true; |
117 |
} |
|
118 |
||
119 |
/* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
* If the string 'none' (previously 'div') is passed instead of a URL, don't output |
5 | 121 |
* the default menu image so an icon can be added to div.wp-menu-image as background |
122 |
* with CSS. Dashicons and base64-encoded data:image/svg_xml URIs are also handled |
|
123 |
* as special cases. |
|
124 |
*/ |
|
125 |
if ( ! empty( $item[6] ) ) { |
|
19 | 126 |
$img = '<img src="' . esc_url( $item[6] ) . '" alt="" />'; |
5 | 127 |
|
128 |
if ( 'none' === $item[6] || 'div' === $item[6] ) { |
|
129 |
$img = '<br />'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
} elseif ( str_starts_with( $item[6], 'data:image/svg+xml;base64,' ) ) { |
19 | 131 |
$img = '<br />'; |
132 |
// The value is base64-encoded data, so esc_attr() is used here instead of esc_url(). |
|
5 | 133 |
$img_style = ' style="background-image:url(\'' . esc_attr( $item[6] ) . '\')"'; |
134 |
$img_class = ' svg'; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
} elseif ( str_starts_with( $item[6], 'dashicons-' ) ) { |
9 | 136 |
$img = '<br />'; |
5 | 137 |
$img_class = ' dashicons-before ' . sanitize_html_class( $item[6] ); |
138 |
} |
|
139 |
} |
|
0 | 140 |
$arrow = '<div class="wp-menu-arrow"><div></div></div>'; |
141 |
||
142 |
$title = wptexturize( $item[0] ); |
|
143 |
||
9 | 144 |
// Hide separators from screen readers. |
5 | 145 |
if ( $is_separator ) { |
146 |
$aria_hidden = ' aria-hidden="true"'; |
|
147 |
} |
|
0 | 148 |
|
5 | 149 |
echo "\n\t<li$class$id$aria_hidden>"; |
150 |
||
151 |
if ( $is_separator ) { |
|
0 | 152 |
echo '<div class="separator"></div>'; |
153 |
} elseif ( $submenu_as_parent && ! empty( $submenu_items ) ) { |
|
154 |
$submenu_items = array_values( $submenu_items ); // Re-index. |
|
9 | 155 |
$menu_hook = get_plugin_page_hook( $submenu_items[0][2], $item[2] ); |
156 |
$menu_file = $submenu_items[0][2]; |
|
16 | 157 |
$pos = strpos( $menu_file, '?' ); |
158 |
||
159 |
if ( false !== $pos ) { |
|
0 | 160 |
$menu_file = substr( $menu_file, 0, $pos ); |
9 | 161 |
} |
16 | 162 |
|
163 |
if ( ! empty( $menu_hook ) |
|
164 |
|| ( ( 'index.php' !== $submenu_items[0][2] ) |
|
165 |
&& file_exists( WP_PLUGIN_DIR . "/$menu_file" ) |
|
166 |
&& ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) |
|
167 |
) { |
|
0 | 168 |
$admin_is_parent = true; |
18 | 169 |
echo "<a href='admin.php?page={$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style aria-hidden='true'>$img</div><div class='wp-menu-name'>$title</div></a>"; |
0 | 170 |
} else { |
18 | 171 |
echo "\n\t<a href='{$submenu_items[0][2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style aria-hidden='true'>$img</div><div class='wp-menu-name'>$title</div></a>"; |
0 | 172 |
} |
173 |
} elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) { |
|
174 |
$menu_hook = get_plugin_page_hook( $item[2], 'admin.php' ); |
|
175 |
$menu_file = $item[2]; |
|
16 | 176 |
$pos = strpos( $menu_file, '?' ); |
177 |
||
178 |
if ( false !== $pos ) { |
|
0 | 179 |
$menu_file = substr( $menu_file, 0, $pos ); |
9 | 180 |
} |
16 | 181 |
|
182 |
if ( ! empty( $menu_hook ) |
|
183 |
|| ( ( 'index.php' !== $item[2] ) |
|
184 |
&& file_exists( WP_PLUGIN_DIR . "/$menu_file" ) |
|
185 |
&& ! file_exists( ABSPATH . "/wp-admin/$menu_file" ) ) |
|
186 |
) { |
|
0 | 187 |
$admin_is_parent = true; |
18 | 188 |
echo "\n\t<a href='admin.php?page={$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style aria-hidden='true'>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>"; |
0 | 189 |
} else { |
18 | 190 |
echo "\n\t<a href='{$item[2]}'$class $aria_attributes>$arrow<div class='wp-menu-image$img_class'$img_style aria-hidden='true'>$img</div><div class='wp-menu-name'>{$item[0]}</div></a>"; |
0 | 191 |
} |
192 |
} |
|
193 |
||
194 |
if ( ! empty( $submenu_items ) ) { |
|
195 |
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
|
196 |
echo "<li class='wp-submenu-head' aria-hidden='true'>{$item[0]}</li>"; |
0 | 197 |
|
198 |
$first = true; |
|
5 | 199 |
|
16 | 200 |
// 0 = menu_title, 1 = capability, 2 = menu_slug, 3 = page_title, 4 = classes. |
0 | 201 |
foreach ( $submenu_items as $sub_key => $sub_item ) { |
9 | 202 |
if ( ! current_user_can( $sub_item[1] ) ) { |
0 | 203 |
continue; |
9 | 204 |
} |
0 | 205 |
|
9 | 206 |
$class = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$aria_attributes = ''; |
16 | 208 |
|
0 | 209 |
if ( $first ) { |
210 |
$class[] = 'wp-first-item'; |
|
9 | 211 |
$first = false; |
0 | 212 |
} |
213 |
||
214 |
$menu_file = $item[2]; |
|
16 | 215 |
$pos = strpos( $menu_file, '?' ); |
0 | 216 |
|
16 | 217 |
if ( false !== $pos ) { |
0 | 218 |
$menu_file = substr( $menu_file, 0, $pos ); |
9 | 219 |
} |
0 | 220 |
|
221 |
// Handle current for post_type=post|page|foo pages, which won't match $self. |
|
222 |
$self_type = ! empty( $typenow ) ? $self . '?post_type=' . $typenow : 'nothing'; |
|
223 |
||
224 |
if ( isset( $submenu_file ) ) { |
|
16 | 225 |
if ( $submenu_file === $sub_item[2] ) { |
9 | 226 |
$class[] = 'current'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
$aria_attributes .= ' aria-current="page"'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
230 |
* If plugin_page is set the parent must either match the current page or not physically exist. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
* This allows plugin pages with the same hook to exist under different parents. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
*/ |
5 | 233 |
} elseif ( |
16 | 234 |
( ! isset( $plugin_page ) && $self === $sub_item[2] ) |
235 |
|| ( isset( $plugin_page ) && $plugin_page === $sub_item[2] |
|
236 |
&& ( $item[2] === $self_type || $item[2] === $self || file_exists( $menu_file ) === false ) ) |
|
0 | 237 |
) { |
9 | 238 |
$class[] = 'current'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
239 |
$aria_attributes .= ' aria-current="page"'; |
0 | 240 |
} |
241 |
||
5 | 242 |
if ( ! empty( $sub_item[4] ) ) { |
243 |
$class[] = esc_attr( $sub_item[4] ); |
|
244 |
} |
|
245 |
||
18 | 246 |
$class = $class ? ' class="' . implode( ' ', $class ) . '"' : ''; |
0 | 247 |
|
9 | 248 |
$menu_hook = get_plugin_page_hook( $sub_item[2], $item[2] ); |
249 |
$sub_file = $sub_item[2]; |
|
16 | 250 |
$pos = strpos( $sub_file, '?' ); |
251 |
if ( false !== $pos ) { |
|
9 | 252 |
$sub_file = substr( $sub_file, 0, $pos ); |
253 |
} |
|
0 | 254 |
|
9 | 255 |
$title = wptexturize( $sub_item[0] ); |
0 | 256 |
|
16 | 257 |
if ( ! empty( $menu_hook ) |
258 |
|| ( ( 'index.php' !== $sub_item[2] ) |
|
259 |
&& file_exists( WP_PLUGIN_DIR . "/$sub_file" ) |
|
260 |
&& ! file_exists( ABSPATH . "/wp-admin/$sub_file" ) ) |
|
261 |
) { |
|
262 |
// If admin.php is the current page or if the parent exists as a file in the plugins or admin directory. |
|
9 | 263 |
if ( ( ! $admin_is_parent && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! is_dir( WP_PLUGIN_DIR . "/{$item[2]}" ) ) || file_exists( $menu_file ) ) { |
0 | 264 |
$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), $item[2] ); |
9 | 265 |
} else { |
0 | 266 |
$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' ); |
9 | 267 |
} |
0 | 268 |
|
269 |
$sub_item_url = esc_url( $sub_item_url ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
echo "<li$class><a href='$sub_item_url'$class$aria_attributes>$title</a></li>"; |
0 | 271 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
echo "<li$class><a href='{$sub_item[2]}'$class$aria_attributes>$title</a></li>"; |
0 | 273 |
} |
274 |
} |
|
9 | 275 |
echo '</ul>'; |
0 | 276 |
} |
9 | 277 |
echo '</li>'; |
0 | 278 |
} |
279 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
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
|
281 |
'<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
|
282 |
'<span class="collapse-button-icon" aria-hidden="true"></span>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
'<span class="collapse-button-label">' . __( 'Collapse menu' ) . '</span>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
'</button></li>'; |
0 | 285 |
} |
286 |
||
287 |
?> |
|
288 |
||
5 | 289 |
<div id="adminmenumain" role="navigation" aria-label="<?php esc_attr_e( 'Main menu' ); ?>"> |
290 |
<a href="#wpbody-content" class="screen-reader-shortcut"><?php _e( 'Skip to main content' ); ?></a> |
|
291 |
<a href="#wp-toolbar" class="screen-reader-shortcut"><?php _e( 'Skip to toolbar' ); ?></a> |
|
0 | 292 |
<div id="adminmenuback"></div> |
293 |
<div id="adminmenuwrap"> |
|
5 | 294 |
<ul id="adminmenu"> |
0 | 295 |
|
296 |
<?php |
|
297 |
||
298 |
_wp_menu_output( $menu, $submenu ); |
|
5 | 299 |
/** |
300 |
* Fires after the admin menu has been output. |
|
301 |
* |
|
302 |
* @since 2.5.0 |
|
303 |
*/ |
|
0 | 304 |
do_action( 'adminmenu' ); |
305 |
||
306 |
?> |
|
307 |
</ul> |
|
308 |
</div> |
|
5 | 309 |
</div> |