X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/7f1521bf193b382565eb753043c161f4cb3fcda7..refs/tags/wordpress-4.4:/wp-admin/includes/menu.php diff --git a/wp-admin/includes/menu.php b/wp-admin/includes/menu.php index ce90c1ba..74804022 100644 --- a/wp-admin/includes/menu.php +++ b/wp-admin/includes/menu.php @@ -178,29 +178,23 @@ foreach ( $menu as $id => $data ) { } unset($id, $data, $subs, $first_sub); -// Remove any duplicated separators -$separator_found = false; -foreach ( $menu as $id => $data ) { - if ( 0 == strcmp('wp-menu-separator', $data[4] ) ) { - if (false == $separator_found) { - $separator_found = true; - } else { - unset($menu[$id]); - $separator_found = false; - } - } else { - $separator_found = false; - } -} -unset($id, $data); - +/** + * + * @param string $add + * @param string $class + * @return string + */ function add_cssclass($add, $class) { $class = empty($class) ? $add : $class .= ' ' . $add; return $class; } +/** + * + * @param array $menu + * @return array + */ function add_menu_classes($menu) { - $first = $lastorder = false; $i = 0; $mc = count($menu); @@ -249,7 +243,7 @@ uksort($menu, "strnatcasecmp"); // make it all pretty /** * Filter whether to enable custom ordering of the administration menu. * - * See the 'menu_order' filter for reordering menu items. + * See the {@see 'menu_order'} filter for reordering menu items. * * @since 2.8.0 * @@ -266,7 +260,7 @@ if ( apply_filters( 'custom_menu_order', false ) ) { /** * Filter the order of administration menu items. * - * A truthy value must first be passed to the 'custom_menu_order' filter + * A truthy value must first be passed to the {@see 'custom_menu_order'} filter * for this filter to work. Use the following to enable custom menu ordering: * * add_filter( 'custom_menu_order', '__return_true' ); @@ -279,6 +273,15 @@ if ( apply_filters( 'custom_menu_order', false ) ) { $menu_order = array_flip($menu_order); $default_menu_order = array_flip($default_menu_order); + /** + * + * @global array $menu_order + * @global array $default_menu_order + * + * @param array $a + * @param array $b + * @return int + */ function sort_menu($a, $b) { global $menu_order, $default_menu_order; $a = $a[2]; @@ -300,6 +303,26 @@ if ( apply_filters( 'custom_menu_order', false ) ) { unset($menu_order, $default_menu_order); } +// Prevent adjacent separators +$prev_menu_was_separator = false; +foreach ( $menu as $id => $data ) { + if ( false === stristr( $data[4], 'wp-menu-separator' ) ) { + + // This item is not a separator, so falsey the toggler and do nothing + $prev_menu_was_separator = false; + } else { + + // The previous item was a separator, so unset this one + if ( true === $prev_menu_was_separator ) { + unset( $menu[ $id ] ); + } + + // This item is a separator, so truthy the toggler and move on + $prev_menu_was_separator = true; + } +} +unset( $id, $data, $prev_menu_was_separator ); + // Remove the last menu item if it is a separator. $last_menu_key = array_keys( $menu ); $last_menu_key = array_pop( $last_menu_key );