]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/menu.php
WordPress 4.4.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / menu.php
index accc04b1b0b46d59857b9ee7677a1cc930e00562..74804022b7034b607256046e6fed685e356e193c 100644 (file)
@@ -178,22 +178,6 @@ 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 ( ! $separator_found ) {
-                       $separator_found = true;
-               } else {
-                       unset($menu[$id]);
-                       $separator_found = false;
-               }
-       } else {
-               $separator_found = false;
-       }
-}
-unset($id, $data);
-
 /**
  *
  * @param string $add
@@ -259,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
  *
@@ -276,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' );
@@ -319,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 );