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