Make WordPress Core

Changeset 18787


Ignore:
Timestamp:
09/27/2011 03:53:43 AM (13 years ago)
Author:
koopersmith
Message:

Add secondary section to 'Add New' admin bar menu. see #18197.

File:
1 edited

Legend:

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

    r18777 r18787  
    430430 */
    431431function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
    432     $actions = array();
     432    $primary   = array();
     433    $secondary = array();
     434
    433435    foreach ( (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ) as $ptype_obj ) {
    434436        if ( ! current_user_can( $ptype_obj->cap->edit_posts ) )
    435437            continue;
    436438
    437         $actions[ 'post-new.php?post_type=' . $ptype_obj->name ] = array( $ptype_obj->labels->name_admin_bar, $ptype_obj->cap->edit_posts, 'new-' . $ptype_obj->name );
     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 );
    438440    }
    439441
    440442    if ( current_user_can( 'upload_files' ) )
    441         $actions[ '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' ), 'upload_files', 'new-media' );
    442444
    443445    if ( current_user_can( 'manage_links' ) )
    444         $actions[ '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' ), 'manage_links', 'new-link' );
    445447
    446448    if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    447         $actions[ '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' ), 'create_users', 'new-user' );
    448450
    449451    if ( ! is_multisite() && current_user_can( 'install_themes' ) )
    450         $actions[ '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' ), 'install_themes', 'new-theme' );
    451453
    452454    if ( ! is_multisite() && current_user_can( 'install_plugins' ) )
    453         $actions[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'install_plugins', 'new-plugin' );
    454 
    455     if ( empty( $actions ) )
     455        $secondary[ 'plugin-install.php' ] = array( _x( 'Plugin', 'add new from admin bar' ), 'install_plugins', 'new-plugin' );
     456
     457    if ( empty( $primary ) && empty( $secondary ) )
    456458        return;
    457459
    458     $wp_admin_bar->add_menu( array( 'id' => 'new-content', 'title' => _x( 'Add New', 'admin bar menu group label' ), 'href' => admin_url( array_shift( array_keys( $actions ) ) ) ) );
    459 
    460     foreach ( $actions as $link => $action ) {
    461         $wp_admin_bar->add_menu( array( 'parent' => 'new-content', 'id' => $action[2], 'title' => $action[0], 'href' => admin_url($link) ) );
     460    $wp_admin_bar->add_menu( array(
     461        'id'    => 'new-content',
     462        'title' => _x( 'Add New', 'admin bar menu group label' ),
     463        'href'  => admin_url( array_shift( array_keys( $primary ) ) ),
     464    ) );
     465
     466    $items = array(
     467        'new-content' => $primary,
     468        'new-content-secondary' => $secondary,
     469    );
     470
     471    foreach ( $items as $parent => $actions ) {
     472
     473        if ( ! empty( $actions ) && $parent == 'new-content-secondary' ) {
     474            $wp_admin_bar->add_menu( array(
     475                'parent' => 'new-content',
     476                'id'     => 'new-content-secondary',
     477                'title'  => ' ',
     478                'meta'   => array(
     479                    'class' => 'secondary',
     480                ),
     481            ) );
     482        }
     483
     484        foreach ( $actions as $link => $action ) {
     485            $wp_admin_bar->add_menu( array(
     486                'parent' => $parent,
     487                'id'     => $action[2],
     488                'title'  => $action[0],
     489                'href'   => admin_url( $link )
     490            ) );
     491        }
    462492    }
    463493}
Note: See TracChangeset for help on using the changeset viewer.