Changeset 42343 for trunk/src/wp-includes/class-wp-admin-bar.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-admin-bar.php
r42131 r42343 24 24 public function __get( $name ) { 25 25 switch ( $name ) { 26 case 'proto' 26 case 'proto': 27 27 return is_ssl() ? 'https://' : 'http://'; 28 28 29 case 'menu' 29 case 'menu': 30 30 _deprecated_argument( 'WP_Admin_Bar', '3.3.0', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the <code>menu</code> property.' ); 31 31 return array(); // Sorry, folks. … … 42 42 $this->user->blogs = get_blogs_of_user( get_current_user_id() ); 43 43 if ( is_multisite() ) { 44 $this->user->active_blog = get_active_blog_for_user( get_current_user_id() );45 $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );44 $this->user->active_blog = get_active_blog_for_user( get_current_user_id() ); 45 $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); 46 46 $this->user->account_domain = $this->user->domain; 47 47 } else { 48 $this->user->active_blog = $this->user->blogs[get_current_blog_id()];49 $this->user->domain = trailingslashit( home_url() );48 $this->user->active_blog = $this->user->blogs[ get_current_blog_id() ]; 49 $this->user->domain = trailingslashit( home_url() ); 50 50 $this->user->account_domain = $this->user->domain; 51 51 } … … 61 61 * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) ); 62 62 */ 63 $admin_bar_args = get_theme_support( 'admin-bar' );63 $admin_bar_args = get_theme_support( 'admin-bar' ); 64 64 $header_callback = $admin_bar_args[0]['callback']; 65 65 } 66 66 67 if ( empty( $header_callback) )67 if ( empty( $header_callback ) ) { 68 68 $header_callback = '_admin_bar_bump_cb'; 69 70 add_action('wp_head', $header_callback); 69 } 70 71 add_action( 'wp_head', $header_callback ); 71 72 72 73 wp_enqueue_script( 'admin-bar' ); … … 115 116 public function add_node( $args ) { 116 117 // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ) 117 if ( func_num_args() >= 3 && is_string( func_get_arg(0) ) ) 118 $args = array_merge( array( 'parent' => func_get_arg(0) ), func_get_arg(2) ); 119 120 if ( is_object( $args ) ) 118 if ( func_num_args() >= 3 && is_string( func_get_arg( 0 ) ) ) { 119 $args = array_merge( array( 'parent' => func_get_arg( 0 ) ), func_get_arg( 2 ) ); 120 } 121 122 if ( is_object( $args ) ) { 121 123 $args = get_object_vars( $args ); 124 } 122 125 123 126 // Ensure we have a valid title. 124 127 if ( empty( $args['id'] ) ) { 125 if ( empty( $args['title'] ) ) 128 if ( empty( $args['title'] ) ) { 126 129 return; 130 } 127 131 128 132 _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3.0' ); … … 141 145 142 146 // If the node already exists, keep any data that isn't provided. 143 if ( $maybe_defaults = $this->get_node( $args['id'] ) ) 147 if ( $maybe_defaults = $this->get_node( $args['id'] ) ) { 144 148 $defaults = get_object_vars( $maybe_defaults ); 149 } 145 150 146 151 // Do the same for 'meta' items. 147 if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) 152 if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) { 148 153 $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] ); 154 } 149 155 150 156 $args = wp_parse_args( $args, $defaults ); … … 152 158 $back_compat_parents = array( 153 159 'my-account-with-avatar' => array( 'my-account', '3.3' ), 154 'my-blogs' => array( 'my-sites', 160 'my-blogs' => array( 'my-sites', '3.3' ), 155 161 ); 156 162 … … 178 184 */ 179 185 final public function get_node( $id ) { 180 if ( $node = $this->_get_node( $id ) ) 186 if ( $node = $this->_get_node( $id ) ) { 181 187 return clone $node; 188 } 182 189 } 183 190 … … 187 194 */ 188 195 final protected function _get_node( $id ) { 189 if ( $this->bound ) 190 return; 191 192 if ( empty( $id ) ) 196 if ( $this->bound ) { 197 return; 198 } 199 200 if ( empty( $id ) ) { 193 201 $id = 'root'; 194 195 if ( isset( $this->nodes[ $id ] ) ) 202 } 203 204 if ( isset( $this->nodes[ $id ] ) ) { 196 205 return $this->nodes[ $id ]; 206 } 197 207 } 198 208 … … 201 211 */ 202 212 final public function get_nodes() { 203 if ( ! $nodes = $this->_get_nodes() ) 204 return; 213 if ( ! $nodes = $this->_get_nodes() ) { 214 return; 215 } 205 216 206 217 foreach ( $nodes as &$node ) { … … 214 225 */ 215 226 final protected function _get_nodes() { 216 if ( $this->bound ) 217 return; 227 if ( $this->bound ) { 228 return; 229 } 218 230 219 231 return $this->nodes; … … 260 272 public function render() { 261 273 $root = $this->_bind(); 262 if ( $root ) 274 if ( $root ) { 263 275 $this->_render( $root ); 276 } 264 277 } 265 278 … … 268 281 */ 269 282 final protected function _bind() { 270 if ( $this->bound ) 271 return; 283 if ( $this->bound ) { 284 return; 285 } 272 286 273 287 // Add the root node. 274 288 // Clear it first, just in case. Don't mess with The Root. 275 289 $this->remove_node( 'root' ); 276 $this->add_node( array( 277 'id' => 'root', 278 'group' => false, 279 ) ); 290 $this->add_node( 291 array( 292 'id' => 'root', 293 'group' => false, 294 ) 295 ); 280 296 281 297 // Normalize nodes: define internal 'children' and 'type' properties. 282 298 foreach ( $this->_get_nodes() as $node ) { 283 299 $node->children = array(); 284 $node->type = ( $node->group ) ? 'group' : 'item';300 $node->type = ( $node->group ) ? 'group' : 'item'; 285 301 unset( $node->group ); 286 302 287 303 // The Root wants your orphans. No lonely items allowed. 288 if ( ! $node->parent ) 304 if ( ! $node->parent ) { 289 305 $node->parent = 'root'; 306 } 290 307 } 291 308 292 309 foreach ( $this->_get_nodes() as $node ) { 293 if ( 'root' == $node->id ) 310 if ( 'root' == $node->id ) { 294 311 continue; 312 } 295 313 296 314 // Fetch the parent node. If it isn't registered, ignore the node. … … 303 321 304 322 if ( $node->type == 'group' ) { 305 if ( empty( $node->meta['class'] ) ) 323 if ( empty( $node->meta['class'] ) ) { 306 324 $node->meta['class'] = $group_class; 307 else325 } else { 308 326 $node->meta['class'] .= ' ' . $group_class; 327 } 309 328 } 310 329 … … 319 338 // Use _set_node because add_node can be overloaded. 320 339 // Make sure to specify default settings for all properties. 321 $this->_set_node( array( 322 'id' => $default_id, 323 'parent' => $parent->id, 324 'type' => 'group', 325 'children' => array(), 326 'meta' => array( 327 'class' => $group_class, 328 ), 329 'title' => false, 330 'href' => false, 331 ) ); 332 $default = $this->_get_node( $default_id ); 340 $this->_set_node( 341 array( 342 'id' => $default_id, 343 'parent' => $parent->id, 344 'type' => 'group', 345 'children' => array(), 346 'meta' => array( 347 'class' => $group_class, 348 ), 349 'title' => false, 350 'href' => false, 351 ) 352 ); 353 $default = $this->_get_node( $default_id ); 333 354 $parent->children[] = $default; 334 355 } 335 356 $parent = $default; 336 357 337 // Groups in groups aren't allowed. Add a special 'container' node.338 // The container will invisibly wrap both groups.358 // Groups in groups aren't allowed. Add a special 'container' node. 359 // The container will invisibly wrap both groups. 339 360 } elseif ( $parent->type == 'group' && $node->type == 'group' ) { 340 361 $container_id = $parent->id . '-container'; … … 345 366 // Use _set_node because add_node can be overloaded. 346 367 // Make sure to specify default settings for all properties. 347 $this->_set_node( array( 348 'id' => $container_id, 349 'type' => 'container', 350 'children' => array( $parent ), 351 'parent' => false, 352 'title' => false, 353 'href' => false, 354 'meta' => array(), 355 ) ); 368 $this->_set_node( 369 array( 370 'id' => $container_id, 371 'type' => 'container', 372 'children' => array( $parent ), 373 'parent' => false, 374 'title' => false, 375 'href' => false, 376 'meta' => array(), 377 ) 378 ); 356 379 357 380 $container = $this->_get_node( $container_id ); … … 364 387 365 388 $index = array_search( $parent, $grandparent->children, true ); 366 if ( $index === false ) 389 if ( $index === false ) { 367 390 $grandparent->children[] = $container; 368 else391 } else { 369 392 array_splice( $grandparent->children, $index, 1, array( $container ) ); 393 } 370 394 } 371 395 … … 383 407 } 384 408 385 $root = $this->_get_node( 'root' );409 $root = $this->_get_node( 'root' ); 386 410 $this->bound = true; 387 411 return $root; … … 389 413 390 414 /** 391 *392 415 * @global bool $is_IE 393 416 * @param object $root … … 400 423 $class = 'nojq nojs'; 401 424 if ( $is_IE ) { 402 if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) 425 if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) { 403 426 $class .= ' ie7'; 404 elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) )427 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) { 405 428 $class .= ' ie8'; 406 elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) )429 } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) { 407 430 $class .= ' ie9'; 431 } 408 432 } elseif ( wp_is_mobile() ) { 409 433 $class .= ' mobile'; … … 416 440 <?php } ?> 417 441 <div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e( 'Toolbar' ); ?>" tabindex="0"> 418 <?php foreach ( $root->children as $group ) { 442 <?php 443 foreach ( $root->children as $group ) { 419 444 $this->_render_group( $group ); 420 } ?> 445 } 446 ?> 421 447 </div> 422 448 <?php if ( is_user_logged_in() ) : ?> 423 <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e( 'Log Out'); ?></a>449 <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e( 'Log Out' ); ?></a> 424 450 <?php endif; ?> 425 451 </div> … … 432 458 */ 433 459 final protected function _render_container( $node ) { 434 if ( $node->type != 'container' || empty( $node->children ) ) 435 return; 460 if ( $node->type != 'container' || empty( $node->children ) ) { 461 return; 462 } 436 463 437 464 echo '<div id="' . esc_attr( 'wp-admin-bar-' . $node->id ) . '" class="ab-group-container">'; … … 450 477 return; 451 478 } 452 if ( $node->type != 'group' || empty( $node->children ) ) 453 return; 454 455 if ( ! empty( $node->meta['class'] ) ) 479 if ( $node->type != 'group' || empty( $node->children ) ) { 480 return; 481 } 482 483 if ( ! empty( $node->meta['class'] ) ) { 456 484 $class = ' class="' . esc_attr( trim( $node->meta['class'] ) ) . '"'; 457 else485 } else { 458 486 $class = ''; 487 } 459 488 460 489 echo "<ul id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>"; … … 469 498 */ 470 499 final protected function _render_item( $node ) { 471 if ( $node->type != 'item' ) 472 return; 500 if ( $node->type != 'item' ) { 501 return; 502 } 473 503 474 504 $is_parent = ! empty( $node->children ); … … 476 506 477 507 // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y. 478 $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';508 $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : ''; 479 509 $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : ''; 480 510 … … 482 512 483 513 if ( $is_parent ) { 484 $menuclass = 'menupop ';514 $menuclass = 'menupop '; 485 515 $aria_attributes .= ' aria-haspopup="true"'; 486 516 } 487 517 488 if ( ! empty( $node->meta['class'] ) ) 518 if ( ! empty( $node->meta['class'] ) ) { 489 519 $menuclass .= $node->meta['class']; 490 491 if ( $menuclass ) 520 } 521 522 if ( $menuclass ) { 492 523 $menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"'; 524 } 493 525 494 526 echo "<li id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>";
Note: See TracChangeset
for help on using the changeset viewer.