Ticket #19136: groups.3.diff
File groups.3.diff, 15.0 KB (added by , 13 years ago) |
---|
-
wp-includes/admin-bar.php
90 90 91 91 // Add WordPress.org link 92 92 $wp_admin_bar->add_menu( array( 93 'parent' => 'wp-logo', 94 'secondary' => true, 93 'parent' => 'wp-logo-external', 95 94 'id' => 'wporg', 96 95 'title' => __('WordPress.org'), 97 96 'href' => __('http://wordpress.org'), … … 99 98 100 99 // Add codex link 101 100 $wp_admin_bar->add_menu( array( 102 'parent' => 'wp-logo', 103 'secondary' => true, 101 'parent' => 'wp-logo-external', 104 102 'id' => 'documentation', 105 103 'title' => __('Documentation'), 106 104 'href' => __('http://codex.wordpress.org'), … … 108 106 109 107 // Add forums link 110 108 $wp_admin_bar->add_menu( array( 111 'parent' => 'wp-logo', 112 'secondary' => true, 109 'parent' => 'wp-logo-external', 113 110 'id' => 'support-forums', 114 111 'title' => __('Support Forums'), 115 112 'href' => __('http://wordpress.org/support/'), … … 117 114 118 115 // Add feedback link 119 116 $wp_admin_bar->add_menu( array( 120 'parent' => 'wp-logo', 121 'secondary' => true, 117 'parent' => 'wp-logo-external', 122 118 'id' => 'feedback', 123 119 'title' => __('Feedback'), 124 120 'href' => __('http://wordpress.org/support/forum/requests-and-feedback'), … … 143 139 144 140 $wp_admin_bar->add_menu( array( 145 141 'id' => 'my-account', 146 ' secondary' => true,142 'parent' => 'top-secondary', 147 143 'title' => $howdy . $avatar, 148 144 'href' => $profile_url, 149 145 'meta' => array( … … 165 161 'title' => $user_info, 166 162 'href' => $profile_url, 167 163 'meta' => array( 168 'class' => 'user-info user-info-item',169 164 'tabindex' => -1 170 165 ), 171 166 ) ); … … 174 169 'id' => 'edit-profile', 175 170 'title' => __( 'Edit My Profile' ), 176 171 'href' => $profile_url, 177 'meta' => array(178 'class' => 'user-info-item',179 ),180 172 ) ); 181 173 $wp_admin_bar->add_menu( array( 182 174 'parent' => 'my-account', 183 175 'id' => 'logout', 184 176 'title' => __( 'Log Out' ), 185 177 'href' => wp_logout_url(), 186 'meta' => array(187 'class' => 'user-info-item',188 ),189 178 ) ); 190 179 } 191 180 } … … 276 265 ) ); 277 266 278 267 if ( is_super_admin() ) { 268 $wp_admin_bar->add_group( array( 269 'parent' => 'my-sites', 270 'id' => 'my-sites-super-admin', 271 ) ); 272 279 273 $wp_admin_bar->add_menu( array( 280 'parent' => 'my-sites ',274 'parent' => 'my-sites-super-admin', 281 275 'id' => 'network-admin', 282 276 'title' => __('Network Admin'), 283 277 'href' => network_admin_url(), … … 309 303 ) ); 310 304 } 311 305 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 313 315 $blue_wp_logo_url = includes_url('images/wpmini-blue.png'); 314 316 315 317 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { … … 321 323 $menu_id = 'blog-' . $blog->userblog_id; 322 324 323 325 $wp_admin_bar->add_menu( array( 324 'parent' => 'my-sites', 325 'secondary' => is_super_admin(), 326 'parent' => 'my-sites-list', 326 327 'id' => $menu_id, 327 328 'title' => $blavatar . $blogname, 328 329 'href' => get_admin_url( $blog->userblog_id ), … … 480 481 } 481 482 482 483 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' ); 484 485 485 486 if ( ! $actions ) 486 487 return; … … 493 494 494 495 foreach ( $actions as $link => $action ) { 495 496 list( $title, $id ) = $action; 496 $ secondary = ! empty( $action[2] );497 $parent = empty( $action[2] ) ? 'new-content' : $action[2]; 497 498 498 499 $wp_admin_bar->add_menu( array( 499 'parent' => 'new-content', 500 'secondary' => $secondary, 500 'parent' => $parent, 501 501 'id' => $id, 502 502 'title' => $title, 503 503 'href' => admin_url( $link ) … … 599 599 } 600 600 601 601 /** 602 * Add secondary menus. 603 * 604 * @since 3.3.0 605 */ 606 function 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 /** 602 632 * Style and scripts for the admin bar. 603 633 * 604 634 * @since 3.1.0 -
wp-includes/css/admin-bar-rtl.dev.css
107 107 /** 108 108 * My Account 109 109 */ 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 { 111 111 margin-right: 88px; 112 112 margin-left: 16px; 113 113 } 114 114 115 #wp adminbar #wp-admin-bar-my-account .user-info-item > a{115 #wp-admin-bar-my-account-default > li > .ab-item { 116 116 padding-left: 0; 117 117 padding-right: 8px; 118 118 } 119 119 120 #wp-admin-bar- my-account .user-info .avatar {120 #wp-admin-bar-user-info .avatar { 121 121 left: auto; 122 122 right: -72px; 123 123 } -
wp-includes/css/admin-bar.dev.css
135 135 margin: 0 -1px 0 0; 136 136 } 137 137 138 #wpadminbar .ab-sub-wrapper > .ab-submenu:first-child { 139 border-top: none; 140 } 141 138 142 #wpadminbar .ab-submenu { 139 143 padding: 6px 0; 144 border-top: 1px solid #dfdfdf; 140 145 } 141 146 142 147 #wpadminbar .selected .shortlink-input { … … 247 252 position: relative; 248 253 right: auto; 249 254 margin: 0; 250 border: 0;251 255 252 256 background: #eee; 253 border-top: 1px solid #dfdfdf;254 257 255 258 -moz-box-shadow: none; 256 259 -webkit-box-shadow: none; … … 310 313 min-width: 270px; 311 314 } 312 315 313 #wpadminbar #wp-admin-bar-my-account .user-info-item{316 #wpadminbar #wp-admin-bar-my-account-default > li { 314 317 margin-left: 16px; 315 318 margin-right: 16px; 316 319 } 317 320 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 { 319 322 margin-left: 88px; 320 323 } 321 324 322 #wp adminbar #wp-admin-bar-my-account .user-info-item > a{325 #wp-admin-bar-my-account-default > li > .ab-item { 323 326 padding-left: 8px; 324 327 } 325 328 326 #wpadminbar #wp-admin-bar- my-account .user-info {329 #wpadminbar #wp-admin-bar-user-info { 327 330 margin-top: 6px; 328 331 margin-bottom: 15px; 329 332 height: auto; 330 333 background: none; 331 334 } 332 335 333 #wp-admin-bar- my-account .user-info .avatar {336 #wp-admin-bar-user-info .avatar { 334 337 position: absolute; 335 338 left: -72px; 336 339 top: 4px; 337 340 } 338 341 339 #wpadminbar #wp-admin-bar- my-account .user-info a {342 #wpadminbar #wp-admin-bar-user-info a { 340 343 height: auto; 341 344 } 342 345 343 #wpadminbar #wp-admin-bar- my-account .user-info span {346 #wpadminbar #wp-admin-bar-user-info span { 344 347 background: none; 345 348 padding: 0; 346 349 height: 18px; 347 350 } 348 351 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 { 351 354 text-shadow: none; 352 355 display: block; 353 356 } 354 #wpadminbar #wp-admin-bar- my-account .user-info .display-name {357 #wpadminbar #wp-admin-bar-user-info .display-name { 355 358 color: #333; 356 359 } 357 360 358 #wpadminbar #wp-admin-bar- my-account .user-info .username {361 #wpadminbar #wp-admin-bar-user-info .username { 359 362 color: #999; 360 363 font-size: 11px; 361 364 } -
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(),15 $this->root = (object) array( 16 'id' => 'root', 17 'group' => false, 18 'children' => array(), 19 19 ); 20 20 21 21 if ( is_user_logged_in() ) { … … 68 68 * - title - string - The title of the node. 69 69 * - parent - string - The ID of the parent node. Optional. 70 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.71 * - group - boolean - If the node is a group. Optional. Default false. 72 72 * - meta - array - Meta data including the following keys: html, class, onclick, target, title. 73 73 */ 74 74 public function add_node( $args ) { … … 77 77 $args = array_merge( array( 'parent' => func_get_arg(0) ), func_get_arg(2) ); 78 78 79 79 // Ensure we have a valid title. 80 if ( empty( $args['title'] ) ) 81 return false; 80 if ( empty( $args['id'] ) ) { 81 if ( empty( $args['title'] ) ) 82 return; 82 83 83 if ( empty( $args['id'] ) ) {84 84 _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3' ); 85 // Deprecated: Generate an ID from the title. 85 86 $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) ); 86 87 } 87 88 88 89 $defaults = array( 89 'id' 90 'title' 91 'parent' 92 'href' 93 ' secondary'=> false,94 'meta' 90 'id' => false, 91 'title' => false, 92 'parent' => false, 93 'href' => false, 94 'group' => false, 95 'meta' => array(), 95 96 ); 96 97 97 98 // If the node already exists, keep any data that isn't provided. … … 99 100 $defaults = (array) $this->nodes[ $args['id'] ]; 100 101 101 102 $args = wp_parse_args( $args, $defaults ); 102 $args['children'] = (object) array( 103 'primary' => array(), 104 'secondary' => array(), 105 ); 103 $args['children'] = array(); 106 104 107 105 $this->nodes[ $args['id'] ] = (object) $args; 108 106 } 109 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 ); 120 } 121 110 122 public function remove_node( $id ) { 111 123 unset( $this->nodes[ $id ] ); 112 124 } … … 136 148 $parent = $this->nodes[ $node->parent ]; 137 149 } 138 150 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; 143 172 } 144 173 145 174 // Add browser classes. … … 159 188 ?> 160 189 <div id="wpadminbar" class="<?php echo $class; ?>"> 161 190 <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 } ?> 176 194 </div> 177 195 </div> 178 196 179 197 <?php 180 198 } 181 199 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(); 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 } 186 217 } 187 218 188 $is_parent = (bool) $node->children->primary; 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; 189 249 $has_link = (bool) $node->href; 190 250 191 251 $menuclass = $is_parent ? 'menupop' : ''; … … 222 282 223 283 if ( $is_parent ) : 224 284 ?><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' ); 230 287 } 231 ?></ul><?php232 233 // Render secondary submenu234 if ( ! empty( $node->children->secondary ) ):235 ?><ul class="ab-submenu ab-sub-secondary"><?php236 foreach ( $node->children->secondary as $child_node ) {237 $this->recursive_render( $child_node );238 }239 ?></ul><?php240 endif;241 242 288 ?></div><?php 243 289 endif; 244 290 … … 247 293 248 294 ?> 249 295 </li><?php 296 } 250 297 298 function recursive_render( $node ) { 299 $this->render_item( $node ); 251 300 } 252 301 253 302 function add_menus() { … … 271 320 if ( ! is_admin() ) 272 321 add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 100 ); 273 322 323 add_action( 'admin_bar_menu', 'wp_admin_bar_add_secondary_groups', 200 ); 324 274 325 do_action( 'add_admin_bar_menus' ); 275 326 } 276 327 }