Ticket #19136: 19136.diff
File 19136.diff, 13.4 KB (added by , 13 years ago) |
---|
-
wp-includes/admin-bar.php
91 91 ) ); 92 92 } 93 93 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 104 94 // Add WordPress.org link 105 95 $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'), 110 101 ) ); 111 102 112 103 // Add codex link 113 104 $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'), 118 110 ) ); 119 111 120 112 // Add forums link 121 113 $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/'), 126 119 ) ); 127 120 128 121 // Add feedback link 129 122 $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'), 134 128 ) ); 135 129 } 136 130 … … 150 144 /* Add the 'My Account' menu */ 151 145 $avatar = get_avatar( $user_id, 28 ); 152 146 $howdy = sprintf( __('Howdy, %1$s'), $user_identity ); 153 $class = 'opposite';147 $class = empty( $avatar ) ? '' : 'with-avatar'; 154 148 155 if ( ! empty( $avatar ) )156 $class .= ' with-avatar';157 158 149 $wp_admin_bar->add_menu( array( 159 'id' => 'my-account', 160 'title' => $howdy . $avatar, 161 'href' => $profile_url, 162 'meta' => array( 163 'class' => $class, 150 'id' => 'my-account', 151 'secondary' => true, 152 'title' => $howdy . $avatar, 153 'href' => $profile_url, 154 'meta' => array( 155 'class' => $class, 164 156 ), 165 157 ) ); 166 158 … … 322 314 ) ); 323 315 } 324 316 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 336 317 // Add blog links 337 318 $blue_wp_logo_url = includes_url('images/wpmini-blue.png'); 338 319 … … 345 326 $menu_id = 'blog-' . $blog->userblog_id; 346 327 347 328 $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 ), 352 334 ) ); 353 335 354 336 $wp_admin_bar->add_menu( array( … … 473 455 * @since 3.1.0 474 456 */ 475 457 function wp_admin_bar_new_content_menu( $wp_admin_bar ) { 476 $ primary = $secondary= array();458 $actions = array(); 477 459 478 460 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); 479 461 480 462 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' ); 482 464 unset( $cpts['post'] ); 483 465 } 484 466 485 467 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' ); 487 469 488 470 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' ); 490 472 491 473 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' ); 493 475 unset( $cpts['page'] ); 494 476 } 495 477 … … 499 481 continue; 500 482 501 483 $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 ); 503 485 } 504 486 505 487 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');488 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user', true ); 507 489 508 if ( ! $ primary && ! $secondary)490 if ( ! $actions ) 509 491 return; 510 492 511 493 $wp_admin_bar->add_menu( array( 512 494 'id' => 'new-content', 495 'secondary' => true, 513 496 'title' => _x( 'Add New', 'admin bar menu group label' ), 514 'href' => admin_url( current( array_keys( $ primary) ) ),497 'href' => admin_url( current( array_keys( $actions ) ) ), 515 498 ) ); 516 499 517 $items = array( 518 'new-content' => $primary, 519 'new-content-secondary' => $secondary, 520 ); 500 foreach ( $actions as $link => $action ) { 501 $action = array_pad( $action, 3, false ); 502 list( $title, $id, $secondary ) = $action; 521 503 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 } 504 $wp_admin_bar->add_menu( array( 505 'parent' => 'new-content', 506 'secondary' => $secondary, 507 'id' => $id, 508 'title' => $title, 509 'href' => admin_url( $link ) 510 ) ); 543 511 } 544 512 } 545 513 -
wp-includes/css/admin-bar.dev.css
78 78 border-right: 1px solid #333; 79 79 } 80 80 81 #wpadminbar .quicklinks > ul > li.opposite{81 #wpadminbar .quicklinks .top-secondary > li { 82 82 border-left: 1px solid #333; 83 83 border-right: 0; 84 float: right; 84 85 } 85 86 86 #wpadminbar .quicklinks > ul > li.opposite> a {87 #wpadminbar .quicklinks .top-secondary > li > a { 87 88 border-left: 1px solid #555; 88 89 border-right: 0; 89 90 } … … 117 118 border-color: #dfdfdf; 118 119 } 119 120 120 #wpadminbar .quicklinks . opposite.menupop ul {121 #wpadminbar .quicklinks .top-secondary .menupop ul { 121 122 right: 0; 122 123 margin: 0 -1px 0 0; 123 124 } … … 166 167 border-width: 1px; 167 168 } 168 169 169 #wpadminbar .quicklinks . opposite.menupop li:hover > ul,170 #wpadminbar .quicklinks . opposite.menupop li.hover > ul {170 #wpadminbar .quicklinks .top-secondary .menupop li:hover > ul, 171 #wpadminbar .quicklinks .top-secondary .menupop li.hover > ul { 171 172 margin-left: 0; 172 173 left: inherit; 173 174 right: 100%; … … 232 233 padding: 0 1.5em 0 0; 233 234 } 234 235 235 #wpadminbar . opposite.menupop li a > span {236 #wpadminbar .top-secondary .menupop li a > span { 236 237 background-position: -28px -31px; 237 238 padding: 0 0 0 1.5em; 238 239 } 239 240 240 #wpadminbar .quicklinks .menupop .secondary { 241 background: #eee; 242 margin: 6px 0 -6px; 243 border-top: 1px solid #dfdfdf; 244 } 245 246 #wpadminbar .quicklinks .menupop .secondary > a { 247 display: none; 248 } 249 250 #wpadminbar .quicklinks .menupop li.secondary > ul, 251 #wpadminbar .quicklinks .opposite.menupop li.secondary > ul { 241 #wpadminbar .quicklinks .menupop ul.sub-secondary { 252 242 display: block; 253 243 position: relative; 254 244 right: auto; 255 245 margin: 0; 256 246 border: 0; 247 257 248 background: #eee; 249 margin: 6px 0 -6px; 250 border-top: 1px solid #dfdfdf; 251 258 252 -moz-box-shadow: none; 259 253 -webkit-box-shadow: none; 260 254 box-shadow: none; 261 255 } 262 256 263 #wpadminbar .quicklinks .menupop li.secondary > ul> li:hover,264 #wpadminbar .quicklinks .menupop li.secondary > ul> li.hover,265 #wpadminbar .quicklinks .menupop li.secondary > ul> li a:focus {257 #wpadminbar .quicklinks .menupop .sub-secondary > li:hover, 258 #wpadminbar .quicklinks .menupop .sub-secondary > li.hover, 259 #wpadminbar .quicklinks .menupop .sub-secondary > li a:focus { 266 260 background: #dfdfdf; 267 261 } 268 262 … … 283 277 color: #000; 284 278 } 285 279 286 #wpadminbar li.opposite{280 #wpadminbar .top-secondary { 287 281 float: right; 288 282 } 289 283 -
wp-includes/class-wp-admin-bar.php
12 12 $this->proto = 'https://'; 13 13 14 14 $this->user = new stdClass; 15 $this->root = new stdClass; 16 $this->root->children = (object) array( 17 'primary' => array(), 18 'secondary' => array(), 19 ); 15 20 16 21 if ( is_user_logged_in() ) { 17 22 /* Populate settings we need for the menu based on the current user. */ … … 59 64 * Add a node to the menu. 60 65 * 61 66 * @param array $args - The arguments for each node. 62 * - id - string - The ID of the item. 63 * - title - string - The title of the node. 64 * - parent - string - The ID of the parent node. Optional. 65 * - href - string - The link for the item. Optional. 66 * - meta - array - Meta data including the following keys: html, class, onclick, target, title. 67 * - id - string - The ID of the item. 68 * - title - string - The title of the node. 69 * - parent - string - The ID of the parent node. Optional. 70 * - href - string - The link for the item. Optional. 71 * - secondary - boolean - If the item should be part of a secondary menu. Optional. Default false. 72 * - meta - array - Meta data including the following keys: html, class, onclick, target, title. 67 73 */ 68 74 public function add_node( $args ) { 69 75 // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ) … … 80 86 } 81 87 82 88 $defaults = array( 83 'id' => false, 84 'title' => false, 85 'parent' => false, 86 'href' => false, 87 'meta' => array(), 89 'id' => false, 90 'title' => false, 91 'parent' => false, 92 'href' => false, 93 'secondary' => false, 94 'meta' => array(), 88 95 ); 89 96 90 97 // If the node already exists, keep any data that isn't provided. … … 92 99 $defaults = (array) $this->nodes[ $args['id'] ]; 93 100 94 101 $args = wp_parse_args( $args, $defaults ); 102 $args['children'] = (object) array( 103 'primary' => array(), 104 'secondary' => array(), 105 ); 95 106 96 107 $this->nodes[ $args['id'] ] = (object) $args; 97 108 } … … 106 117 107 118 // Handle root menu items 108 119 if ( empty( $node->parent ) ) { 109 $this->root[] = $node; 110 continue; 111 } 120 $parent = $this->root; 112 121 113 122 // If the parent node isn't registered, ignore the node. 114 if ( ! isset( $this->nodes[ $node->parent ] ) )123 } elseif ( ! isset( $this->nodes[ $node->parent ] ) ) { 115 124 continue; 116 125 117 $parent = $this->nodes[ $node->parent ];118 if ( ! isset( $parent->children ) )119 $parent->children = array();126 } else { 127 $parent = $this->nodes[ $node->parent ]; 128 } 120 129 121 $parent->children[] = $node; 130 if ( $node->secondary ) 131 $parent->children->secondary[] = $node; 132 else 133 $parent->children->primary[] = $node; 122 134 } 123 135 124 136 ?> … … 126 138 <div class="quicklinks"> 127 139 <ul class="ab-top-menu"><?php 128 140 129 foreach ( $this->root as $node ) {141 foreach ( $this->root->children->primary as $node ) { 130 142 $this->recursive_render( $node ); 131 143 } 132 144 145 if ( ! empty( $this->root->children->secondary ) ): 146 ?><ul class="top-secondary"><?php 147 148 foreach ( $this->root->children->secondary as $node ) { 149 $this->recursive_render( $node ); 150 } 151 152 ?></ul><?php 153 endif; 133 154 ?></ul> 134 155 </div> 135 156 </div> … … 138 159 } 139 160 140 161 function recursive_render( $node ) { 141 $is_parent = ! empty( $node->children );162 $is_parent = ! empty( $node->children->primary ); 142 163 143 164 $menuclass = $is_parent ? 'menupop' : ''; 144 165 if ( ! empty( $node->meta['class'] ) ) … … 173 194 174 195 ?></a> 175 196 176 <?php if ( $is_parent ) : ?> 177 <ul><?php 178 179 // Render children. 180 foreach ( $node->children as $child_node ) { 197 <?php 198 if ( $is_parent ) : 199 ?><ul><?php 200 foreach ( $node->children->primary as $child_node ) { 181 201 $this->recursive_render( $child_node ); 182 202 } 183 203 184 ?></ul> 185 <?php endif; 204 if ( ! empty( $node->children->secondary ) ): 205 ?><ul class="sub-secondary"><?php 206 foreach ( $node->children->secondary as $child_node ) { 207 $this->recursive_render( $child_node ); 208 } 209 ?></ul><?php 210 endif; 211 ?></ul><?php 212 endif; 186 213 187 214 if ( ! empty( $node->meta['html'] ) ) 188 215 echo $node->meta['html'];