wp/wp-admin/includes/menu.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
--- a/wp/wp-admin/includes/menu.php	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-admin/includes/menu.php	Mon Oct 14 17:39:30 2019 +0200
@@ -178,29 +178,23 @@
 }
 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);
@@ -235,7 +229,7 @@
 	}
 
 	/**
-	 * Filter administration menus array with classes added for top-level items.
+	 * Filters administration menus array with classes added for top-level items.
 	 *
 	 * @since 2.7.0
 	 *
@@ -247,9 +241,9 @@
 uksort($menu, "strnatcasecmp"); // make it all pretty
 
 /**
- * Filter whether to enable custom ordering of the administration menu.
+ * Filters 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
  *
@@ -264,9 +258,9 @@
 	$default_menu_order = $menu_order;
 
 	/**
-	 * Filter the order of administration menu items.
+	 * Filters 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 @@
 	$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 @@
 	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 );
@@ -316,7 +339,7 @@
 	 */
 	do_action( 'admin_page_access_denied' );
 
-	wp_die( __( 'You do not have sufficient permissions to access this page.' ), 403 );
+	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
 }
 
 $menu = add_menu_classes($menu);