WordPress.org

Make WordPress Core

Changeset 35416


Ignore:
Timestamp:
10/28/2015 06:05:05 PM (5 years ago)
Author:
wonderboymusic
Message:

Admin Menu: after [34861], prevent adjacent separators.

Props johnjamesjacoby.
Fixes #24104.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/menu.php

    r35027 r35416  
    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 *
     
    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 );
Note: See TracChangeset for help on using the changeset viewer.