Add secondary flag to admin bar. fixes #19136.

git-svn-id: http://svn.automattic.com/wordpress/trunk@19230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
koopersmith 2011-11-09 19:12:48 +00:00
parent a57f6b0271
commit 4de1815c67
5 changed files with 123 additions and 135 deletions

View File

@ -91,46 +91,40 @@ function wp_admin_bar_wp_menu( $wp_admin_bar ) {
) ); ) );
} }
// Add secondary menu.
$wp_admin_bar->add_menu( array(
'parent' => 'wp-logo',
'id' => 'wp-logo-secondary',
'title' => ' ',
'meta' => array(
'class' => 'secondary',
),
) );
// Add WordPress.org link // Add WordPress.org link
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'parent' => 'wp-logo-secondary', 'parent' => 'wp-logo',
'id' => 'wporg', 'secondary' => true,
'title' => __('WordPress.org'), 'id' => 'wporg',
'href' => __('http://wordpress.org'), 'title' => __('WordPress.org'),
'href' => __('http://wordpress.org'),
) ); ) );
// Add codex link // Add codex link
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'parent' => 'wp-logo-secondary', 'parent' => 'wp-logo',
'id' => 'documentation', 'secondary' => true,
'title' => __('Documentation'), 'id' => 'documentation',
'href' => __('http://codex.wordpress.org'), 'title' => __('Documentation'),
'href' => __('http://codex.wordpress.org'),
) ); ) );
// Add forums link // Add forums link
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'parent' => 'wp-logo-secondary', 'parent' => 'wp-logo',
'id' => 'support-forums', 'secondary' => true,
'title' => __('Support Forums'), 'id' => 'support-forums',
'href' => __('http://wordpress.org/support/'), 'title' => __('Support Forums'),
'href' => __('http://wordpress.org/support/'),
) ); ) );
// Add feedback link // Add feedback link
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'parent' => 'wp-logo-secondary', 'parent' => 'wp-logo',
'id' => 'feedback', 'secondary' => true,
'title' => __('Feedback'), 'id' => 'feedback',
'href' => __('http://wordpress.org/support/forum/requests-and-feedback'), 'title' => __('Feedback'),
'href' => __('http://wordpress.org/support/forum/requests-and-feedback'),
) ); ) );
} }
@ -150,17 +144,15 @@ function wp_admin_bar_my_account_menu( $wp_admin_bar ) {
/* Add the 'My Account' menu */ /* Add the 'My Account' menu */
$avatar = get_avatar( $user_id, 28 ); $avatar = get_avatar( $user_id, 28 );
$howdy = sprintf( __('Howdy, %1$s'), $user_identity ); $howdy = sprintf( __('Howdy, %1$s'), $user_identity );
$class = 'opposite'; $class = empty( $avatar ) ? '' : 'with-avatar';
if ( ! empty( $avatar ) )
$class .= ' with-avatar';
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'id' => 'my-account', 'id' => 'my-account',
'title' => $howdy . $avatar, 'secondary' => true,
'href' => $profile_url, 'title' => $howdy . $avatar,
'meta' => array( 'href' => $profile_url,
'class' => $class, 'meta' => array(
'class' => $class,
), ),
) ); ) );
@ -322,17 +314,6 @@ function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
) ); ) );
} }
if ( $wp_admin_bar->user->blogs ) {
$wp_admin_bar->add_menu( array(
'parent' => 'my-sites',
'id' => 'my-sites-secondary',
'title' => ' ',
'meta' => array(
'class' => 'secondary',
),
) );
}
// Add blog links // Add blog links
$blue_wp_logo_url = includes_url('images/wpmini-blue.png'); $blue_wp_logo_url = includes_url('images/wpmini-blue.png');
@ -345,10 +326,11 @@ function wp_admin_bar_my_sites_menu( $wp_admin_bar ) {
$menu_id = 'blog-' . $blog->userblog_id; $menu_id = 'blog-' . $blog->userblog_id;
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'parent' => 'my-sites-secondary', 'parent' => 'my-sites',
'id' => $menu_id, 'secondary' => true,
'title' => $blavatar . $blogname, 'id' => $menu_id,
'href' => get_admin_url( $blog->userblog_id ), 'title' => $blavatar . $blogname,
'href' => get_admin_url( $blog->userblog_id ),
) ); ) );
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
@ -473,23 +455,23 @@ function wp_admin_bar_edit_menu( $wp_admin_bar ) {
* @since 3.1.0 * @since 3.1.0
*/ */
function wp_admin_bar_new_content_menu( $wp_admin_bar ) { function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
$primary = $secondary = array(); $actions = array();
$cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' );
if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) { if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->edit_posts ) ) {
$primary[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' );
unset( $cpts['post'] ); unset( $cpts['post'] );
} }
if ( current_user_can( 'upload_files' ) ) if ( current_user_can( 'upload_files' ) )
$primary[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' ); $actions[ 'media-new.php' ] = array( _x( 'Media', 'add new from admin bar' ), 'new-media' );
if ( current_user_can( 'manage_links' ) ) if ( current_user_can( 'manage_links' ) )
$primary[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' );
if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) { if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->edit_posts ) ) {
$primary[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' );
unset( $cpts['page'] ); unset( $cpts['page'] );
} }
@ -499,47 +481,32 @@ function wp_admin_bar_new_content_menu( $wp_admin_bar ) {
continue; continue;
$key = 'post-new.php?post_type=' . $cpt->name; $key = 'post-new.php?post_type=' . $cpt->name;
$primary[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name );
} }
if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) )
$secondary[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user', true );
if ( ! $primary && ! $secondary ) if ( ! $actions )
return; return;
$wp_admin_bar->add_menu( array( $wp_admin_bar->add_menu( array(
'id' => 'new-content', 'id' => 'new-content',
'title' => _x( 'Add New', 'admin bar menu group label' ), 'title' => _x( 'Add New', 'admin bar menu group label' ),
'href' => admin_url( current( array_keys( $primary ) ) ), 'href' => admin_url( current( array_keys( $actions ) ) ),
) ); ) );
$items = array( foreach ( $actions as $link => $action ) {
'new-content' => $primary, list( $title, $id ) = $action;
'new-content-secondary' => $secondary, $secondary = ! empty( $action[2] );
);
foreach ( $items as $parent => $actions ) { $wp_admin_bar->add_menu( array(
'parent' => 'new-content',
if ( ! empty( $actions ) && $parent == 'new-content-secondary' ) { 'secondary' => $secondary,
$wp_admin_bar->add_menu( array( 'id' => $id,
'parent' => 'new-content', 'title' => $title,
'id' => 'new-content-secondary', 'href' => admin_url( $link )
'title' => ' ', ) );
'meta' => array(
'class' => 'secondary',
),
) );
}
foreach ( $actions as $link => $action ) {
$wp_admin_bar->add_menu( array(
'parent' => $parent,
'id' => $action[1],
'title' => $action[0],
'href' => admin_url( $link )
) );
}
} }
} }

