Changeset 42343 for trunk/src/wp-includes/admin-bar.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/admin-bar.php (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/admin-bar.php
r41796 r42343 24 24 global $wp_admin_bar; 25 25 26 if ( ! is_admin_bar_showing() ) 26 if ( ! is_admin_bar_showing() ) { 27 27 return false; 28 } 28 29 29 30 /* Load the admin bar class code ready for instantiation */ … … 40 41 */ 41 42 $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); 42 if ( class_exists( $admin_bar_class ) ) 43 if ( class_exists( $admin_bar_class ) ) { 43 44 $wp_admin_bar = new $admin_bar_class; 44 else45 } else { 45 46 return false; 47 } 46 48 47 49 $wp_admin_bar->initialize(); … … 69 71 global $wp_admin_bar; 70 72 71 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) 72 return; 73 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { 74 return; 75 } 73 76 74 77 /** … … 133 136 if ( $about_url ) { 134 137 // Add "About WordPress" link 135 $wp_admin_bar->add_menu( array( 136 'parent' => 'wp-logo', 137 'id' => 'about', 138 'title' => __('About WordPress'), 139 'href' => $about_url, 140 ) ); 138 $wp_admin_bar->add_menu( 139 array( 140 'parent' => 'wp-logo', 141 'id' => 'about', 142 'title' => __( 'About WordPress' ), 143 'href' => $about_url, 144 ) 145 ); 141 146 } 142 147 143 148 // Add WordPress.org link 144 $wp_admin_bar->add_menu( array( 145 'parent' => 'wp-logo-external', 146 'id' => 'wporg', 147 'title' => __('WordPress.org'), 148 'href' => __('https://wordpress.org/'), 149 ) ); 149 $wp_admin_bar->add_menu( 150 array( 151 'parent' => 'wp-logo-external', 152 'id' => 'wporg', 153 'title' => __( 'WordPress.org' ), 154 'href' => __( 'https://wordpress.org/' ), 155 ) 156 ); 150 157 151 158 // Add codex link 152 $wp_admin_bar->add_menu( array( 153 'parent' => 'wp-logo-external', 154 'id' => 'documentation', 155 'title' => __('Documentation'), 156 'href' => __('https://codex.wordpress.org/'), 157 ) ); 159 $wp_admin_bar->add_menu( 160 array( 161 'parent' => 'wp-logo-external', 162 'id' => 'documentation', 163 'title' => __( 'Documentation' ), 164 'href' => __( 'https://codex.wordpress.org/' ), 165 ) 166 ); 158 167 159 168 // Add forums link 160 $wp_admin_bar->add_menu( array( 161 'parent' => 'wp-logo-external', 162 'id' => 'support-forums', 163 'title' => __('Support Forums'), 164 'href' => __('https://wordpress.org/support/'), 165 ) ); 169 $wp_admin_bar->add_menu( 170 array( 171 'parent' => 'wp-logo-external', 172 'id' => 'support-forums', 173 'title' => __( 'Support Forums' ), 174 'href' => __( 'https://wordpress.org/support/' ), 175 ) 176 ); 166 177 167 178 // Add feedback link 168 $wp_admin_bar->add_menu( array( 169 'parent' => 'wp-logo-external', 170 'id' => 'feedback', 171 'title' => __('Feedback'), 172 'href' => __('https://wordpress.org/support/forum/requests-and-feedback'), 173 ) ); 179 $wp_admin_bar->add_menu( 180 array( 181 'parent' => 'wp-logo-external', 182 'id' => 'feedback', 183 'title' => __( 'Feedback' ), 184 'href' => __( 'https://wordpress.org/support/forum/requests-and-feedback' ), 185 ) 186 ); 174 187 } 175 188 … … 183 196 function wp_admin_bar_sidebar_toggle( $wp_admin_bar ) { 184 197 if ( is_admin() ) { 185 $wp_admin_bar->add_menu( array( 186 'id' => 'menu-toggle', 187 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>', 188 'href' => '#', 189 ) ); 198 $wp_admin_bar->add_menu( 199 array( 200 'id' => 'menu-toggle', 201 'title' => '<span class="ab-icon"></span><span class="screen-reader-text">' . __( 'Menu' ) . '</span>', 202 'href' => '#', 203 ) 204 ); 190 205 } 191 206 } … … 202 217 $current_user = wp_get_current_user(); 203 218 204 if ( ! $user_id ) 205 return; 219 if ( ! $user_id ) { 220 return; 221 } 206 222 207 223 if ( current_user_can( 'read' ) ) { … … 215 231 $avatar = get_avatar( $user_id, 26 ); 216 232 /* translators: %s: current user's display name */ 217 $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); 218 $class = empty( $avatar ) ? '' : 'with-avatar'; 219 220 $wp_admin_bar->add_menu( array( 221 'id' => 'my-account', 222 'parent' => 'top-secondary', 223 'title' => $howdy . $avatar, 224 'href' => $profile_url, 225 'meta' => array( 226 'class' => $class, 227 ), 228 ) ); 233 $howdy = sprintf( __( 'Howdy, %s' ), '<span class="display-name">' . $current_user->display_name . '</span>' ); 234 $class = empty( $avatar ) ? '' : 'with-avatar'; 235 236 $wp_admin_bar->add_menu( 237 array( 238 'id' => 'my-account', 239 'parent' => 'top-secondary', 240 'title' => $howdy . $avatar, 241 'href' => $profile_url, 242 'meta' => array( 243 'class' => $class, 244 ), 245 ) 246 ); 229 247 } 230 248 … … 240 258 $current_user = wp_get_current_user(); 241 259 242 if ( ! $user_id ) 243 return; 260 if ( ! $user_id ) { 261 return; 262 } 244 263 245 264 if ( current_user_can( 'read' ) ) { … … 251 270 } 252 271 253 $wp_admin_bar->add_group( array( 254 'parent' => 'my-account', 255 'id' => 'user-actions', 256 ) ); 272 $wp_admin_bar->add_group( 273 array( 274 'parent' => 'my-account', 275 'id' => 'user-actions', 276 ) 277 ); 257 278 258 279 $user_info = get_avatar( $user_id, 64 ); 259 280 $user_info .= "<span class='display-name'>{$current_user->display_name}</span>"; 260 281 261 if ( $current_user->display_name !== $current_user->user_login ) 282 if ( $current_user->display_name !== $current_user->user_login ) { 262 283 $user_info .= "<span class='username'>{$current_user->user_login}</span>"; 263 264 $wp_admin_bar->add_menu( array( 265 'parent' => 'user-actions', 266 'id' => 'user-info', 267 'title' => $user_info, 268 'href' => $profile_url, 269 'meta' => array( 270 'tabindex' => -1, 271 ), 272 ) ); 284 } 285 286 $wp_admin_bar->add_menu( 287 array( 288 'parent' => 'user-actions', 289 'id' => 'user-info', 290 'title' => $user_info, 291 'href' => $profile_url, 292 'meta' => array( 293 'tabindex' => -1, 294 ), 295 ) 296 ); 273 297 274 298 if ( false !== $profile_url ) { 275 $wp_admin_bar->add_menu( array( 299 $wp_admin_bar->add_menu( 300 array( 301 'parent' => 'user-actions', 302 'id' => 'edit-profile', 303 'title' => __( 'Edit My Profile' ), 304 'href' => $profile_url, 305 ) 306 ); 307 } 308 309 $wp_admin_bar->add_menu( 310 array( 276 311 'parent' => 'user-actions', 277 'id' => 'edit-profile', 278 'title' => __( 'Edit My Profile' ), 279 'href' => $profile_url, 280 ) ); 281 } 282 283 $wp_admin_bar->add_menu( array( 284 'parent' => 'user-actions', 285 'id' => 'logout', 286 'title' => __( 'Log Out' ), 287 'href' => wp_logout_url(), 288 ) ); 312 'id' => 'logout', 313 'title' => __( 'Log Out' ), 314 'href' => wp_logout_url(), 315 ) 316 ); 289 317 } 290 318 … … 298 326 function wp_admin_bar_site_menu( $wp_admin_bar ) { 299 327 // Don't show for logged out users. 300 if ( ! is_user_logged_in() ) 301 return; 328 if ( ! is_user_logged_in() ) { 329 return; 330 } 302 331 303 332 // Show only when the user is a member of this site, or they're a super admin. … … 306 335 } 307 336 308 $blogname = get_bloginfo( 'name');337 $blogname = get_bloginfo( 'name' ); 309 338 310 339 if ( ! $blogname ) { … … 322 351 $title = wp_html_excerpt( $blogname, 40, '…' ); 323 352 324 $wp_admin_bar->add_menu( array( 325 'id' => 'site-name', 326 'title' => $title, 327 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), 328 ) ); 353 $wp_admin_bar->add_menu( 354 array( 355 'id' => 'site-name', 356 'title' => $title, 357 'href' => ( is_admin() || ! current_user_can( 'read' ) ) ? home_url( '/' ) : admin_url(), 358 ) 359 ); 329 360 330 361 // Create submenu items. … … 332 363 if ( is_admin() ) { 333 364 // Add an option to visit the site. 334 $wp_admin_bar->add_menu( array( 335 'parent' => 'site-name', 336 'id' => 'view-site', 337 'title' => __( 'Visit Site' ), 338 'href' => home_url( '/' ), 339 ) ); 365 $wp_admin_bar->add_menu( 366 array( 367 'parent' => 'site-name', 368 'id' => 'view-site', 369 'title' => __( 'Visit Site' ), 370 'href' => home_url( '/' ), 371 ) 372 ); 340 373 341 374 if ( is_blog_admin() && is_multisite() && current_user_can( 'manage_sites' ) ) { 342 $wp_admin_bar->add_menu( array( 375 $wp_admin_bar->add_menu( 376 array( 377 'parent' => 'site-name', 378 'id' => 'edit-site', 379 'title' => __( 'Edit Site' ), 380 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), 381 ) 382 ); 383 } 384 } elseif ( current_user_can( 'read' ) ) { 385 // We're on the front end, link to the Dashboard. 386 $wp_admin_bar->add_menu( 387 array( 343 388 'parent' => 'site-name', 344 'id' => 'edit-site', 345 'title' => __( 'Edit Site' ), 346 'href' => network_admin_url( 'site-info.php?id=' . get_current_blog_id() ), 347 ) ); 348 } 349 350 } else if ( current_user_can( 'read' ) ) { 351 // We're on the front end, link to the Dashboard. 352 $wp_admin_bar->add_menu( array( 353 'parent' => 'site-name', 354 'id' => 'dashboard', 355 'title' => __( 'Dashboard' ), 356 'href' => admin_url(), 357 ) ); 389 'id' => 'dashboard', 390 'title' => __( 'Dashboard' ), 391 'href' => admin_url(), 392 ) 393 ); 358 394 359 395 // Add the appearance submenu items. … … 393 429 } 394 430 395 $wp_admin_bar->add_menu( array( 396 'id' => 'customize', 397 'title' => __( 'Customize' ), 398 'href' => $customize_url, 399 'meta' => array( 400 'class' => 'hide-if-no-customize', 401 ), 402 ) ); 431 $wp_admin_bar->add_menu( 432 array( 433 'id' => 'customize', 434 'title' => __( 'Customize' ), 435 'href' => $customize_url, 436 'meta' => array( 437 'class' => 'hide-if-no-customize', 438 ), 439 ) 440 ); 403 441 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); 404 442 } … … 413 451 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { 414 452 // Don't show for logged out users or single site mode. 415 if ( ! is_user_logged_in() || ! is_multisite() ) 416 return; 453 if ( ! is_user_logged_in() || ! is_multisite() ) { 454 return; 455 } 417 456 418 457 // Show only when the user has at least one site, or they're a super admin. … … 427 466 } 428 467 429 $wp_admin_bar->add_menu( array( 430 'id' => 'my-sites', 431 'title' => __( 'My Sites' ), 432 'href' => $my_sites_url, 433 ) ); 468 $wp_admin_bar->add_menu( 469 array( 470 'id' => 'my-sites', 471 'title' => __( 'My Sites' ), 472 'href' => $my_sites_url, 473 ) 474 ); 434 475 435 476 if ( current_user_can( 'manage_network' ) ) { 436 $wp_admin_bar->add_group( array( 477 $wp_admin_bar->add_group( 478 array( 479 'parent' => 'my-sites', 480 'id' => 'my-sites-super-admin', 481 ) 482 ); 483 484 $wp_admin_bar->add_menu( 485 array( 486 'parent' => 'my-sites-super-admin', 487 'id' => 'network-admin', 488 'title' => __( 'Network Admin' ), 489 'href' => network_admin_url(), 490 ) 491 ); 492 493 $wp_admin_bar->add_menu( 494 array( 495 'parent' => 'network-admin', 496 'id' => 'network-admin-d', 497 'title' => __( 'Dashboard' ), 498 'href' => network_admin_url(), 499 ) 500 ); 501 502 if ( current_user_can( 'manage_sites' ) ) { 503 $wp_admin_bar->add_menu( 504 array( 505 'parent' => 'network-admin', 506 'id' => 'network-admin-s', 507 'title' => __( 'Sites' ), 508 'href' => network_admin_url( 'sites.php' ), 509 ) 510 ); 511 } 512 513 if ( current_user_can( 'manage_network_users' ) ) { 514 $wp_admin_bar->add_menu( 515 array( 516 'parent' => 'network-admin', 517 'id' => 'network-admin-u', 518 'title' => __( 'Users' ), 519 'href' => network_admin_url( 'users.php' ), 520 ) 521 ); 522 } 523 524 if ( current_user_can( 'manage_network_themes' ) ) { 525 $wp_admin_bar->add_menu( 526 array( 527 'parent' => 'network-admin', 528 'id' => 'network-admin-t', 529 'title' => __( 'Themes' ), 530 'href' => network_admin_url( 'themes.php' ), 531 ) 532 ); 533 } 534 535 if ( current_user_can( 'manage_network_plugins' ) ) { 536 $wp_admin_bar->add_menu( 537 array( 538 'parent' => 'network-admin', 539 'id' => 'network-admin-p', 540 'title' => __( 'Plugins' ), 541 'href' => network_admin_url( 'plugins.php' ), 542 ) 543 ); 544 } 545 546 if ( current_user_can( 'manage_network_options' ) ) { 547 $wp_admin_bar->add_menu( 548 array( 549 'parent' => 'network-admin', 550 'id' => 'network-admin-o', 551 'title' => __( 'Settings' ), 552 'href' => network_admin_url( 'settings.php' ), 553 ) 554 ); 555 } 556 } 557 558 // Add site links 559 $wp_admin_bar->add_group( 560 array( 437 561 'parent' => 'my-sites', 438 'id' => 'my-sites-super-admin', 439 ) ); 440 441 $wp_admin_bar->add_menu( array( 442 'parent' => 'my-sites-super-admin', 443 'id' => 'network-admin', 444 'title' => __('Network Admin'), 445 'href' => network_admin_url(), 446 ) ); 447 448 $wp_admin_bar->add_menu( array( 449 'parent' => 'network-admin', 450 'id' => 'network-admin-d', 451 'title' => __( 'Dashboard' ), 452 'href' => network_admin_url(), 453 ) ); 454 455 if ( current_user_can( 'manage_sites' ) ) { 456 $wp_admin_bar->add_menu( array( 457 'parent' => 'network-admin', 458 'id' => 'network-admin-s', 459 'title' => __( 'Sites' ), 460 'href' => network_admin_url( 'sites.php' ), 461 ) ); 462 } 463 464 if ( current_user_can( 'manage_network_users' ) ) { 465 $wp_admin_bar->add_menu( array( 466 'parent' => 'network-admin', 467 'id' => 'network-admin-u', 468 'title' => __( 'Users' ), 469 'href' => network_admin_url( 'users.php' ), 470 ) ); 471 } 472 473 if ( current_user_can( 'manage_network_themes' ) ) { 474 $wp_admin_bar->add_menu( array( 475 'parent' => 'network-admin', 476 'id' => 'network-admin-t', 477 'title' => __( 'Themes' ), 478 'href' => network_admin_url( 'themes.php' ), 479 ) ); 480 } 481 482 if ( current_user_can( 'manage_network_plugins' ) ) { 483 $wp_admin_bar->add_menu( array( 484 'parent' => 'network-admin', 485 'id' => 'network-admin-p', 486 'title' => __( 'Plugins' ), 487 'href' => network_admin_url( 'plugins.php' ), 488 ) ); 489 } 490 491 if ( current_user_can( 'manage_network_options' ) ) { 492 $wp_admin_bar->add_menu( array( 493 'parent' => 'network-admin', 494 'id' => 'network-admin-o', 495 'title' => __( 'Settings' ), 496 'href' => network_admin_url( 'settings.php' ), 497 ) ); 498 } 499 } 500 501 // Add site links 502 $wp_admin_bar->add_group( array( 503 'parent' => 'my-sites', 504 'id' => 'my-sites-list', 505 'meta' => array( 506 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', 507 ), 508 ) ); 562 'id' => 'my-sites-list', 563 'meta' => array( 564 'class' => current_user_can( 'manage_network' ) ? 'ab-sub-secondary' : '', 565 ), 566 ) 567 ); 509 568 510 569 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { … … 519 578 } 520 579 521 $menu_id = 'blog-' . $blog->userblog_id;580 $menu_id = 'blog-' . $blog->userblog_id; 522 581 523 582 if ( current_user_can( 'read' ) ) { 524 $wp_admin_bar->add_menu( array( 525 'parent' => 'my-sites-list', 526 'id' => $menu_id, 527 'title' => $blavatar . $blogname, 528 'href' => admin_url(), 529 ) ); 530 531 $wp_admin_bar->add_menu( array( 583 $wp_admin_bar->add_menu( 584 array( 585 'parent' => 'my-sites-list', 586 'id' => $menu_id, 587 'title' => $blavatar . $blogname, 588 'href' => admin_url(), 589 ) 590 ); 591 592 $wp_admin_bar->add_menu( 593 array( 594 'parent' => $menu_id, 595 'id' => $menu_id . '-d', 596 'title' => __( 'Dashboard' ), 597 'href' => admin_url(), 598 ) 599 ); 600 } else { 601 $wp_admin_bar->add_menu( 602 array( 603 'parent' => 'my-sites-list', 604 'id' => $menu_id, 605 'title' => $blavatar . $blogname, 606 'href' => home_url(), 607 ) 608 ); 609 } 610 611 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { 612 $wp_admin_bar->add_menu( 613 array( 614 'parent' => $menu_id, 615 'id' => $menu_id . '-n', 616 'title' => __( 'New Post' ), 617 'href' => admin_url( 'post-new.php' ), 618 ) 619 ); 620 } 621 622 if ( current_user_can( 'edit_posts' ) ) { 623 $wp_admin_bar->add_menu( 624 array( 625 'parent' => $menu_id, 626 'id' => $menu_id . '-c', 627 'title' => __( 'Manage Comments' ), 628 'href' => admin_url( 'edit-comments.php' ), 629 ) 630 ); 631 } 632 633 $wp_admin_bar->add_menu( 634 array( 532 635 'parent' => $menu_id, 533 'id' => $menu_id . '-d', 534 'title' => __( 'Dashboard' ), 535 'href' => admin_url(), 536 ) ); 537 } else { 538 $wp_admin_bar->add_menu( array( 539 'parent' => 'my-sites-list', 540 'id' => $menu_id, 541 'title' => $blavatar . $blogname, 542 'href' => home_url(), 543 ) ); 544 } 545 546 if ( current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { 547 $wp_admin_bar->add_menu( array( 548 'parent' => $menu_id, 549 'id' => $menu_id . '-n', 550 'title' => __( 'New Post' ), 551 'href' => admin_url( 'post-new.php' ), 552 ) ); 553 } 554 555 if ( current_user_can( 'edit_posts' ) ) { 556 $wp_admin_bar->add_menu( array( 557 'parent' => $menu_id, 558 'id' => $menu_id . '-c', 559 'title' => __( 'Manage Comments' ), 560 'href' => admin_url( 'edit-comments.php' ), 561 ) ); 562 } 563 564 $wp_admin_bar->add_menu( array( 565 'parent' => $menu_id, 566 'id' => $menu_id . '-v', 567 'title' => __( 'Visit Site' ), 568 'href' => home_url( '/' ), 569 ) ); 636 'id' => $menu_id . '-v', 637 'title' => __( 'Visit Site' ), 638 'href' => home_url( '/' ), 639 ) 640 ); 570 641 571 642 restore_current_blog(); … … 582 653 function wp_admin_bar_shortlink_menu( $wp_admin_bar ) { 583 654 $short = wp_get_shortlink( 0, 'query' ); 584 $id = 'get-shortlink'; 585 586 if ( empty( $short ) ) 587 return; 655 $id = 'get-shortlink'; 656 657 if ( empty( $short ) ) { 658 return; 659 } 588 660 589 661 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; 590 662 591 $wp_admin_bar->add_menu( array( 592 'id' => $id, 593 'title' => __( 'Shortlink' ), 594 'href' => $short, 595 'meta' => array( 'html' => $html ), 596 ) ); 663 $wp_admin_bar->add_menu( 664 array( 665 'id' => $id, 666 'title' => __( 'Shortlink' ), 667 'href' => $short, 668 'meta' => array( 'html' => $html ), 669 ) 670 ); 597 671 } 598 672 … … 612 686 if ( is_admin() ) { 613 687 $current_screen = get_current_screen(); 614 $post = get_post();688 $post = get_post(); 615 689 616 690 if ( 'post' == $current_screen->base … … 619 693 && current_user_can( 'read_post', $post->ID ) 620 694 && ( $post_type_object->public ) 621 && ( $post_type_object->show_in_admin_bar ) ) 622 { 695 && ( $post_type_object->show_in_admin_bar ) ) { 623 696 if ( 'draft' == $post->post_status ) { 624 697 $preview_link = get_preview_post_link( $post ); 625 $wp_admin_bar->add_menu( array( 626 'id' => 'preview', 627 'title' => $post_type_object->labels->view_item, 628 'href' => esc_url( $preview_link ), 629 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), 630 ) ); 698 $wp_admin_bar->add_menu( 699 array( 700 'id' => 'preview', 701 'title' => $post_type_object->labels->view_item, 702 'href' => esc_url( $preview_link ), 703 'meta' => array( 'target' => 'wp-preview-' . $post->ID ), 704 ) 705 ); 631 706 } else { 632 $wp_admin_bar->add_menu( array( 633 'id' => 'view', 634 'title' => $post_type_object->labels->view_item, 635 'href' => get_permalink( $post->ID ) 636 ) ); 707 $wp_admin_bar->add_menu( 708 array( 709 'id' => 'view', 710 'title' => $post_type_object->labels->view_item, 711 'href' => get_permalink( $post->ID ), 712 ) 713 ); 637 714 } 638 715 } elseif ( 'edit' == $current_screen->base 639 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) 640 && ( $post_type_object->public ) 641 && ( $post_type_object->show_in_admin_bar ) 642 && ( get_post_type_archive_link( $post_type_object->name ) ) 643 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) 644 { 645 $wp_admin_bar->add_node( array( 646 'id' => 'archive', 647 'title' => $post_type_object->labels->view_items, 648 'href' => get_post_type_archive_link( $current_screen->post_type ) 649 ) ); 716 && ( $post_type_object = get_post_type_object( $current_screen->post_type ) ) 717 && ( $post_type_object->public ) 718 && ( $post_type_object->show_in_admin_bar ) 719 && ( get_post_type_archive_link( $post_type_object->name ) ) 720 && ! ( 'post' === $post_type_object->name && 'posts' === get_option( 'show_on_front' ) ) ) { 721 $wp_admin_bar->add_node( 722 array( 723 'id' => 'archive', 724 'title' => $post_type_object->labels->view_items, 725 'href' => get_post_type_archive_link( $current_screen->post_type ), 726 ) 727 ); 650 728 } elseif ( 'term' == $current_screen->base 651 729 && isset( $tag ) && is_object( $tag ) && ! is_wp_error( $tag ) 652 730 && ( $tax = get_taxonomy( $tag->taxonomy ) ) 653 && $tax->public ) 654 { 655 $wp_admin_bar->add_menu( array( 656 'id' => 'view', 657 'title' => $tax->labels->view_item, 658 'href' => get_term_link( $tag ) 659 ) ); 731 && $tax->public ) { 732 $wp_admin_bar->add_menu( 733 array( 734 'id' => 'view', 735 'title' => $tax->labels->view_item, 736 'href' => get_term_link( $tag ), 737 ) 738 ); 660 739 } elseif ( 'user-edit' == $current_screen->base 661 740 && isset( $user_id ) 662 741 && ( $user_object = get_userdata( $user_id ) ) 663 742 && $user_object->exists() 664 && $view_link = get_author_posts_url( $user_object->ID ) ) 665 { 666 $wp_admin_bar->add_menu( array( 667 'id' => 'view', 668 'title' => __( 'View User' ), 669 'href' => $view_link, 670 ) ); 743 && $view_link = get_author_posts_url( $user_object->ID ) ) { 744 $wp_admin_bar->add_menu( 745 array( 746 'id' => 'view', 747 'title' => __( 'View User' ), 748 'href' => $view_link, 749 ) 750 ); 671 751 } 672 752 } else { 673 753 $current_object = $wp_the_query->get_queried_object(); 674 754 675 if ( empty( $current_object ) ) 755 if ( empty( $current_object ) ) { 676 756 return; 757 } 677 758 678 759 if ( ! empty( $current_object->post_type ) … … 680 761 && current_user_can( 'edit_post', $current_object->ID ) 681 762 && $post_type_object->show_in_admin_bar 682 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) 683 { 684 $wp_admin_bar->add_menu( array( 685 'id' => 'edit', 686 'title' => $post_type_object->labels->edit_item, 687 'href' => $edit_post_link 688 ) ); 763 && $edit_post_link = get_edit_post_link( $current_object->ID ) ) { 764 $wp_admin_bar->add_menu( 765 array( 766 'id' => 'edit', 767 'title' => $post_type_object->labels->edit_item, 768 'href' => $edit_post_link, 769 ) 770 ); 689 771 } elseif ( ! empty( $current_object->taxonomy ) 690 772 && ( $tax = get_taxonomy( $current_object->taxonomy ) ) 691 773 && current_user_can( 'edit_term', $current_object->term_id ) 692 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) 693 { 694 $wp_admin_bar->add_menu( array( 695 'id' => 'edit', 696 'title' => $tax->labels->edit_item, 697 'href' => $edit_term_link 698 ) ); 774 && $edit_term_link = get_edit_term_link( $current_object->term_id, $current_object->taxonomy ) ) { 775 $wp_admin_bar->add_menu( 776 array( 777 'id' => 'edit', 778 'title' => $tax->labels->edit_item, 779 'href' => $edit_term_link, 780 ) 781 ); 699 782 } elseif ( is_a( $current_object, 'WP_User' ) 700 783 && current_user_can( 'edit_user', $current_object->ID ) 701 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) 702 { 703 $wp_admin_bar->add_menu( array( 704 'id' => 'edit', 705 'title' => __( 'Edit User' ), 706 'href' => $edit_user_link, 707 ) ); 784 && $edit_user_link = get_edit_user_link( $current_object->ID ) ) { 785 $wp_admin_bar->add_menu( 786 array( 787 'id' => 'edit', 788 'title' => __( 'Edit User' ), 789 'href' => $edit_user_link, 790 ) 791 ); 708 792 } 709 793 } … … 722 806 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); 723 807 724 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) 725 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); 726 727 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) 728 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); 729 730 if ( current_user_can( 'manage_links' ) ) 731 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); 732 733 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) 734 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); 808 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { 809 $actions['post-new.php'] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); 810 } 811 812 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { 813 $actions['media-new.php'] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); 814 } 815 816 if ( current_user_can( 'manage_links' ) ) { 817 $actions['link-add.php'] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); 818 } 819 820 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) { 821 $actions['post-new.php?post_type=page'] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); 822 } 735 823 736 824 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); … … 738 826 // Add any additional custom post types. 739 827 foreach ( $cpts as $cpt ) { 740 if ( ! current_user_can( $cpt->cap->create_posts ) ) 828 if ( ! current_user_can( $cpt->cap->create_posts ) ) { 741 829 continue; 742 743 $key = 'post-new.php?post_type=' . $cpt->name; 830 } 831 832 $key = 'post-new.php?post_type=' . $cpt->name; 744 833 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); 745 834 } 746 835 // Avoid clash with parent node and a 'content' post type. 747 if ( isset( $actions['post-new.php?post_type=content'] ) ) 836 if ( isset( $actions['post-new.php?post_type=content'] ) ) { 748 837 $actions['post-new.php?post_type=content'][1] = 'add-new-content'; 838 } 749 839 750 840 if ( current_user_can( 'create_users' ) || ( is_multisite() && current_user_can( 'promote_users' ) ) ) { 751 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); 752 } 753 754 if ( ! $actions ) 755 return; 841 $actions['user-new.php'] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); 842 } 843 844 if ( ! $actions ) { 845 return; 846 } 756 847 757 848 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; 758 849 759 $wp_admin_bar->add_menu( array( 760 'id' => 'new-content', 761 'title' => $title, 762 'href' => admin_url( current( array_keys( $actions ) ) ), 763 ) ); 850 $wp_admin_bar->add_menu( 851 array( 852 'id' => 'new-content', 853 'title' => $title, 854 'href' => admin_url( current( array_keys( $actions ) ) ), 855 ) 856 ); 764 857 765 858 foreach ( $actions as $link => $action ) { 766 859 list( $title, $id ) = $action; 767 860 768 $wp_admin_bar->add_menu( array( 769 'parent' => 'new-content', 770 'id' => $id, 771 'title' => $title, 772 'href' => admin_url( $link ) 773 ) ); 861 $wp_admin_bar->add_menu( 862 array( 863 'parent' => 'new-content', 864 'id' => $id, 865 'title' => $title, 866 'href' => admin_url( $link ), 867 ) 868 ); 774 869 } 775 870 } … … 783 878 */ 784 879 function wp_admin_bar_comments_menu( $wp_admin_bar ) { 785 if ( !current_user_can('edit_posts') ) 786 return; 787 788 $awaiting_mod = wp_count_comments(); 789 $awaiting_mod = $awaiting_mod->moderated; 880 if ( ! current_user_can( 'edit_posts' ) ) { 881 return; 882 } 883 884 $awaiting_mod = wp_count_comments(); 885 $awaiting_mod = $awaiting_mod->moderated; 790 886 $awaiting_text = sprintf( _n( '%s comment awaiting moderation', '%s comments awaiting moderation', $awaiting_mod ), number_format_i18n( $awaiting_mod ) ); 791 887 792 $icon = '<span class="ab-icon"></span>';793 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>';888 $icon = '<span class="ab-icon"></span>'; 889 $title = '<span class="ab-label awaiting-mod pending-count count-' . $awaiting_mod . '" aria-hidden="true">' . number_format_i18n( $awaiting_mod ) . '</span>'; 794 890 $title .= '<span class="screen-reader-text">' . $awaiting_text . '</span>'; 795 891 796 $wp_admin_bar->add_menu( array( 797 'id' => 'comments', 798 'title' => $icon . $title, 799 'href' => admin_url('edit-comments.php'), 800 ) ); 892 $wp_admin_bar->add_menu( 893 array( 894 'id' => 'comments', 895 'title' => $icon . $title, 896 'href' => admin_url( 'edit-comments.php' ), 897 ) 898 ); 801 899 } 802 900 … … 809 907 */ 810 908 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { 811 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); 909 $wp_admin_bar->add_group( 910 array( 911 'parent' => 'site-name', 912 'id' => 'appearance', 913 ) 914 ); 812 915 813 916 if ( current_user_can( 'switch_themes' ) ) { 814 $wp_admin_bar->add_menu( array( 815 'parent' => 'appearance', 816 'id' => 'themes', 817 'title' => __( 'Themes' ), 818 'href' => admin_url( 'themes.php' ), 819 ) ); 917 $wp_admin_bar->add_menu( 918 array( 919 'parent' => 'appearance', 920 'id' => 'themes', 921 'title' => __( 'Themes' ), 922 'href' => admin_url( 'themes.php' ), 923 ) 924 ); 820 925 } 821 926 … … 824 929 } 825 930 826 if ( current_theme_supports( 'widgets' ) ) { 827 $wp_admin_bar->add_menu( array( 828 'parent' => 'appearance', 829 'id' => 'widgets', 830 'title' => __( 'Widgets' ), 831 'href' => admin_url( 'widgets.php' ), 832 ) ); 833 } 834 835 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) 836 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); 931 if ( current_theme_supports( 'widgets' ) ) { 932 $wp_admin_bar->add_menu( 933 array( 934 'parent' => 'appearance', 935 'id' => 'widgets', 936 'title' => __( 'Widgets' ), 937 'href' => admin_url( 'widgets.php' ), 938 ) 939 ); 940 } 941 942 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { 943 $wp_admin_bar->add_menu( 944 array( 945 'parent' => 'appearance', 946 'id' => 'menus', 947 'title' => __( 'Menus' ), 948 'href' => admin_url( 'nav-menus.php' ), 949 ) 950 ); 951 } 837 952 838 953 if ( current_theme_supports( 'custom-background' ) ) { 839 $wp_admin_bar->add_menu( array( 840 'parent' => 'appearance', 841 'id' => 'background', 842 'title' => __( 'Background' ), 843 'href' => admin_url( 'themes.php?page=custom-background' ), 844 'meta' => array( 845 'class' => 'hide-if-customize', 954 $wp_admin_bar->add_menu( 955 array( 956 'parent' => 'appearance', 957 'id' => 'background', 958 'title' => __( 'Background' ), 959 'href' => admin_url( 'themes.php?page=custom-background' ), 960 'meta' => array( 961 'class' => 'hide-if-customize', 962 ), 963 ) 964 ); 965 } 966 967 if ( current_theme_supports( 'custom-header' ) ) { 968 $wp_admin_bar->add_menu( 969 array( 970 'parent' => 'appearance', 971 'id' => 'header', 972 'title' => __( 'Header' ), 973 'href' => admin_url( 'themes.php?page=custom-header' ), 974 'meta' => array( 975 'class' => 'hide-if-customize', 976 ), 977 ) 978 ); 979 } 980 981 } 982 983 /** 984 * Provide an update link if theme/plugin/core updates are available. 985 * 986 * @since 3.1.0 987 * 988 * @param WP_Admin_Bar $wp_admin_bar 989 */ 990 function wp_admin_bar_updates_menu( $wp_admin_bar ) { 991 992 $update_data = wp_get_update_data(); 993 994 if ( ! $update_data['counts']['total'] ) { 995 return; 996 } 997 998 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; 999 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; 1000 1001 $wp_admin_bar->add_menu( 1002 array( 1003 'id' => 'updates', 1004 'title' => $title, 1005 'href' => network_admin_url( 'update-core.php' ), 1006 'meta' => array( 1007 'title' => $update_data['title'], 846 1008 ), 847 ) ); 848 } 849 850 if ( current_theme_supports( 'custom-header' ) ) { 851 $wp_admin_bar->add_menu( array( 852 'parent' => 'appearance', 853 'id' => 'header', 854 'title' => __( 'Header' ), 855 'href' => admin_url( 'themes.php?page=custom-header' ), 856 'meta' => array( 857 'class' => 'hide-if-customize', 858 ), 859 ) ); 860 } 861 862 } 863 864 /** 865 * Provide an update link if theme/plugin/core updates are available. 866 * 867 * @since 3.1.0 868 * 869 * @param WP_Admin_Bar $wp_admin_bar 870 */ 871 function wp_admin_bar_updates_menu( $wp_admin_bar ) { 872 873 $update_data = wp_get_update_data(); 874 875 if ( !$update_data['counts']['total'] ) 876 return; 877 878 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; 879 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; 880 881 $wp_admin_bar->add_menu( array( 882 'id' => 'updates', 883 'title' => $title, 884 'href' => network_admin_url( 'update-core.php' ), 885 'meta' => array( 886 'title' => $update_data['title'], 887 ), 888 ) ); 1009 ) 1010 ); 889 1011 } 890 1012 … … 897 1019 */ 898 1020 function wp_admin_bar_search_menu( $wp_admin_bar ) { 899 if ( is_admin() ) 900 return; 1021 if ( is_admin() ) { 1022 return; 1023 } 901 1024 902 1025 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; 903 1026 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; 904 1027 $form .= '<label for="adminbar-search" class="screen-reader-text">' . __( 'Search' ) . '</label>'; 905 $form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search') . '"/>';1028 $form .= '<input type="submit" class="adminbar-button" value="' . __( 'Search' ) . '"/>'; 906 1029 $form .= '</form>'; 907 1030 908 $wp_admin_bar->add_menu( array( 909 'parent' => 'top-secondary', 910 'id' => 'search', 911 'title' => $form, 912 'meta' => array( 913 'class' => 'admin-bar-search', 914 'tabindex' => -1, 915 ) 916 ) ); 1031 $wp_admin_bar->add_menu( 1032 array( 1033 'parent' => 'top-secondary', 1034 'id' => 'search', 1035 'title' => $form, 1036 'meta' => array( 1037 'class' => 'admin-bar-search', 1038 'tabindex' => -1, 1039 ), 1040 ) 1041 ); 917 1042 } 918 1043 … … 925 1050 */ 926 1051 function wp_admin_bar_add_secondary_groups( $wp_admin_bar ) { 927 $wp_admin_bar->add_group( array( 928 'id' => 'top-secondary', 929 'meta' => array( 930 'class' => 'ab-top-secondary', 931 ), 932 ) ); 933 934 $wp_admin_bar->add_group( array( 935 'parent' => 'wp-logo', 936 'id' => 'wp-logo-external', 937 'meta' => array( 938 'class' => 'ab-sub-secondary', 939 ), 940 ) ); 1052 $wp_admin_bar->add_group( 1053 array( 1054 'id' => 'top-secondary', 1055 'meta' => array( 1056 'class' => 'ab-top-secondary', 1057 ), 1058 ) 1059 ); 1060 1061 $wp_admin_bar->add_group( 1062 array( 1063 'parent' => 'wp-logo', 1064 'id' => 'wp-logo-external', 1065 'meta' => array( 1066 'class' => 'ab-sub-secondary', 1067 ), 1068 ) 1069 ); 941 1070 } 942 1071 … … 946 1075 * @since 3.1.0 947 1076 */ 948 function wp_admin_bar_header() { ?> 1077 function wp_admin_bar_header() { 1078 ?> 949 1079 <style type="text/css" media="print">#wpadminbar { display:none; }</style> 950 1080 <?php … … 956 1086 * @since 3.1.0 957 1087 */ 958 function _admin_bar_bump_cb() { ?> 1088 function _admin_bar_bump_cb() { 1089 1090 ?> 959 1091 <style type="text/css" media="screen"> 960 1092 html { margin-top: 32px !important; } … … 999 1131 1000 1132 // For all these types of requests, we never want an admin bar. 1001 if ( defined( 'XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') )1133 if ( defined( 'XMLRPC_REQUEST' ) || defined( 'DOING_AJAX' ) || defined( 'IFRAME_REQUEST' ) ) { 1002 1134 return false; 1135 } 1003 1136 1004 1137 if ( is_embed() ) { … … 1007 1140 1008 1141 // Integrated into the admin. 1009 if ( is_admin() ) 1142 if ( is_admin() ) { 1010 1143 return true; 1144 } 1011 1145 1012 1146 if ( ! isset( $show_admin_bar ) ) { … … 1040 1174 * 1041 1175 * @param string $context Context of this preference check. Defaults to 'front'. The 'admin' 1042 * preference is no longer used.1176 * preference is no longer used. 1043 1177 * @param int $user Optional. ID of the user to check, defaults to 0 for current user. 1044 1178 * @return bool Whether the admin bar should be showing for this user. … … 1046 1180 function _get_admin_bar_pref( $context = 'front', $user = 0 ) { 1047 1181 $pref = get_user_option( "show_admin_bar_{$context}", $user ); 1048 if ( false === $pref ) 1182 if ( false === $pref ) { 1049 1183 return true; 1184 } 1050 1185 1051 1186 return 'true' === $pref;
Note: See TracChangeset
for help on using the changeset viewer.