WordPress.org

Make WordPress Core

Ticket #17528: 17528.2.diff

File 17528.2.diff, 857 bytes (added by ryan, 7 years ago)

A generic approach

  • wp-admin/includes/menu.php

     
    102102        if ( ! current_user_can($data[1]) )
    103103                $_wp_menu_nopriv[$data[2]] = true;
    104104
     105        // If there is only one submenu and it is has same destination as the parent,
     106        // remove the submenu.
     107        if ( 1 == count ( $submenu[$data[2]] ) ) {
     108                $subs = $submenu[$data[2]];
     109                $first_sub = array_shift($subs);
     110                if ( $data[2] == $first_sub[2] )
     111                        unset( $submenu[$data[2]] );
     112        }
     113
    105114        // If submenu is empty...
    106115        if ( empty($submenu[$data[2]]) ) {
    107116                // And user doesn't have privs, remove menu.
     
    110119                }
    111120        }
    112121}
    113 unset($id, $data);
     122unset($id, $data, $subs, $first_sub);
    114123
    115124// Remove any duplicated seperators
    116125$seperator_found = false;