author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Build Administration Menu. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
5 | 9 |
if ( is_network_admin() ) { |
10 |
||
11 |
/** |
|
12 |
* Fires before the administration menu loads in the Network Admin. |
|
13 |
* |
|
14 |
* The hook fires before menus and sub-menus are removed based on user privileges. |
|
15 |
* |
|
16 |
* @since 3.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
* @access private |
5 | 18 |
*/ |
19 |
do_action( '_network_admin_menu' ); |
|
20 |
} elseif ( is_user_admin() ) { |
|
21 |
||
22 |
/** |
|
23 |
* Fires before the administration menu loads in the User Admin. |
|
24 |
* |
|
25 |
* The hook fires before menus and sub-menus are removed based on user privileges. |
|
26 |
* |
|
27 |
* @since 3.1.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
* @access private |
5 | 29 |
*/ |
30 |
do_action( '_user_admin_menu' ); |
|
31 |
} else { |
|
32 |
||
33 |
/** |
|
34 |
* Fires before the administration menu loads in the admin. |
|
35 |
* |
|
36 |
* The hook fires before menus and sub-menus are removed based on user privileges. |
|
37 |
* |
|
38 |
* @since 2.2.0 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
39 |
* @access private |
5 | 40 |
*/ |
41 |
do_action( '_admin_menu' ); |
|
42 |
} |
|
0 | 43 |
|
44 |
// Create list of page plugin hook names. |
|
9 | 45 |
foreach ( $menu as $menu_page ) { |
16 | 46 |
$pos = strpos( $menu_page[2], '?' ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
|
16 | 48 |
if ( false !== $pos ) { |
0 | 49 |
// Handle post_type=post|page|foo pages. |
9 | 50 |
$hook_name = substr( $menu_page[2], 0, $pos ); |
51 |
$hook_args = substr( $menu_page[2], $pos + 1 ); |
|
52 |
wp_parse_str( $hook_args, $hook_args ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
|
0 | 54 |
// Set the hook name to be the post type. |
9 | 55 |
if ( isset( $hook_args['post_type'] ) ) { |
0 | 56 |
$hook_name = $hook_args['post_type']; |
9 | 57 |
} else { |
58 |
$hook_name = basename( $hook_name, '.php' ); |
|
59 |
} |
|
60 |
unset( $hook_args ); |
|
0 | 61 |
} else { |
9 | 62 |
$hook_name = basename( $menu_page[2], '.php' ); |
0 | 63 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
|
9 | 65 |
$hook_name = sanitize_title( $hook_name ); |
0 | 66 |
|
9 | 67 |
if ( isset( $compat[ $hook_name ] ) ) { |
68 |
$hook_name = $compat[ $hook_name ]; |
|
69 |
} elseif ( ! $hook_name ) { |
|
0 | 70 |
continue; |
9 | 71 |
} |
0 | 72 |
|
9 | 73 |
$admin_page_hooks[ $menu_page[2] ] = $hook_name; |
0 | 74 |
} |
9 | 75 |
unset( $menu_page, $compat ); |
0 | 76 |
|
77 |
$_wp_submenu_nopriv = array(); |
|
9 | 78 |
$_wp_menu_nopriv = array(); |
0 | 79 |
// Loop over submenus and remove pages for which the user does not have privs. |
9 | 80 |
foreach ( $submenu as $parent => $sub ) { |
81 |
foreach ( $sub as $index => $data ) { |
|
82 |
if ( ! current_user_can( $data[1] ) ) { |
|
83 |
unset( $submenu[ $parent ][ $index ] ); |
|
84 |
$_wp_submenu_nopriv[ $parent ][ $data[2] ] = true; |
|
0 | 85 |
} |
5 | 86 |
} |
9 | 87 |
unset( $index, $data ); |
0 | 88 |
|
9 | 89 |
if ( empty( $submenu[ $parent ] ) ) { |
90 |
unset( $submenu[ $parent ] ); |
|
91 |
} |
|
0 | 92 |
} |
9 | 93 |
unset( $sub, $parent ); |
0 | 94 |
|
5 | 95 |
/* |
96 |
* Loop over the top-level menu. |
|
97 |
* Menus for which the original parent is not accessible due to lack of privileges |
|
98 |
* will have the next submenu in line be assigned as the new menu parent. |
|
99 |
*/ |
|
0 | 100 |
foreach ( $menu as $id => $data ) { |
9 | 101 |
if ( empty( $submenu[ $data[2] ] ) ) { |
0 | 102 |
continue; |
9 | 103 |
} |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
|
9 | 105 |
$subs = $submenu[ $data[2] ]; |
106 |
$first_sub = reset( $subs ); |
|
0 | 107 |
$old_parent = $data[2]; |
108 |
$new_parent = $first_sub[2]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
|
5 | 110 |
/* |
111 |
* If the first submenu is not the same as the assigned parent, |
|
112 |
* make the first submenu the new parent. |
|
113 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
if ( $new_parent !== $old_parent ) { |
9 | 115 |
$_wp_real_parent_file[ $old_parent ] = $new_parent; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
$menu[ $id ][2] = $new_parent; |
0 | 118 |
|
9 | 119 |
foreach ( $submenu[ $old_parent ] as $index => $data ) { |
120 |
$submenu[ $new_parent ][ $index ] = $submenu[ $old_parent ][ $index ]; |
|
121 |
unset( $submenu[ $old_parent ][ $index ] ); |
|
0 | 122 |
} |
9 | 123 |
unset( $submenu[ $old_parent ], $index ); |
0 | 124 |
|
9 | 125 |
if ( isset( $_wp_submenu_nopriv[ $old_parent ] ) ) { |
126 |
$_wp_submenu_nopriv[ $new_parent ] = $_wp_submenu_nopriv[ $old_parent ]; |
|
127 |
} |
|
0 | 128 |
} |
129 |
} |
|
9 | 130 |
unset( $id, $data, $subs, $first_sub, $old_parent, $new_parent ); |
0 | 131 |
|
5 | 132 |
if ( is_network_admin() ) { |
133 |
||
134 |
/** |
|
135 |
* Fires before the administration menu loads in the Network Admin. |
|
136 |
* |
|
137 |
* @since 3.1.0 |
|
138 |
* |
|
139 |
* @param string $context Empty context. |
|
140 |
*/ |
|
141 |
do_action( 'network_admin_menu', '' ); |
|
142 |
} elseif ( is_user_admin() ) { |
|
0 | 143 |
|
5 | 144 |
/** |
145 |
* Fires before the administration menu loads in the User Admin. |
|
146 |
* |
|
147 |
* @since 3.1.0 |
|
148 |
* |
|
149 |
* @param string $context Empty context. |
|
150 |
*/ |
|
151 |
do_action( 'user_admin_menu', '' ); |
|
152 |
} else { |
|
153 |
||
154 |
/** |
|
155 |
* Fires before the administration menu loads in the admin. |
|
156 |
* |
|
157 |
* @since 1.5.0 |
|
158 |
* |
|
159 |
* @param string $context Empty context. |
|
160 |
*/ |
|
161 |
do_action( 'admin_menu', '' ); |
|
162 |
} |
|
163 |
||
164 |
/* |
|
165 |
* Remove menus that have no accessible submenus and require privileges |
|
166 |
* that the user does not have. Run re-parent loop again. |
|
167 |
*/ |
|
0 | 168 |
foreach ( $menu as $id => $data ) { |
9 | 169 |
if ( ! current_user_can( $data[1] ) ) { |
170 |
$_wp_menu_nopriv[ $data[2] ] = true; |
|
171 |
} |
|
0 | 172 |
|
5 | 173 |
/* |
174 |
* If there is only one submenu and it is has same destination as the parent, |
|
175 |
* remove the submenu. |
|
176 |
*/ |
|
16 | 177 |
if ( ! empty( $submenu[ $data[2] ] ) && 1 === count( $submenu[ $data[2] ] ) ) { |
9 | 178 |
$subs = $submenu[ $data[2] ]; |
5 | 179 |
$first_sub = reset( $subs ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
if ( $data[2] === $first_sub[2] ) { |
9 | 182 |
unset( $submenu[ $data[2] ] ); |
183 |
} |
|
0 | 184 |
} |
185 |
||
186 |
// If submenu is empty... |
|
9 | 187 |
if ( empty( $submenu[ $data[2] ] ) ) { |
0 | 188 |
// And user doesn't have privs, remove menu. |
9 | 189 |
if ( isset( $_wp_menu_nopriv[ $data[2] ] ) ) { |
190 |
unset( $menu[ $id ] ); |
|
0 | 191 |
} |
192 |
} |
|
193 |
} |
|
9 | 194 |
unset( $id, $data, $subs, $first_sub ); |
0 | 195 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
196 |
/** |
19 | 197 |
* Adds a CSS class to a string. |
198 |
* |
|
199 |
* @since 2.7.0 |
|
200 |
* |
|
201 |
* @param string $class_to_add The CSS class to add. |
|
202 |
* @param string $classes The string to add the CSS class to. |
|
203 |
* @return string The string with the CSS class added. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
*/ |
19 | 205 |
function add_cssclass( $class_to_add, $classes ) { |
206 |
if ( empty( $classes ) ) { |
|
207 |
return $class_to_add; |
|
208 |
} |
|
209 |
||
210 |
return $classes . ' ' . $class_to_add; |
|
0 | 211 |
} |
212 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
/** |
19 | 214 |
* Adds CSS classes for top-level administration menu items. |
215 |
* |
|
216 |
* The list of added classes includes `.menu-top-first` and `.menu-top-last`. |
|
217 |
* |
|
218 |
* @since 2.7.0 |
|
219 |
* |
|
220 |
* @param array $menu The array of administration menu items. |
|
221 |
* @return array The array of administration menu items with the CSS classes added. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
*/ |
9 | 223 |
function add_menu_classes( $menu ) { |
19 | 224 |
$first_item = false; |
225 |
$last_order = false; |
|
226 |
$items_count = count( $menu ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
227 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
228 |
$i = 0; |
19 | 229 |
|
0 | 230 |
foreach ( $menu as $order => $top ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
231 |
++$i; |
0 | 232 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
if ( 0 === $order ) { // Dashboard is always shown/single. |
9 | 234 |
$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] ); |
19 | 235 |
$last_order = 0; |
0 | 236 |
continue; |
237 |
} |
|
238 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
239 |
if ( str_starts_with( $top[2], 'separator' ) && false !== $last_order ) { // If separator. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
$first_item = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
241 |
$classes = $menu[ $last_order ][4]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
242 |
|
19 | 243 |
$menu[ $last_order ][4] = add_cssclass( 'menu-top-last', $classes ); |
0 | 244 |
continue; |
245 |
} |
|
246 |
||
19 | 247 |
if ( $first_item ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
248 |
$first_item = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
249 |
$classes = $menu[ $order ][4]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
250 |
|
19 | 251 |
$menu[ $order ][4] = add_cssclass( 'menu-top-first', $classes ); |
0 | 252 |
} |
253 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
if ( $i === $items_count ) { // Last item. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
$classes = $menu[ $order ][4]; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
|
19 | 257 |
$menu[ $order ][4] = add_cssclass( 'menu-top-last', $classes ); |
0 | 258 |
} |
259 |
||
19 | 260 |
$last_order = $order; |
0 | 261 |
} |
262 |
||
5 | 263 |
/** |
19 | 264 |
* Filters administration menu array with classes added for top-level items. |
5 | 265 |
* |
266 |
* @since 2.7.0 |
|
267 |
* |
|
268 |
* @param array $menu Associative array of administration menu items. |
|
269 |
*/ |
|
0 | 270 |
return apply_filters( 'add_menu_classes', $menu ); |
271 |
} |
|
272 |
||
16 | 273 |
uksort( $menu, 'strnatcasecmp' ); // Make it all pretty. |
0 | 274 |
|
5 | 275 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
* Filters whether to enable custom ordering of the administration menu. |
5 | 277 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
* See the {@see 'menu_order'} filter for reordering menu items. |
5 | 279 |
* |
280 |
* @since 2.8.0 |
|
281 |
* |
|
282 |
* @param bool $custom Whether custom ordering is enabled. Default false. |
|
283 |
*/ |
|
284 |
if ( apply_filters( 'custom_menu_order', false ) ) { |
|
0 | 285 |
$menu_order = array(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
286 |
|
0 | 287 |
foreach ( $menu as $menu_item ) { |
288 |
$menu_order[] = $menu_item[2]; |
|
289 |
} |
|
9 | 290 |
unset( $menu_item ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
291 |
|
0 | 292 |
$default_menu_order = $menu_order; |
5 | 293 |
|
294 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
* Filters the order of administration menu items. |
5 | 296 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
297 |
* A truthy value must first be passed to the {@see 'custom_menu_order'} filter |
5 | 298 |
* for this filter to work. Use the following to enable custom menu ordering: |
299 |
* |
|
300 |
* add_filter( 'custom_menu_order', '__return_true' ); |
|
301 |
* |
|
302 |
* @since 2.8.0 |
|
303 |
* |
|
304 |
* @param array $menu_order An ordered array of menu items. |
|
305 |
*/ |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
306 |
$menu_order = apply_filters( 'menu_order', $menu_order ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
307 |
$menu_order = array_flip( $menu_order ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
|
9 | 309 |
$default_menu_order = array_flip( $default_menu_order ); |
0 | 310 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
311 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
312 |
* @global array $menu_order |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
313 |
* @global array $default_menu_order |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
314 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
315 |
* @param array $a |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
316 |
* @param array $b |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
* @return int |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
*/ |
9 | 319 |
function sort_menu( $a, $b ) { |
0 | 320 |
global $menu_order, $default_menu_order; |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
321 |
|
0 | 322 |
$a = $a[2]; |
323 |
$b = $b[2]; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
324 |
|
9 | 325 |
if ( isset( $menu_order[ $a ] ) && ! isset( $menu_order[ $b ] ) ) { |
0 | 326 |
return -1; |
9 | 327 |
} elseif ( ! isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) { |
0 | 328 |
return 1; |
9 | 329 |
} elseif ( isset( $menu_order[ $a ] ) && isset( $menu_order[ $b ] ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
330 |
if ( $menu_order[ $a ] === $menu_order[ $b ] ) { |
0 | 331 |
return 0; |
9 | 332 |
} |
333 |
return ( $menu_order[ $a ] < $menu_order[ $b ] ) ? -1 : 1; |
|
0 | 334 |
} else { |
9 | 335 |
return ( $default_menu_order[ $a ] <= $default_menu_order[ $b ] ) ? -1 : 1; |
0 | 336 |
} |
337 |
} |
|
338 |
||
9 | 339 |
usort( $menu, 'sort_menu' ); |
340 |
unset( $menu_order, $default_menu_order ); |
|
0 | 341 |
} |
342 |
||
16 | 343 |
// Prevent adjacent separators. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
344 |
$prev_menu_was_separator = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
345 |
foreach ( $menu as $id => $data ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
346 |
if ( false === stristr( $data[4], 'wp-menu-separator' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
|
16 | 348 |
// This item is not a separator, so falsey the toggler and do nothing. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
349 |
$prev_menu_was_separator = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
351 |
|
16 | 352 |
// The previous item was a separator, so unset this one. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
if ( true === $prev_menu_was_separator ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
354 |
unset( $menu[ $id ] ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
355 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
356 |
|
16 | 357 |
// This item is a separator, so truthy the toggler and move on. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
358 |
$prev_menu_was_separator = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
359 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
360 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
361 |
unset( $id, $data, $prev_menu_was_separator ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
|
0 | 363 |
// Remove the last menu item if it is a separator. |
364 |
$last_menu_key = array_keys( $menu ); |
|
365 |
$last_menu_key = array_pop( $last_menu_key ); |
|
16 | 366 |
if ( ! empty( $menu ) && 'wp-menu-separator' === $menu[ $last_menu_key ][4] ) { |
0 | 367 |
unset( $menu[ $last_menu_key ] ); |
9 | 368 |
} |
0 | 369 |
unset( $last_menu_key ); |
370 |
||
9 | 371 |
if ( ! user_can_access_admin_page() ) { |
5 | 372 |
|
373 |
/** |
|
374 |
* Fires when access to an admin page is denied. |
|
375 |
* |
|
376 |
* @since 2.5.0 |
|
377 |
*/ |
|
378 |
do_action( 'admin_page_access_denied' ); |
|
379 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
0 | 381 |
} |
382 |
||
9 | 383 |
$menu = add_menu_classes( $menu ); |