WordPress.org

Make WordPress Core

Ticket #16856: 16856.2.diff

File 16856.2.diff, 1.8 KB (added by nathanrice, 4 years ago)

Adds is_numeric() check to wp-admin/menu.php and wp-admin/includes/plugin.php

  • wp-admin/menu.php

     
    123123 
    124124foreach ( (array) get_post_types( array('show_ui' => true, '_builtin' => false) ) as $ptype ) { 
    125125        $ptype_obj = get_post_type_object( $ptype ); 
    126         $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : $_wp_last_object_menu++; // If we're to use $_wp_last_object_menu, increment it first. 
     126        $ptype_menu_position = is_numeric( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : $_wp_last_object_menu++; // If we're to use $_wp_last_object_menu, increment it first. 
    127127        $ptype_for_id = sanitize_html_class( $ptype ); 
    128128        if ( is_string( $ptype_obj->menu_icon ) ) { 
    129129                $menu_icon   = esc_url( $ptype_obj->menu_icon ); 
  • wp-admin/includes/plugin.php

     
    817817 * @param int $position The position in the menu order this one should appear 
    818818 */ 
    819819function add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function = '', $icon_url = '', $position = NULL ) { 
    820         global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages; 
     820        global $menu, $admin_page_hooks, $_registered_pages, $_parent_pages, $_wp_last_object_menu; 
    821821 
    822822        $menu_slug = plugin_basename( $menu_slug ); 
    823823 
     
    835835 
    836836        $new_menu = array( $menu_title, $capability, $menu_slug, $page_title, 'menu-top ' . $hookname, $hookname, $icon_url ); 
    837837 
    838         if ( null === $position  ) 
    839                 $menu[] = $new_menu; 
     838        if ( is_numeric( $position )  ) 
     839                $menu[$position] = $new_menu; 
    840840        else 
    841                 $menu[$position] = $new_menu; 
     841                $menu[$_wp_last_object_menu++] = $new_menu; 
    842842 
    843843        $_registered_pages[$hookname] = true; 
    844844