WordPress.org

Make WordPress Core

Ticket #24104: 24104.02.patch

File 24104.02.patch, 1.4 KB (added by johnjamesjacoby, 4 years ago)

(Lengthy description imminent.)

  • src/wp-admin/includes/menu.php

    diff --git src/wp-admin/includes/menu.php src/wp-admin/includes/menu.php
    index 26ce6f3..7480402 100644
     
    178178}
    179179unset($id, $data, $subs, $first_sub);
    180180
    181 // Remove any duplicated separators
    182 $separator_found = false;
    183 foreach ( $menu as $id => $data ) {
    184         if ( false !== strpos( $data[4], 'wp-menu-separator' ) ) {
    185                 if ( ! $separator_found ) {
    186                         $separator_found = true;
    187                 } else {
    188                         unset($menu[$id]);
    189                 }
    190         } else {
    191                 $separator_found = false;
    192         }
    193 }
    194 unset($id, $data);
    195 
    196181/**
    197182 *
    198183 * @param string $add
     
    318303        unset($menu_order, $default_menu_order);
    319304}
    320305
     306// Prevent adjacent separators
     307$prev_menu_was_separator = false;
     308foreach ( $menu as $id => $data ) {
     309        if ( false === stristr( $data[4], 'wp-menu-separator' ) ) {
     310
     311                // This item is not a separator, so falsey the toggler and do nothing
     312                $prev_menu_was_separator = false;
     313        } else {
     314
     315                // The previous item was a separator, so unset this one
     316                if ( true === $prev_menu_was_separator ) {
     317                        unset( $menu[ $id ] );
     318                }
     319
     320                // This item is a separator, so truthy the toggler and move on
     321                $prev_menu_was_separator = true;
     322        }
     323}
     324unset( $id, $data, $prev_menu_was_separator );
     325
    321326// Remove the last menu item if it is a separator.
    322327$last_menu_key = array_keys( $menu );
    323328$last_menu_key = array_pop( $last_menu_key );