WordPress.org

Make WordPress Core

Ticket #16946: 16946.diff

File 16946.diff, 2.1 KB (added by blepoxp, 3 years ago)
  • wp-admin/includes/plugin.php

     
    888888        if ( null === $position  ) 
    889889                $menu[] = $new_menu; 
    890890        else 
    891                 $menu[$position] = $new_menu; 
     891                $position = $menu[get_unique_menu_key( $position )] = $new_menu; 
    892892 
    893893        $_registered_pages[$hookname] = true; 
    894894 
     
    14831483        return $title; 
    14841484} 
    14851485 
     1486/** 
     1487 * Preserves core menu keys as well as keys previously set by various APIs  
     1488 * 
     1489 * If requested key has already been set or will be set by core, bump it util we find a free one 
     1490 * 
     1491 * @param int $int The position in the menu order this one should appear 
     1492 * @return int 
     1493 */ 
     1494function get_unique_menu_key( $int ) { 
     1495        global $menu; 
     1496         
     1497        $core_menu_positions = array( 2, 4, 5, 10, 15, 20, 25, 59, 60, 65, 70, 75, 80, 99); 
     1498        while ( isset($menu[$int] ) || in_array( $int, $core_menu_positions ) ) 
     1499                $int++; 
     1500                         
     1501        return $int; 
     1502} 
     1503 
    14861504function get_plugin_page_hook( $plugin_page, $parent_page ) { 
    14871505        $hook = get_plugin_page_hookname( $plugin_page, $parent_page ); 
    14881506        if ( has_action($hook) ) 
  • wp-admin/menu.php

     
    122122                $ptype_class = 'post'; 
    123123        } 
    124124 
    125         // if $ptype_menu_position is already populated or will be populated by a hard-coded value below, increment the position. 
    126         $core_menu_positions = array(59, 60, 65, 70, 75, 80, 85, 99); 
    127         while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) ) 
    128                 $ptype_menu_position++; 
     125        $ptype_menu_position = get_unique_menu_key( $ptype_menu_position ); 
    129126 
    130127        $menu[$ptype_menu_position] = array( esc_attr( $ptype_obj->labels->menu_name ), $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-' . $ptype_class, 'menu-posts-' . $ptype_for_id, $menu_icon ); 
    131128        $submenu["edit.php?post_type=$ptype"][5]  = array( $ptype_obj->labels->menu_name, $ptype_obj->cap->edit_posts,  "edit.php?post_type=$ptype");