WordPress.org

Make WordPress Core

Ticket #19541: 19541.diff

File 19541.diff, 3.4 KB (added by nacin, 6 years ago)
  • wp-includes/admin-bar.php

     
    488488        $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
    489489
    490490        if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
    491                 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
     491                $actions[5] = array( 'post-new.php', $cpts['post']->labels->name_admin_bar, 'new-post' );
    492492                unset( $cpts['post'] );
    493493        }
    494494
    495495        if ( current_user_can( 'upload_files' ) )
    496                 $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
     496                $actions[10] = array( 'media-new.php', _x( 'Media', 'add new from admin bar' ), 'new-media' );
    497497
    498498        if ( current_user_can( 'manage_links' ) )
    499                 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
     499                $actions[15] = array( 'link-add.php', _x( 'Link', 'add new from admin bar' ), 'new-link' );
    500500
    501501        if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
    502                 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
     502                $actions[20] = array( 'post-new.php?post_type=page', $cpts['page']->labels->name_admin_bar, 'new-page' );
    503503                unset( $cpts['page'] );
    504504        }
    505505
     506        if ( current_user_can( 'promote_users' ) || current_user_can( 'create_users' ) )
     507                $actions[70] = array( 'user-new.php', _x( 'User', 'add new from admin bar' ), 'new-user' );
     508
    506509        // Add any additional custom post types.
    507510        foreach ( $cpts as $cpt ) {
    508511                if ( ! current_user_can( $cpt->cap->edit_posts ) )
    509512                        continue;
    510513
    511                 $key = 'post-new.php?post_type=' . $cpt->name;
    512                 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
     514                $link = 'post-new.php?post_type=' . $cpt->name;
     515                // Avoid clash with parent node and a 'content' post type.
     516                $id = 'content' === $cpt->name ? 'add-new-content' : 'new-' . $cpt->name;
     517
     518                if ( $position = $cpt->menu_position ) {
     519                        while ( isset( $actions[ $position ] ) )
     520                                $position++;
     521                        $actions[ $position ] = array( $link, $cpt->labels->name_admin_bar, $id );
     522                } else {
     523                        $actions[] = array( $link, $cpt->labels->name_admin_bar, $id );
     524                }
    513525        }
    514         // Avoid clash with parent node and a 'content' post type.
    515         if ( isset( $actions['post-new.php?post_type=content'] ) )
    516                 $actions['post-new.php?post_type=content'][1] = 'add-new-content';
    517526
    518         if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    519                 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
    520 
    521527        if ( ! $actions )
    522528                return;
    523529
     530        ksort( $actions );
     531
    524532        $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>';
    525533
     534        $first = current( $actions );
     535
    526536        $wp_admin_bar->add_menu( array(
    527537                'id'    => 'new-content',
    528538                'title' => $title,
    529                 'href'  => admin_url( current( array_keys( $actions ) ) ),
     539                'href'  => admin_url( $first[0] ),
    530540                'meta'  => array(
    531541                        'title' => _x( 'Add New', 'admin bar menu group label' ),
    532542                ),
    533543        ) );
    534544
    535         foreach ( $actions as $link => $action ) {
    536                 list( $title, $id ) = $action;
     545        foreach ( $actions as $action ) {
     546                list( $link, $title, $id ) = $action;
    537547
    538548                $wp_admin_bar->add_menu( array(
    539549                        'parent'    => 'new-content',