View File

@ -12,6 +12,11 @@ class WP_Admin_Bar {
$this->proto = 'https://'; $this->proto = 'https://';
$this->user = new stdClass; $this->user = new stdClass;
$this->root = new stdClass;
$this->root->children = (object) array(
'primary' => array(),
'secondary' => array(),
);
if ( is_user_logged_in() ) { if ( is_user_logged_in() ) {
/* Populate settings we need for the menu based on the current user. */ /* Populate settings we need for the menu based on the current user. */
@ -59,11 +64,12 @@ class WP_Admin_Bar {
* Add a node to the menu. * Add a node to the menu.
* *
* @param array $args - The arguments for each node. * @param array $args - The arguments for each node.
* - id - string - The ID of the item. * - id - string - The ID of the item.
* - title - string - The title of the node. * - title - string - The title of the node.
* - parent - string - The ID of the parent node. Optional. * - parent - string - The ID of the parent node. Optional.
* - href - string - The link for the item. Optional. * - href - string - The link for the item. Optional.
* - meta - array - Meta data including the following keys: html, class, onclick, target, title. * - secondary - boolean - If the item should be part of a secondary menu. Optional. Default false.
* - meta - array - Meta data including the following keys: html, class, onclick, target, title.
*/ */
public function add_node( $args ) { public function add_node( $args ) {
// Shim for old method signature: add_node( $parent_id, $menu_obj, $args ) // Shim for old method signature: add_node( $parent_id, $menu_obj, $args )
@ -80,11 +86,12 @@ class WP_Admin_Bar {
} }
$defaults = array( $defaults = array(
'id' => false, 'id' => false,
'title' => false, 'title' => false,
'parent' => false, 'parent' => false,
'href' => false, 'href' => false,
'meta' => array(), 'secondary' => false,
'meta' => array(),
); );
// If the node already exists, keep any data that isn't provided. // If the node already exists, keep any data that isn't provided.
@ -92,6 +99,10 @@ class WP_Admin_Bar {
$defaults = (array) $this->nodes[ $args['id'] ]; $defaults = (array) $this->nodes[ $args['id'] ];
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
$args['children'] = (object) array(
'primary' => array(),
'secondary' => array(),
);
$this->nodes[ $args['id'] ] = (object) $args; $this->nodes[ $args['id'] ] = (object) $args;
} }
@ -106,19 +117,20 @@ class WP_Admin_Bar {
// Handle root menu items // Handle root menu items
if ( empty( $node->parent ) ) { if ( empty( $node->parent ) ) {
$this->root[] = $node; $parent = $this->root;
continue;
}
// If the parent node isn't registered, ignore the node. // If the parent node isn't registered, ignore the node.
if ( ! isset( $this->nodes[ $node->parent ] ) ) } elseif ( ! isset( $this->nodes[ $node->parent ] ) ) {
continue; continue;
$parent = $this->nodes[ $node->parent ]; } else {
if ( ! isset( $parent->children ) ) $parent = $this->nodes[ $node->parent ];
$parent->children = array(); }
$parent->children[] = $node; if ( $node->secondary )
$parent->children->secondary[] = $node;
else
$parent->children->primary[] = $node;
} }
?> ?>
@ -126,10 +138,19 @@ class WP_Admin_Bar {
<div class="quicklinks"> <div class="quicklinks">
<ul class="ab-top-menu"><?php <ul class="ab-top-menu"><?php
foreach ( $this->root as $node ) { foreach ( $this->root->children->primary as $node ) {
$this->recursive_render( $node ); $this->recursive_render( $node );
} }
if ( ! empty( $this->root->children->secondary ) ):
?><ul class="top-secondary"><?php
foreach ( $this->root->children->secondary as $node ) {
$this->recursive_render( $node );
}
?></ul><?php
endif;
?></ul> ?></ul>
</div> </div>
</div> </div>
@ -138,7 +159,7 @@ class WP_Admin_Bar {
} }
function recursive_render( $node ) { function recursive_render( $node ) {
$is_parent = ! empty( $node->children ); $is_parent = ! empty( $node->children->primary );
$menuclass = $is_parent ? 'menupop' : ''; $menuclass = $is_parent ? 'menupop' : '';
if ( ! empty( $node->meta['class'] ) ) if ( ! empty( $node->meta['class'] ) )
@ -173,16 +194,22 @@ class WP_Admin_Bar {
?></a> ?></a>
<?php if ( $is_parent ) : ?> <?php
<ul><?php if ( $is_parent ) :
?><ul><?php
// Render children. foreach ( $node->children->primary as $child_node ) {
foreach ( $node->children as $child_node ) {
$this->recursive_render( $child_node ); $this->recursive_render( $child_node );
} }
?></ul> if ( ! empty( $node->children->secondary ) ):
<?php endif; ?><ul class="sub-secondary"><?php
foreach ( $node->children->secondary as $child_node ) {
$this->recursive_render( $child_node );
}
?></ul><?php
endif;
?></ul><?php
endif;
if ( ! empty( $node->meta['html'] ) ) if ( ! empty( $node->meta['html'] ) )
echo $node->meta['html']; echo $node->meta['html'];

File diff suppressed because one or more lines are too long

View File

@ -78,12 +78,13 @@
border-right: 1px solid #333; border-right: 1px solid #333;
} }
#wpadminbar .quicklinks > ul > li.opposite { #wpadminbar .quicklinks .top-secondary > li {
border-left: 1px solid #333; border-left: 1px solid #333;
border-right: 0; border-right: 0;
float: right;
} }
#wpadminbar .quicklinks > ul > li.opposite > a { #wpadminbar .quicklinks .top-secondary > li > a {
border-left: 1px solid #555; border-left: 1px solid #555;
border-right: 0; border-right: 0;
} }
@ -117,7 +118,7 @@
border-color: #dfdfdf; border-color: #dfdfdf;
} }
#wpadminbar .quicklinks .opposite.menupop ul { #wpadminbar .quicklinks .top-secondary .menupop ul {
right: 0; right: 0;
margin: 0 -1px 0 0; margin: 0 -1px 0 0;
} }
@ -166,8 +167,8 @@
border-width: 1px; border-width: 1px;
} }
#wpadminbar .quicklinks .opposite.menupop li:hover > ul, #wpadminbar .quicklinks .top-secondary .menupop li:hover > ul,
#wpadminbar .quicklinks .opposite.menupop li.hover > ul { #wpadminbar .quicklinks .top-secondary .menupop li.hover > ul {
margin-left: 0; margin-left: 0;
left: inherit; left: inherit;
right: 100%; right: 100%;
@ -232,37 +233,30 @@
padding: 0 1.5em 0 0; padding: 0 1.5em 0 0;
} }
#wpadminbar .opposite.menupop li a > span { #wpadminbar .top-secondary .menupop li a > span {
background-position: -28px -31px; background-position: -28px -31px;
padding: 0 0 0 1.5em; padding: 0 0 0 1.5em;
} }
#wpadminbar .quicklinks .menupop .secondary { #wpadminbar .quicklinks .menupop ul.sub-secondary {
background: #eee;
margin: 6px 0 -6px;
border-top: 1px solid #dfdfdf;
}
#wpadminbar .quicklinks .menupop .secondary > a {
display: none;
}
#wpadminbar .quicklinks .menupop li.secondary > ul,
#wpadminbar .quicklinks .opposite.menupop li.secondary > ul {
display: block; display: block;
position: relative; position: relative;
right: auto; right: auto;
margin: 0; margin: 0;
border: 0; border: 0;
background: #eee; background: #eee;
margin: 6px 0 -6px;
border-top: 1px solid #dfdfdf;
-moz-box-shadow: none; -moz-box-shadow: none;
-webkit-box-shadow: none; -webkit-box-shadow: none;
box-shadow: none; box-shadow: none;
} }
#wpadminbar .quicklinks .menupop li.secondary > ul > li:hover, #wpadminbar .quicklinks .menupop .sub-secondary > li:hover,
#wpadminbar .quicklinks .menupop li.secondary > ul > li.hover, #wpadminbar .quicklinks .menupop .sub-secondary > li.hover,
#wpadminbar .quicklinks .menupop li.secondary > ul > li a:focus { #wpadminbar .quicklinks .menupop .sub-secondary > li a:focus {
background: #dfdfdf; background: #dfdfdf;
} }
@ -283,7 +277,7 @@
color: #000; color: #000;
} }
#wpadminbar li.opposite { #wpadminbar .top-secondary {
float: right; float: right;
} }

View File

@ -452,7 +452,7 @@ function wp_default_styles( &$styles ) {
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.3u1' ); $styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.3u1' );
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' ); $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' ); $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' );
$styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array(), '20111108a' ); $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array(), '20111109' );
$styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array(), '20111107' ); $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array(), '20111107' );
$styles->add( 'editor-buttons', "/wp-includes/css/editor-buttons$suffix.css", array(), '20111107' ); $styles->add( 'editor-buttons', "/wp-includes/css/editor-buttons$suffix.css", array(), '20111107' );
$styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array(), '20111017' ); $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array(), '20111017' );