Make WordPress Core


Ignore:
Timestamp:
11/09/2011 07:12:48 PM (13 years ago)
Author:
koopersmith
Message:

Add secondary flag to admin bar. fixes #19136.

File:
1 edited

Legend:

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

    r19214 r19230  
    9292    }
    9393
    94     // Add secondary menu.
    95     $wp_admin_bar->add_menu( array(
    96         'parent' => 'wp-logo',
    97         'id'     => 'wp-logo-secondary',
    98         'title'  => ' ',
    99         'meta'   => array(
    100             'class' => 'secondary',
    101         ),
    102     ) );
    103 
    10494    // Add WordPress.org link
    10595    $wp_admin_bar->add_menu( array(
    106         'parent' => 'wp-logo-secondary',
    107         'id'     => 'wporg',
    108         'title'  => __('WordPress.org'),
    109         'href'   => __('http://wordpress.org'),
     96        'parent'    => 'wp-logo',
     97        'secondary' => true,
     98        'id'        => 'wporg',
     99        'title'     => __('WordPress.org'),
     100        'href'      => __('http://wordpress.org'),
    110101    ) );
    111102
    112103    // Add codex link
    113104    $wp_admin_bar->add_menu( array(
    114         'parent' => 'wp-logo-secondary',
    115         'id'     => 'documentation',
    116         'title'  => __('Documentation'),
    117         'href'   => __('http://codex.wordpress.org'),
     105        'parent'    => 'wp-logo',
     106        'secondary' => true,
     107        'id'        => 'documentation',
     108        'title'     => __('Documentation'),
     109        'href'      => __('http://codex.wordpress.org'),
    118110    ) );
    119111
    120112    // Add forums link
    121113    $wp_admin_bar->add_menu( array(
    122         'parent' => 'wp-logo-secondary',
    123         'id'     => 'support-forums',
    124         'title'  => __('Support Forums'),
    125         'href'   => __('http://wordpress.org/support/'),
     114        'parent'    => 'wp-logo',
     115        'secondary' => true,
     116        'id'        => 'support-forums',
     117        'title'     => __('Support Forums'),
     118        'href'      => __('http://wordpress.org/support/'),
    126119    ) );
    127120
    128121    // Add feedback link
    129122    $wp_admin_bar->add_menu( array(
    130         'parent' => 'wp-logo-secondary',
    131         'id'     => 'feedback',
    132         'title'  => __('Feedback'),
    133         'href'   => __('http://wordpress.org/support/forum/requests-and-feedback'),
     123        'parent'    => 'wp-logo',
     124        'secondary' => true,
     125        'id'        => 'feedback',
     126        'title'     => __('Feedback'),
     127        'href'      => __('http://wordpress.org/support/forum/requests-and-feedback'),
    134128    ) );
    135129}
     
    151145        $avatar = get_avatar( $user_id, 28 );
    152146        $howdy  = sprintf( __('Howdy, %1$s'), $user_identity );
    153         $class  = 'opposite';
    154 
    155         if ( ! empty( $avatar ) )
    156             $class .= ' with-avatar';
    157 
    158         $wp_admin_bar->add_menu( array(
    159             'id'    => 'my-account',
    160             'title' => $howdy . $avatar,
    161             'href'  => $profile_url,
    162             'meta'  => array(
    163                 'class' => $class,
     147        $class  = empty( $avatar ) ? '' : 'with-avatar';
     148
     149        $wp_admin_bar->add_menu( array(
     150            'id'        => 'my-account',
     151            'secondary' => true,
     152            'title'     => $howdy . $avatar,
     153            'href'      => $profile_url,
     154            'meta'      => array(
     155                'class'     => $class,
    164156            ),
    165157        ) );
     
    323315    }
    324316
    325     if ( $wp_admin_bar->user->blogs ) {
    326         $wp_admin_bar->add_menu( array(
    327             'parent' => 'my-sites',
    328             'id'     => 'my-sites-secondary',
    329             'title'  => ' ',
    330             'meta'   => array(
    331                 'class' => 'secondary',
    332             ),
    333         ) );
    334     }
    335 
    336317    // Add blog links
    337318    $blue_wp_logo_url = includes_url('images/wpmini-blue.png');
     
    346327
    347328        $wp_admin_bar->add_menu( array(
    348             'parent' => 'my-sites-secondary',
    349             'id'     => $menu_id,
    350             'title'  => $blavatar . $blogname,
    351             'href'   => get_admin_url( $blog->userblog_id ),
     329            'parent'    => 'my-sites',
     330            'secondary' => true,
     331            'id'        => $menu_id,
     332            'title'     => $blavatar . $blogname,
     333            'href'      => get_admin_url( $blog->userblog_id ),
    352334        ) );
    353335
     
    474456 */
    475457function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
    476     $primary = $secondary = array();
     458    $actions = array();
    477459
    478460    $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
    479461
    480462    if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
    481         $primary[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
     463        $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
    482464        unset( $cpts['post'] );
    483465    }
    484466
    485467    if ( current_user_can( 'upload_files' ) )
    486         $primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
     468        $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
    487469
    488470    if ( current_user_can( 'manage_links' ) )
    489         $primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
     471        $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
    490472
    491473    if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
    492         $primary[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
     474        $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
    493475        unset( $cpts['page'] );
    494476    }
     
    500482
    501483        $key = 'post-new.php?post_type=' . $cpt->name;
    502         $primary[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
     484        $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
    503485    }
    504486
    505487    if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    506         $secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' );
    507 
    508     if ( ! $primary && ! $secondary )
     488        $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user', true );
     489
     490    if ( ! $actions )
    509491        return;
    510492
     
    512494        'id'    => 'new-content',
    513495        'title' => _x( 'Add New', 'admin bar menu group label' ),
    514         'href'  => admin_url( current( array_keys( $primary ) ) ),
    515     ) );
    516 
    517     $items = array(
    518         'new-content' => $primary,
    519         'new-content-secondary' => $secondary,
    520     );
    521 
    522     foreach ( $items as $parent => $actions ) {
    523 
    524         if ( ! empty( $actions ) && $parent == 'new-content-secondary' ) {
    525             $wp_admin_bar->add_menu( array(
    526                 'parent' => 'new-content',
    527                 'id'     => 'new-content-secondary',
    528                 'title'  => ' ',
    529                 'meta'   => array(
    530                     'class' => 'secondary',
    531                 ),
    532             ) );
    533         }
    534 
    535         foreach ( $actions as $link => $action ) {
    536             $wp_admin_bar->add_menu( array(
    537                 'parent' => $parent,
    538                 'id'     => $action[1],
    539                 'title'  => $action[0],
    540                 'href'   => admin_url( $link )
    541             ) );
    542         }
     496        'href'  => admin_url( current( array_keys( $actions ) ) ),
     497    ) );
     498
     499    foreach ( $actions as $link => $action ) {
     500        list( $title, $id ) = $action;
     501        $secondary = ! empty( $action[2] );
     502
     503        $wp_admin_bar->add_menu( array(
     504            'parent'    => 'new-content',
     505            'secondary' => $secondary,
     506            'id'        => $id,
     507            'title'     => $title,
     508            'href'      => admin_url( $link )
     509        ) );
    543510    }
    544511}
Note: See TracChangeset for help on using the changeset viewer.