Ticket #28829: 28829.diff
| File 28829.diff, 9.4 KB (added by , 12 years ago) |
|---|
-
admin-bar.php
18 18 function _wp_admin_bar_init() { 19 19 global $wp_admin_bar; 20 20 21 if ( ! is_admin_bar_showing() ) 21 if ( ! is_admin_bar_showing() ) { 22 22 return false; 23 } 23 24 24 25 /* Load the admin bar class code ready for instantiation */ 25 26 require( ABSPATH . WPINC . '/class-wp-admin-bar.php' ); … … 34 35 * @param string $wp_admin_bar_class Admin bar class to use. Default 'WP_Admin_Bar'. 35 36 */ 36 37 $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); 37 if ( class_exists( $admin_bar_class ) ) 38 if ( class_exists( $admin_bar_class ) ) { 38 39 $wp_admin_bar = new $admin_bar_class; 39 else40 } else { 40 41 return false; 42 } 41 43 42 44 $wp_admin_bar->initialize(); 43 45 $wp_admin_bar->add_menus(); … … 62 64 function wp_admin_bar_render() { 63 65 global $wp_admin_bar; 64 66 65 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) 67 if ( ! is_admin_bar_showing() || ! is_object( $wp_admin_bar ) ) { 66 68 return false; 69 } 67 70 68 71 /** 69 72 * Load all necessary admin bar items. … … 184 187 $current_user = wp_get_current_user(); 185 188 $profile_url = get_edit_profile_url( $user_id ); 186 189 187 if ( ! $user_id ) 190 if ( ! $user_id ) { 188 191 return; 192 } 189 193 190 194 $avatar = get_avatar( $user_id, 26 ); 191 195 $howdy = sprintf( __('Howdy, %1$s'), $current_user->display_name ); … … 215 219 $current_user = wp_get_current_user(); 216 220 $profile_url = get_edit_profile_url( $user_id ); 217 221 218 if ( ! $user_id ) 222 if ( ! $user_id ) { 219 223 return; 224 } 220 225 221 226 $wp_admin_bar->add_group( array( 222 227 'parent' => 'my-account', … … 261 266 */ 262 267 function wp_admin_bar_site_menu( $wp_admin_bar ) { 263 268 // Don't show for logged out users. 264 if ( ! is_user_logged_in() ) 269 if ( ! is_user_logged_in() ) { 265 270 return; 271 } 266 272 267 273 // Show only when the user is a member of this site, or they're a super admin. 268 if ( ! is_user_member_of_blog() && ! is_super_admin() ) 274 if ( ! is_user_member_of_blog() && ! is_super_admin() ) { 269 275 return; 276 } 270 277 271 278 $blogname = get_bloginfo('name'); 272 279 273 if ( empty( $blogname ) ) 280 if ( empty( $blogname ) ) { 274 281 $blogname = preg_replace( '#^(https?://)?(www.)?#', '', get_home_url() ); 282 } 275 283 276 284 if ( is_network_admin() ) { 277 285 $blogname = sprintf( __('Network Admin: %s'), esc_html( get_current_site()->site_name ) ); … … 330 338 */ 331 339 function wp_admin_bar_my_sites_menu( $wp_admin_bar ) { 332 340 // Don't show for logged out users or single site mode. 333 if ( ! is_user_logged_in() || ! is_multisite() ) 341 if ( ! is_user_logged_in() || ! is_multisite() ) { 334 342 return; 343 } 335 344 336 345 // Show only when the user has at least one site, or they're a super admin. 337 if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() ) 346 if ( count( $wp_admin_bar->user->blogs ) < 1 && ! is_super_admin() ) { 338 347 return; 348 } 339 349 340 350 $wp_admin_bar->add_menu( array( 341 351 'id' => 'my-sites', … … 459 469 $short = wp_get_shortlink( 0, 'query' ); 460 470 $id = 'get-shortlink'; 461 471 462 if ( empty( $short ) ) 472 if ( empty( $short ) ) { 463 473 return; 474 } 464 475 465 476 $html = '<input class="shortlink-input" type="text" readonly="readonly" value="' . esc_attr( $short ) . '" />'; 466 477 … … 524 535 } else { 525 536 $current_object = $wp_the_query->get_queried_object(); 526 537 527 if ( empty( $current_object ) ) 538 if ( empty( $current_object ) ) { 528 539 return; 540 } 529 541 530 542 if ( ! empty( $current_object->post_type ) 531 543 && ( $post_type_object = get_post_type_object( $current_object->post_type ) ) … … 563 575 564 576 $cpts = (array) get_post_types( array( 'show_in_admin_bar' => true ), 'objects' ); 565 577 566 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) 578 if ( isset( $cpts['post'] ) && current_user_can( $cpts['post']->cap->create_posts ) ) { 567 579 $actions[ 'post-new.php' ] = array( $cpts['post']->labels->name_admin_bar, 'new-post' ); 580 } 568 581 569 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) 582 if ( isset( $cpts['attachment'] ) && current_user_can( 'upload_files' ) ) { 570 583 $actions[ 'media-new.php' ] = array( $cpts['attachment']->labels->name_admin_bar, 'new-media' ); 584 } 571 585 572 if ( current_user_can( 'manage_links' ) ) 586 if ( current_user_can( 'manage_links' ) ) { 573 587 $actions[ 'link-add.php' ] = array( _x( 'Link', 'add new from admin bar' ), 'new-link' ); 588 } 574 589 575 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) 590 if ( isset( $cpts['page'] ) && current_user_can( $cpts['page']->cap->create_posts ) ) { 576 591 $actions[ 'post-new.php?post_type=page' ] = array( $cpts['page']->labels->name_admin_bar, 'new-page' ); 592 } 577 593 578 594 unset( $cpts['post'], $cpts['page'], $cpts['attachment'] ); 579 595 580 596 // Add any additional custom post types. 581 597 foreach ( $cpts as $cpt ) { 582 if ( ! current_user_can( $cpt->cap->create_posts ) ) 598 if ( ! current_user_can( $cpt->cap->create_posts ) ) { 583 599 continue; 600 } 584 601 585 602 $key = 'post-new.php?post_type=' . $cpt->name; 586 603 $actions[ $key ] = array( $cpt->labels->name_admin_bar, 'new-' . $cpt->name ); 587 604 } 588 605 // Avoid clash with parent node and a 'content' post type. 589 if ( isset( $actions['post-new.php?post_type=content'] ) ) 606 if ( isset( $actions['post-new.php?post_type=content'] ) ) { 590 607 $actions['post-new.php?post_type=content'][1] = 'add-new-content'; 608 } 591 609 592 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) 610 if ( current_user_can( 'create_users' ) || current_user_can( 'promote_users' ) ) { 593 611 $actions[ 'user-new.php' ] = array( _x( 'User', 'add new from admin bar' ), 'new-user' ); 612 } 594 613 595 if ( ! $actions ) 614 if ( ! $actions ) { 596 615 return; 616 } 597 617 598 618 $title = '<span class="ab-icon"></span><span class="ab-label">' . _x( 'New', 'admin bar menu group label' ) . '</span>'; 599 619 … … 626 646 * @param WP_Admin_Bar $wp_admin_bar 627 647 */ 628 648 function wp_admin_bar_comments_menu( $wp_admin_bar ) { 629 if ( !current_user_can('edit_posts') ) 649 if ( !current_user_can('edit_posts') ) { 630 650 return; 651 } 631 652 632 653 $awaiting_mod = wp_count_comments(); 633 654 $awaiting_mod = $awaiting_mod->moderated; … … 654 675 function wp_admin_bar_appearance_menu( $wp_admin_bar ) { 655 676 $wp_admin_bar->add_group( array( 'parent' => 'site-name', 'id' => 'appearance' ) ); 656 677 657 if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) 678 if ( current_user_can( 'switch_themes' ) || current_user_can( 'edit_theme_options' ) ) { 658 679 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __('Themes'), 'href' => admin_url('themes.php') ) ); 680 } 659 681 660 if ( ! current_user_can( 'edit_theme_options' ) ) 682 if ( ! current_user_can( 'edit_theme_options' ) ) { 661 683 return; 684 } 662 685 663 686 $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 664 687 $wp_admin_bar->add_menu( array( … … 672 695 ) ); 673 696 add_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' ); 674 697 675 if ( current_theme_supports( 'widgets' ) ) 698 if ( current_theme_supports( 'widgets' ) ) { 676 699 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __('Widgets'), 'href' => admin_url('widgets.php') ) ); 700 } 677 701 678 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) 702 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) { 679 703 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __('Menus'), 'href' => admin_url('nav-menus.php') ) ); 704 } 680 705 681 if ( current_theme_supports( 'custom-background' ) ) 706 if ( current_theme_supports( 'custom-background' ) ) { 682 707 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __('Background'), 'href' => admin_url('themes.php?page=custom-background') ) ); 708 } 683 709 684 if ( current_theme_supports( 'custom-header' ) ) 710 if ( current_theme_supports( 'custom-header' ) ) { 685 711 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __('Header'), 'href' => admin_url('themes.php?page=custom-header') ) ); 712 } 686 713 } 687 714 688 715 /** … … 696 723 697 724 $update_data = wp_get_update_data(); 698 725 699 if ( !$update_data['counts']['total'] ) 726 if ( !$update_data['counts']['total'] ) { 700 727 return; 728 } 701 729 702 730 $title = '<span class="ab-icon"></span><span class="ab-label">' . number_format_i18n( $update_data['counts']['total'] ) . '</span>'; 703 731 $title .= '<span class="screen-reader-text">' . $update_data['title'] . '</span>'; … … 720 748 * @param WP_Admin_Bar $wp_admin_bar 721 749 */ 722 750 function wp_admin_bar_search_menu( $wp_admin_bar ) { 723 if ( is_admin() ) 751 if ( is_admin() ) { 724 752 return; 753 } 725 754 726 755 $form = '<form action="' . esc_url( home_url( '/' ) ) . '" method="get" id="adminbarsearch">'; 727 756 $form .= '<input class="adminbar-input" name="s" id="adminbar-search" type="text" value="" maxlength="150" />'; … … 816 845 global $show_admin_bar, $pagenow; 817 846 818 847 // For all these types of requests, we never want an admin bar. 819 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') ) 848 if ( defined('XMLRPC_REQUEST') || defined('DOING_AJAX') || defined('IFRAME_REQUEST') ) { 820 849 return false; 850 } 821 851 822 852 // Integrated into the admin. 823 if ( is_admin() ) 853 if ( is_admin() ) { 824 854 return true; 855 } 825 856 826 857 if ( ! isset( $show_admin_bar ) ) { 827 858 if ( ! is_user_logged_in() || 'wp-login.php' == $pagenow ) { … … 859 890 */ 860 891 function _get_admin_bar_pref( $context = 'front', $user = 0 ) { 861 892 $pref = get_user_option( "show_admin_bar_{$context}", $user ); 862 if ( false === $pref ) 893 if ( false === $pref ) { 863 894 return true; 895 } 864 896 865 897 return 'true' === $pref; 866 898 }