Make WordPress Core


Ignore:
Timestamp:
04/10/2010 10:48:30 AM (17 years ago)
Author:
dd32
Message:

Prevent $post_type_object->menu_position from conflicting with another plugin, or core menu item. Props blepoxp. Fixes #12951

File:
1 edited

Legend:

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

    r14014 r14049  
    115115
    116116foreach ( (array) get_post_types( array('show_ui' => true) ) as $ptype ) {
    117         $_wp_last_object_menu++;
    118117        $ptype_obj = get_post_type_object($ptype);
    119         $ptype_menu_position = is_int( $ptype_obj->menu_position ) ? $ptype_obj->menu_position : $_wp_last_object_menu;
     118        $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.
    120119        $menu_icon = is_string($ptype_obj->menu_icon) ? esc_url($ptype_obj->menu_icon) : 'div';
    121        
     120
     121        // if $ptype_menu_position is already populated or will be populated by a hard-coded value below, increment the position.
     122        $core_menu_positions = array(59, 60, 65, 70, 75, 80, 85, 99);
     123        while ( isset($menu[$ptype_menu_position]) || in_array($ptype_menu_position, $core_menu_positions) )
     124                $ptype_menu_position++;
     125
    122126        $menu[$ptype_menu_position] = array(esc_attr($ptype_obj->label), $ptype_obj->edit_type_cap, "edit.php?post_type=$ptype", '', 'menu-top menu-icon-posts', 'menu-' . sanitize_html_class($ptype), $menu_icon);
    123127        $submenu["edit.php?post_type=$ptype"][5]  = array( __('Edit'), $ptype_obj->edit_type_cap,  "edit.php?post_type=$ptype");
    … …  
    412416$menu = add_menu_classes($menu);
    413417
    414 if (! user_can_access_admin_page()) {
     418if ( !user_can_access_admin_page() ) {
    415419        do_action('admin_page_access_denied');
    416420        wp_die( __('You do not have sufficient permissions to access this page.') );
Note: See TracChangeset for help on using the changeset viewer.