Make WordPress Core

Changeset 19429


Ignore:
Timestamp:
11/23/2011 09:46:47 PM (12 years ago)
Author:
koopersmith
Message:

Admin Bar: Secondary is so passé. Groups are the new black. fixes #19136.

Location:
trunk/wp-includes
Files:
4 edited

Legend:

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

    r19405 r19429  
    9191    // Add WordPress.org link
    9292    $wp_admin_bar->add_menu( array(
    93         'parent'    => 'wp-logo',
    94         'secondary' => true,
     93        'parent'    => 'wp-logo-external',
    9594        'id'        => 'wporg',
    9695        'title'     => __('WordPress.org'),
     
    10099    // Add codex link
    101100    $wp_admin_bar->add_menu( array(
    102         'parent'    => 'wp-logo',
    103         'secondary' => true,
     101        'parent'    => 'wp-logo-external',
    104102        'id'        => 'documentation',
    105103        'title'     => __('Documentation'),
     
    109107    // Add forums link
    110108    $wp_admin_bar->add_menu( array(
    111         'parent'    => 'wp-logo',
    112         'secondary' => true,
     109        'parent'    => 'wp-logo-external',
    113110        'id'        => 'support-forums',
    114111        'title'     => __('Support Forums'),
     
    118115    // Add feedback link
    119116    $wp_admin_bar->add_menu( array(
    120         'parent'    => 'wp-logo',
    121         'secondary' => true,
     117        'parent'    => 'wp-logo-external',
    122118        'id'        => 'feedback',
    123119        'title'     => __('Feedback'),
     
    144140        $wp_admin_bar->add_menu( array(
    145141            'id'        => 'my-account',
    146             'secondary' => true,
     142            'parent'    => 'top-secondary',
    147143            'title'     => $howdy . $avatar,
    148144            'href'      => $profile_url,
     
    166162            'href'   => $profile_url,
    167163            'meta'   => array(
    168                 'class' => 'user-info user-info-item',
    169164                'tabindex' => -1
    170165            ),
     
    175170            'title'  => __( 'Edit My Profile' ),
    176171            'href' => $profile_url,
    177             'meta'   => array(
    178                 'class' => 'user-info-item',
    179             ),
    180172        ) );
    181173        $wp_admin_bar->add_menu( array(
     
    184176            'title'  => __( 'Log Out' ),
    185177            'href'   => wp_logout_url(),
    186             'meta'   => array(
    187                 'class' => 'user-info-item',
    188             ),
    189178        ) );
    190179    }
     
    277266
    278267    if ( is_super_admin() ) {
    279         $wp_admin_bar->add_menu( array(
     268        $wp_admin_bar->add_group( array(
    280269            'parent' => 'my-sites',
     270            'id'     => 'my-sites-super-admin',
     271        ) );
     272
     273        $wp_admin_bar->add_menu( array(
     274            'parent' => 'my-sites-super-admin',
    281275            'id'     => 'network-admin',
    282276            'title'  => __('Network Admin'),
     
    310304    }
    311305
    312     // Add blog links
     306    // Add site links
     307    $wp_admin_bar->add_group( array(
     308        'parent' => 'my-sites',
     309        'id'     => 'my-sites-list',
     310        'meta'   => array(
     311            'class' => is_super_admin() ? 'ab-sub-secondary' : '',
     312        ),
     313    ) );
     314
    313315    $blue_wp_logo_url = includes_url('images/wpmini-blue.png');
    314316
     
    322324
    323325        $wp_admin_bar->add_menu( array(
    324             'parent'    => 'my-sites',
    325             'secondary' => is_super_admin(),
     326            'parent'    => 'my-sites-list',
    326327            'id'        => $menu_id,
    327328            'title'     => $blavatar . $blogname,
     
    481482
    482483    if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
    483         $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user', true );
     484        $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user', 'new-secondary-object' );
    484485
    485486    if ( ! $actions )
     
    494495    foreach ( $actions as $link => $action ) {
    495496        list( $title, $id ) = $action;
    496         $secondary = ! empty( $action[2] );
    497 
    498         $wp_admin_bar->add_menu( array(
    499             'parent'    => 'new-content',
    500             'secondary' => $secondary,
     497        $parent = empty( $action[2] ) ? 'new-content' : $action[2];
     498
     499        $wp_admin_bar->add_menu( array(
     500            'parent'    => $parent,
    501501            'id'        => $id,
    502502            'title'     => $title,
     
    600600
    601601/**
     602 * Add secondary menus.
     603 *
     604 * @since 3.3.0
     605 */
     606function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) {
     607    $wp_admin_bar->add_group( array(
     608        'id'     => 'top-secondary',
     609        'meta'   => array(
     610            'class' => 'ab-top-secondary',
     611        ),
     612    ) );
     613
     614    $wp_admin_bar->add_group( array(
     615        'parent' => 'wp-logo',
     616        'id'     => 'wp-logo-external',
     617        'meta'   => array(
     618            'class' => 'ab-sub-secondary',
     619        ),
     620    ) );
     621
     622    $wp_admin_bar->add_group( array(
     623        'parent' => 'new-content',
     624        'id'     => 'new-secondary-object',
     625        'meta'   => array(
     626            'class' => 'ab-sub-secondary',
     627        ),
     628    ) );
     629}
     630
     631/**
    602632 * Style and scripts for the admin bar.
    603633 *
  • trunk/wp-includes/class-wp-admin-bar.php

    r19407 r19429  
    1313
    1414        $this->user = new stdClass;
    15         $this->root = new stdClass;
    16         $this->root->children  = (object) array(
    17             'primary'   => array(),
    18             'secondary' => array(),
     15        $this->root = (object) array(
     16            'id'       => 'root',
     17            'group'    => false,
     18            'children' => array(),
    1919        );
    2020
     
    6969     * - parent     - string    - The ID of the parent node. Optional.
    7070     * - href       - string    - The link for the item. Optional.
    71      * - secondary  - boolean   - If the item should be part of a secondary menu. Optional. Default false.
     71     * - group      - boolean   - If the node is a group. Optional. Default false.
    7272     * - meta       - array     - Meta data including the following keys: html, class, onclick, target, title.
    7373     */
     
    7878
    7979        // Ensure we have a valid title.
    80         if ( empty( $args['title'] ) )
    81             return false;
    82 
    8380        if ( empty( $args['id'] ) ) {
     81            if ( empty( $args['title'] ) )
     82                return;
     83
    8484            _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3' );
     85            // Deprecated: Generate an ID from the title.
    8586            $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) );
    8687        }
    8788
    8889        $defaults = array(
    89             'id'        => false,
    90             'title'     => false,
    91             'parent'    => false,
    92             'href'      => false,
    93             'secondary' => false,
    94             'meta'      => array(),
     90            'id'     => false,
     91            'title'  => false,
     92            'parent' => false,
     93            'href'   => false,
     94            'group' => false,
     95            'meta'   => array(),
    9596        );
    9697
     
    100101
    101102        $args = wp_parse_args( $args, $defaults );
    102         $args['children'] = (object) array(
    103             'primary'   => array(),
    104             'secondary' => array(),
    105         );
     103        $args['children'] = array();
    106104
    107105        $this->nodes[ $args['id'] ] = (object) $args;
     106    }
     107
     108    /**
     109     * Add a group to a menu node.
     110     *
     111     * @param array $args - The arguments for each node.
     112     * - id         - string    - The ID of the item.
     113     * - parent     - string    - The ID of the parent node. Optional. Default root.
     114     * - meta       - array     - Meta data including the following keys: class, onclick, target, title.
     115     */
     116    public function add_group( $args ) {
     117        $args['group'] = true;
     118
     119        $this->add_node( $args );
    108120    }
    109121
     
    137149            }
    138150
    139             if ( $node->secondary )
    140                 $parent->children->secondary[] = $node;
    141             else
    142                 $parent->children->primary[] = $node;
     151
     152            // Ensure that our tree is of the form "item -> group -> item -> group -> ..."
     153            if ( ! $parent->group && ! $node->group ) { // Both are items.
     154                // The default group is added here to allow groups that are
     155                // added before standard menu items to render first.
     156                if ( ! isset( $parent->children['default'] ) ) {
     157                    $parent->children['default'] = (object) array(
     158                        'id'       => "{$parent->id}-default",
     159                        'parent'   => $parent->id,
     160                        'group'    => true,
     161                        'children' => array(),
     162                    );
     163                }
     164                $parent = $parent->children['default'];
     165            }
     166
     167            // Update the parent ID (it might have changed).
     168            $node->parent = $parent->id;
     169
     170            // Add the node to the tree.
     171            $parent->children[] = $node;
    143172        }
    144173
     
    160189        <div id="wpadminbar" class="<?php echo $class; ?>">
    161190            <div class="quicklinks">
    162                 <ul class="ab-top-menu"><?php
    163 
    164                     foreach ( $this->root->children->primary as $node ) {
    165                         $this->recursive_render( $node );
    166                     }
    167 
    168                 ?></ul>
    169                 <ul class="ab-top-menu ab-top-secondary"><?php
    170 
    171                     foreach ( $this->root->children->secondary as $node ) {
    172                         $this->recursive_render( $node );
    173                     }
    174 
    175                 ?></ul>
     191                <?php foreach ( $this->root->children as $group ) {
     192                    $this->render_group( $group, 'ab-top-menu' );
     193                } ?>
    176194            </div>
    177195        </div>
     
    180198    }
    181199
    182     function recursive_render( $node ) {
    183         if ( ! $node->children->primary && $node->children->secondary ) {
    184             $node->children->primary = $node->children->secondary;
    185             $node->children->secondary = array();
    186         }
    187 
    188         $is_parent = (bool) $node->children->primary;
     200    private function render_group( $node, $class = '' ) {
     201        if ( ! $node->group )
     202            return;
     203
     204        // Check for groups within groups.
     205        $groups = array();
     206        foreach ( $node->children as $child ) {
     207            if ( $child->group ) {
     208                $groups[] = $child;
     209            } else {
     210                if ( ! isset( $default ) ) {
     211                    // Create a default proxy item to be used in the case of nested groups.
     212                    $default  = (object) wp_parse_args( array( 'children' => array() ), (array) $node );
     213                    $groups[] = $default;
     214                }
     215                $default->children[] = $child;
     216            }
     217        }
     218
     219        $is_single_group = count( $groups ) === 1;
     220
     221
     222        // If we don't have any subgroups, render the group.
     223        if ( $is_single_group && ! empty( $node->children ) ):
     224
     225            if ( ! empty( $node->meta['class'] ) )
     226                $class .= ' ' . $node->meta['class'];
     227
     228            ?><ul id="<?php echo esc_attr( "wp-admin-bar-{$node->id}" ); ?>" class="<?php echo esc_attr( $class ); ?>"><?php
     229                foreach ( $node->children as $item ) {
     230                    $this->render_item( $item );
     231                }
     232            ?></ul><?php
     233
     234        // Wrap the subgroups in a div and render each individual subgroup.
     235        elseif ( ! $is_single_group ):
     236            ?><div id="<?php echo esc_attr( "wp-admin-bar-{$node->id}-container" ); ?>" class="ab-group-container"><?php
     237                foreach ( $groups as $group ) {
     238                    $this->render_group( $group, $class );
     239                }
     240            ?></div><?php
     241        endif;
     242    }
     243
     244    private function render_item( $node ) {
     245        if ( $node->group )
     246            return;
     247
     248        $is_parent = (bool) $node->children;
    189249        $has_link  = (bool) $node->href;
    190250
     
    223283            if ( $is_parent ) :
    224284                ?><div class="ab-sub-wrapper"><?php
    225 
    226                     // Render primary submenu
    227                     ?><ul class="ab-submenu"><?php
    228                     foreach ( $node->children->primary as $child_node ) {
    229                         $this->recursive_render( $child_node );
     285                    foreach ( $node->children as $group ) {
     286                        $this->render_group( $group, 'ab-submenu' );
    230287                    }
    231                     ?></ul><?php
    232 
    233                     // Render secondary submenu
    234                     if ( ! empty( $node->children->secondary ) ):
    235                         ?><ul class="ab-submenu ab-sub-secondary"><?php
    236                         foreach ( $node->children->secondary as $child_node ) {
    237                             $this->recursive_render( $child_node );
    238                         }
    239                         ?></ul><?php
    240                     endif;
    241 
    242288                ?></div><?php
    243289            endif;
     
    248294            ?>
    249295        </li><?php
    250 
     296    }
     297
     298    function recursive_render( $node ) {
     299        $this->render_item( $node );
    251300    }
    252301
     
    272321            add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 100 );
    273322
     323        add_action( 'admin_bar_menu', 'wp_admin_bar_add_secondary_groups', 200 );
     324
    274325        do_action( 'add_admin_bar_menus' );
    275326    }
  • trunk/wp-includes/css/admin-bar-rtl.dev.css

    r19368 r19429  
    108108 * My Account
    109109 */
    110 #wpadminbar #wp-admin-bar-my-account.with-avatar .user-info-item {
     110#wpadminbar #wp-admin-bar-my-account.with-avatar #wp-admin-bar-my-account-default > li {
    111111    margin-right: 88px;
    112112    margin-left: 16px;
    113113}
    114114
    115 #wpadminbar #wp-admin-bar-my-account .user-info-item > a {
     115#wp-admin-bar-my-account-default > li > .ab-item {
    116116    padding-left: 0;
    117117    padding-right: 8px;
    118118}
    119119
    120 #wp-admin-bar-my-account .user-info .avatar {
     120#wp-admin-bar-user-info .avatar {
    121121    left: auto;
    122122    right: -72px;
  • trunk/wp-includes/css/admin-bar.dev.css

    r19413 r19429  
    136136}
    137137
     138#wpadminbar .ab-sub-wrapper > .ab-submenu:first-child {
     139    border-top: none;
     140}
     141
    138142#wpadminbar .ab-submenu {
    139143    padding: 6px 0;
     144    border-top: 1px solid #dfdfdf;
    140145}
    141146
     
    248253    right: auto;
    249254    margin: 0;
    250     border: 0;
    251255
    252256    background: #eee;
    253     border-top: 1px solid #dfdfdf;
    254257
    255258    -moz-box-shadow: none;
     
    311314}
    312315
    313 #wpadminbar #wp-admin-bar-my-account .user-info-item {
     316#wpadminbar #wp-admin-bar-my-account-default > li {
    314317    margin-left: 16px;
    315318    margin-right: 16px;
    316319}
    317320
    318 #wpadminbar #wp-admin-bar-my-account.with-avatar .user-info-item {
     321#wpadminbar #wp-admin-bar-my-account.with-avatar #wp-admin-bar-my-account-default > li {
    319322    margin-left: 88px;
    320323}
    321324
    322 #wpadminbar #wp-admin-bar-my-account .user-info-item > a {
     325#wp-admin-bar-my-account-default > li > .ab-item {
    323326    padding-left: 8px;
    324327}
    325328
    326 #wpadminbar #wp-admin-bar-my-account .user-info {
     329#wpadminbar #wp-admin-bar-user-info {
    327330    margin-top: 6px;
    328331    margin-bottom: 15px;
     
    331334}
    332335
    333 #wp-admin-bar-my-account .user-info .avatar {
     336#wp-admin-bar-user-info .avatar {
    334337    position: absolute;
    335338    left: -72px;
     
    337340}
    338341
    339 #wpadminbar #wp-admin-bar-my-account .user-info a {
     342#wpadminbar #wp-admin-bar-user-info a {
    340343    height: auto;
    341344}
    342345
    343 #wpadminbar #wp-admin-bar-my-account .user-info span {
     346#wpadminbar #wp-admin-bar-user-info span {
    344347    background: none;
    345348    padding: 0;
     
    347350}
    348351
    349 #wpadminbar #wp-admin-bar-my-account .user-info .display-name,
    350 #wpadminbar #wp-admin-bar-my-account .user-info .username {
     352#wpadminbar #wp-admin-bar-user-info .display-name,
     353#wpadminbar #wp-admin-bar-user-info .username {
    351354    text-shadow: none;
    352355    display: block;
    353356}
    354 #wpadminbar #wp-admin-bar-my-account .user-info .display-name {
     357#wpadminbar #wp-admin-bar-user-info .display-name {
    355358    color: #333;
    356359}
    357360
    358 #wpadminbar #wp-admin-bar-my-account .user-info .username {
     361#wpadminbar #wp-admin-bar-user-info .username {
    359362    color: #999;
    360363    font-size: 11px;
Note: See TracChangeset for help on using the changeset viewer.