wp/wp-admin/includes/menu.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 19 3d72ae0968f4
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    41 	do_action( '_admin_menu' );
    41 	do_action( '_admin_menu' );
    42 }
    42 }
    43 
    43 
    44 // Create list of page plugin hook names.
    44 // Create list of page plugin hook names.
    45 foreach ( $menu as $menu_page ) {
    45 foreach ( $menu as $menu_page ) {
    46 	if ( false !== $pos = strpos( $menu_page[2], '?' ) ) {
    46 	$pos = strpos( $menu_page[2], '?' );
       
    47 	if ( false !== $pos ) {
    47 		// Handle post_type=post|page|foo pages.
    48 		// Handle post_type=post|page|foo pages.
    48 		$hook_name = substr( $menu_page[2], 0, $pos );
    49 		$hook_name = substr( $menu_page[2], 0, $pos );
    49 		$hook_args = substr( $menu_page[2], $pos + 1 );
    50 		$hook_args = substr( $menu_page[2], $pos + 1 );
    50 		wp_parse_str( $hook_args, $hook_args );
    51 		wp_parse_str( $hook_args, $hook_args );
    51 		// Set the hook name to be the post type.
    52 		// Set the hook name to be the post type.
   165 
   166 
   166 	/*
   167 	/*
   167 	 * If there is only one submenu and it is has same destination as the parent,
   168 	 * If there is only one submenu and it is has same destination as the parent,
   168 	 * remove the submenu.
   169 	 * remove the submenu.
   169 	 */
   170 	 */
   170 	if ( ! empty( $submenu[ $data[2] ] ) && 1 == count( $submenu[ $data[2] ] ) ) {
   171 	if ( ! empty( $submenu[ $data[2] ] ) && 1 === count( $submenu[ $data[2] ] ) ) {
   171 		$subs      = $submenu[ $data[2] ];
   172 		$subs      = $submenu[ $data[2] ];
   172 		$first_sub = reset( $subs );
   173 		$first_sub = reset( $subs );
   173 		if ( $data[2] == $first_sub[2] ) {
   174 		if ( $data[2] == $first_sub[2] ) {
   174 			unset( $submenu[ $data[2] ] );
   175 			unset( $submenu[ $data[2] ] );
   175 		}
   176 		}
   198 /**
   199 /**
   199  * @param array $menu
   200  * @param array $menu
   200  * @return array
   201  * @return array
   201  */
   202  */
   202 function add_menu_classes( $menu ) {
   203 function add_menu_classes( $menu ) {
   203 	$first = $lastorder = false;
   204 	$first     = false;
   204 	$i     = 0;
   205 	$lastorder = false;
   205 	$mc    = count( $menu );
   206 	$i         = 0;
       
   207 	$mc        = count( $menu );
   206 	foreach ( $menu as $order => $top ) {
   208 	foreach ( $menu as $order => $top ) {
   207 		$i++;
   209 		$i++;
   208 
   210 
   209 		if ( 0 == $order ) { // dashboard is always shown/single
   211 		if ( 0 == $order ) { // Dashboard is always shown/single.
   210 			$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
   212 			$menu[0][4] = add_cssclass( 'menu-top-first', $top[4] );
   211 			$lastorder  = 0;
   213 			$lastorder  = 0;
   212 			continue;
   214 			continue;
   213 		}
   215 		}
   214 
   216 
   215 		if ( 0 === strpos( $top[2], 'separator' ) && false !== $lastorder ) { // if separator
   217 		if ( 0 === strpos( $top[2], 'separator' ) && false !== $lastorder ) { // If separator.
   216 			$first                 = true;
   218 			$first                 = true;
   217 			$c                     = $menu[ $lastorder ][4];
   219 			$c                     = $menu[ $lastorder ][4];
   218 			$menu[ $lastorder ][4] = add_cssclass( 'menu-top-last', $c );
   220 			$menu[ $lastorder ][4] = add_cssclass( 'menu-top-last', $c );
   219 			continue;
   221 			continue;
   220 		}
   222 		}
   223 			$c                 = $menu[ $order ][4];
   225 			$c                 = $menu[ $order ][4];
   224 			$menu[ $order ][4] = add_cssclass( 'menu-top-first', $c );
   226 			$menu[ $order ][4] = add_cssclass( 'menu-top-first', $c );
   225 			$first             = false;
   227 			$first             = false;
   226 		}
   228 		}
   227 
   229 
   228 		if ( $mc == $i ) { // last item
   230 		if ( $mc == $i ) { // Last item.
   229 			$c                 = $menu[ $order ][4];
   231 			$c                 = $menu[ $order ][4];
   230 			$menu[ $order ][4] = add_cssclass( 'menu-top-last', $c );
   232 			$menu[ $order ][4] = add_cssclass( 'menu-top-last', $c );
   231 		}
   233 		}
   232 
   234 
   233 		$lastorder = $order;
   235 		$lastorder = $order;
   241 	 * @param array $menu Associative array of administration menu items.
   243 	 * @param array $menu Associative array of administration menu items.
   242 	 */
   244 	 */
   243 	return apply_filters( 'add_menu_classes', $menu );
   245 	return apply_filters( 'add_menu_classes', $menu );
   244 }
   246 }
   245 
   247 
   246 uksort( $menu, 'strnatcasecmp' ); // make it all pretty
   248 uksort( $menu, 'strnatcasecmp' ); // Make it all pretty.
   247 
   249 
   248 /**
   250 /**
   249  * Filters whether to enable custom ordering of the administration menu.
   251  * Filters whether to enable custom ordering of the administration menu.
   250  *
   252  *
   251  * See the {@see 'menu_order'} filter for reordering menu items.
   253  * See the {@see 'menu_order'} filter for reordering menu items.
   306 
   308 
   307 	usort( $menu, 'sort_menu' );
   309 	usort( $menu, 'sort_menu' );
   308 	unset( $menu_order, $default_menu_order );
   310 	unset( $menu_order, $default_menu_order );
   309 }
   311 }
   310 
   312 
   311 // Prevent adjacent separators
   313 // Prevent adjacent separators.
   312 $prev_menu_was_separator = false;
   314 $prev_menu_was_separator = false;
   313 foreach ( $menu as $id => $data ) {
   315 foreach ( $menu as $id => $data ) {
   314 	if ( false === stristr( $data[4], 'wp-menu-separator' ) ) {
   316 	if ( false === stristr( $data[4], 'wp-menu-separator' ) ) {
   315 
   317 
   316 		// This item is not a separator, so falsey the toggler and do nothing
   318 		// This item is not a separator, so falsey the toggler and do nothing.
   317 		$prev_menu_was_separator = false;
   319 		$prev_menu_was_separator = false;
   318 	} else {
   320 	} else {
   319 
   321 
   320 		// The previous item was a separator, so unset this one
   322 		// The previous item was a separator, so unset this one.
   321 		if ( true === $prev_menu_was_separator ) {
   323 		if ( true === $prev_menu_was_separator ) {
   322 			unset( $menu[ $id ] );
   324 			unset( $menu[ $id ] );
   323 		}
   325 		}
   324 
   326 
   325 		// This item is a separator, so truthy the toggler and move on
   327 		// This item is a separator, so truthy the toggler and move on.
   326 		$prev_menu_was_separator = true;
   328 		$prev_menu_was_separator = true;
   327 	}
   329 	}
   328 }
   330 }
   329 unset( $id, $data, $prev_menu_was_separator );
   331 unset( $id, $data, $prev_menu_was_separator );
   330 
   332 
   331 // Remove the last menu item if it is a separator.
   333 // Remove the last menu item if it is a separator.
   332 $last_menu_key = array_keys( $menu );
   334 $last_menu_key = array_keys( $menu );
   333 $last_menu_key = array_pop( $last_menu_key );
   335 $last_menu_key = array_pop( $last_menu_key );
   334 if ( ! empty( $menu ) && 'wp-menu-separator' == $menu[ $last_menu_key ][4] ) {
   336 if ( ! empty( $menu ) && 'wp-menu-separator' === $menu[ $last_menu_key ][4] ) {
   335 	unset( $menu[ $last_menu_key ] );
   337 	unset( $menu[ $last_menu_key ] );
   336 }
   338 }
   337 unset( $last_menu_key );
   339 unset( $last_menu_key );
   338 
   340 
   339 if ( ! user_can_access_admin_page() ) {
   341 if ( ! user_can_access_admin_page() ) {