WordPress.org

Make WordPress Core

Changeset 18788


Ignore:
Timestamp:
09/27/2011 04:04:10 AM (7 years ago)
Author:
nacin
Message:

Cleanup in wp_admin_bar_new_content_menu. current() instead of array_shift(), remove unused index 1 from the arrays, remove ?post_type=post from the Post link. see #18197.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/admin-bar.php

    r18787 r18788  
    430430 */
    431431function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
    432     $primary   = array();
    433     $secondary = array();
     432    $primary = $secondary = array();
    434433
    435434    foreach ( (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ) as $ptype_obj ) {
     
    437436            continue;
    438437
    439         $primary[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->name_admin_bar, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name );
     438        $key = 'post' == $ptype_obj->name ? 'post-new.php' : 'post-new.php?post_type=' . $ptype_obj->name;
     439        $primary[ $key ] = array( $ptype_obj->labels->name_admin_bar, 'new-' . $ptype_obj->name );
    440440    }
    441441
    442442    if ( current_user_can( 'upload_files' ) )
    443         $primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'upload_files', 'new-media' );
     443        $primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
    444444
    445445    if ( current_user_can( 'manage_links' ) )
    446         $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'manage_links', 'new-link' );
     446        $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
    447447
    448448    if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    449         $secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'create_users', 'new-user' );
     449        $secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
    450450
    451451    if ( ! is_multisite() && current_user_can( 'install_themes' ) )
    452         $secondary[ 'theme-install.php' ] = array( _x( 'Theme', 'add new from admin bar' ), 'install_themes', 'new-theme' );
     452        $secondary[ 'theme-install.php' ] = array( _x( 'Theme', 'add new from admin bar' ), 'new-theme' );
    453453
    454454    if ( ! is_multisite() && current_user_can( 'install_plugins' ) )
    455         $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'install_plugins', 'new-plugin' );
    456 
    457     if ( empty( $primary ) && empty( $secondary ) )
     455        $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'new-plugin' );
     456
     457    if ( ! $primary && ! $secondary )
    458458        return;
    459459
     
    461461        'id'    => 'new-content',
    462462        'title' => _x( 'Add New', 'admin bar menu group label' ),
    463         'href'  => admin_url( array_shift( array_keys( $primary ) ) ),
     463        'href'  => admin_url( current( array_keys( $primary ) ) ),
    464464    ) );
    465465
     
    485485            $wp_admin_bar->add_menu( array(
    486486                'parent' => $parent,
    487                 'id'     => $action[2],
     487                'id'     => $action[1],
    488488                'title'  => $action[0],
    489489                'href'   => admin_url( $link )
Note: See TracChangeset for help on using the changeset viewer.