From ad471ac4742035b97411b65bbe6449ab61292903 Mon Sep 17 00:00:00 2001
From: Scott Taylor <wonderboymusic@git.wordpress.org>
Date: Wed, 28 Oct 2015 18:05:05 +0000
Subject: [PATCH] Admin Menu: after [34861], prevent adjacent separators.

Props johnjamesjacoby.
Fixes #24104.


git-svn-id: https://develop.svn.wordpress.org/trunk@35416 602fd350-edb4-49c9-b593-d223f7449a82
---
 src/wp-admin/includes/menu.php | 35 +++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/wp-admin/includes/menu.php b/src/wp-admin/includes/menu.php
index 26ce6f31e0..74804022b7 100644
--- a/src/wp-admin/includes/menu.php
+++ b/src/wp-admin/includes/menu.php
@@ -178,21 +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 ( false !== strpos( $data[4], 'wp-menu-separator' ) ) {
-		if ( ! $separator_found ) {
-			$separator_found = true;
-		} else {
-			unset($menu[$id]);
-		}
-	} else {
-		$separator_found = false;
-	}
-}
-unset($id, $data);
-
 /**
  *
  * @param string $add
@@ -318,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 );