Index: wp-includes/admin-bar.php =================================================================== --- wp-includes/admin-bar.php (revision 16029) +++ wp-includes/admin-bar.php (working copy) @@ -6,45 +6,31 @@ */ /** - * Instantiate the admin bar class and set it up as a global for access elsewhere. + * Instantiate the admin bar object and set it up as a global for access elsewhere. + * + * @since 3.1.0 + * @return bool Whether the admin bar was successfully initialized. */ function wp_admin_bar_init() { - global $current_user, $pagenow, $wp_admin_bar; + global $wp_admin_bar; - if ( ! show_admin_bar() ) + if ( ! is_admin_bar_showing() ) return false; - /* Set the protocol constant used throughout this code */ - if ( !defined( 'PROTO' ) ) - if ( is_ssl() ) define( 'PROTO', 'https://' ); else define( 'PROTO', 'http://' ); - - /* Don't load the admin bar if the user is not logged in */ - if ( !is_user_logged_in() ) - return false; - - /* Set up the settings we need to render menu items */ - if ( !is_object( $current_user ) ) - $current_user = wp_get_current_user(); - - /* Enqueue the JS files for the admin bar. */ - wp_enqueue_script( 'jquery', false, false, false, true ); - /* Load the admin bar class code ready for instantiation */ require( ABSPATH . WPINC . '/admin-bar/admin-bar-class.php' ); - /* Only load super admin menu code if the logged in user is a super admin */ - if ( is_super_admin() ) { - require( ABSPATH . WPINC . '/admin-bar/admin-bar-debug.php' ); - require( ABSPATH . WPINC . '/admin-bar/admin-bar-superadmin.php' ); - } + /* Instantiate the admin bar */ + $admin_bar_class = apply_filters( 'wp_admin_bar_class', 'WP_Admin_Bar' ); + if ( class_exists( $admin_bar_class ) ) + $wp_admin_bar = new $admin_bar_class; + else + return false; + + $wp_admin_bar->initialize(); + $wp_admin_bar->add_menus(); - /* Initialize the admin bar */ - $wp_admin_bar = new wp_admin_bar(); - - add_action( 'wp_head', 'wp_admin_bar_css' ); - add_action( 'admin_head', 'wp_admin_bar_css' ); - - do_action('admin_bar_init'); + return true; } add_action( 'init', 'wp_admin_bar_init' ); @@ -56,11 +42,13 @@ * It includes the action "wp_before_admin_bar_render" which should be used to hook in and * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point, * right before the admin bar is rendered. This also gives you access to the $post global, among others. + * + * @since 3.1.0 */ function wp_admin_bar_render() { global $wp_admin_bar; - if ( !is_object( $wp_admin_bar ) ) + if ( ! is_object( $wp_admin_bar ) ) return false; $wp_admin_bar->load_user_locale_translations(); @@ -78,57 +66,77 @@ /** * Show the logged in user's gravatar as a separator. + * + * @since 3.1.0 */ function wp_admin_bar_me_separator() { - global $wp_admin_bar, $current_user; + global $wp_admin_bar; - if ( !is_object( $wp_admin_bar ) ) - return false; - - $wp_admin_bar->add_menu( array( 'id' => 'me', 'title' => get_avatar( $current_user->ID, 16 ), 'href' => $wp_admin_bar->user->account_domain . 'wp-admin/profile.php' ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'me', + 'title' => get_avatar( get_current_user_id(), 16 ), + 'href' => admin_url('profile.php'), + ) ); } -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_me_separator', 10 ); /** - * Use the $wp_admin_bar global to add the "My Account" menu and all submenus. + * Add the "My Account" menu and all submenus. + * + * @since 3.1.0 */ function wp_admin_bar_my_account_menu() { - global $wp_admin_bar, $current_user; + global $wp_admin_bar; - if ( !is_object( $wp_admin_bar ) ) - return false; - /* Add the 'My Account' menu */ - $wp_admin_bar->add_menu( array( 'id' => 'my-account', 'title' => __( 'My Account' ), 'href' => admin_url('profile.php') ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'my-account', + 'title' => __( 'My Account' ), + 'href' => admin_url('profile.php'), + ) ); /* Add the "My Account" sub menus */ - $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Edit My Profile' ), 'href' => admin_url('profile.php') ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Global Dashboard' ), 'href' => admin_url() ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) ); + $wp_admin_bar->add_menu( array( + 'parent' => 'my-account', + 'title' => __( 'Edit My Profile' ), + 'href' => admin_url('profile.php'), + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'my-account', + 'title' => __( 'Global Dashboard' ), + 'href' => admin_url(), + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'my-account', + 'title' => __( 'Log Out' ), + 'href' => wp_logout_url(), + ) ); } -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_account_menu', 20 ); /** - * Use the $wp_admin_bar global to add the "My Sites/[Site Name]" menu and all submenus. + * Add the "My Sites/[Site Name]" menu and all submenus. + * + * @since 3.1.0 */ function wp_admin_bar_my_blogs_menu() { global $wpdb, $wp_admin_bar; - if ( !is_object( $wp_admin_bar ) ) - return false; - /* Add the 'My Dashboards' menu if the user has more than one site. */ if ( count( $wp_admin_bar->user->blogs ) > 1 ) { - $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Sites' ), 'href' => $wp_admin_bar->user->account_domain ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'my-blogs', + 'title' => __( 'My Sites' ), + 'href' => $wp_admin_bar->user->account_domain, + ) ); $default = includes_url('images/wpmini-blue.png'); - $counter = 2; foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { $blogdomain = preg_replace( '!^https?://!', '', $blog->siteurl ); // @todo Replace with some favicon lookup. //$blavatar = ''; - $blavatar = '';; + $blavatar = ''; $marker = ''; if ( strlen($blog->blogname) > 35 ) @@ -139,205 +147,274 @@ else $blogname = substr( $blog->blogname, 0, 35 ) . $marker; - if ( !isset( $blog->visible ) || $blog->visible === true ) { - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-' . $blog->userblog_id, 'title' => $blavatar . $blogname, 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/' ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-d', 'title' => __( 'Dashboard' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/' ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-n', 'title' => __( 'New Post' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/post-new.php' ) ); + if ( ! isset( $blog->visible ) || $blog->visible === true ) { + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'blog-' . $blog->userblog_id, + 'title' => $blavatar . $blogname, + 'href' => $wp_admin_bar->proto . $blogdomain . '/wp-admin/', + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'blog-' . $blog->userblog_id, + 'id' => 'blog-' . $blog->userblog_id . '-d', + 'title' => __( 'Dashboard' ), + 'href' => $wp_admin_bar->proto . $blogdomain . '/wp-admin/', + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'blog-' . $blog->userblog_id, + 'id' => 'blog-' . $blog->userblog_id . '-n', + 'title' => __( 'New Post' ), + 'href' => $wp_admin_bar->proto . $blogdomain . '/wp-admin/post-new.php', + ) ); + // @todo, stats plugins should add this: - //$wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-s', 'title' => __( 'Site Stats' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/index.php?page=stats' ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-c', 'title' => __( 'Manage Comments' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/edit-comments.php' ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-v', 'title' => __( 'Read Site' ), 'href' => constant( 'PROTO' ) . $blogdomain ) ); + //$wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-s', 'title' => __( 'Site Stats' ), 'href' => $wp_admin_bar->proto . $blogdomain . '/wp-admin/index.php?page=stats' ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'blog-' . $blog->userblog_id, + 'id' => 'blog-' . $blog->userblog_id . '-c', + 'title' => __( 'Manage Comments' ), + 'href' => $wp_admin_bar->proto . $blogdomain . '/wp-admin/edit-comments.php', + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'blog-' . $blog->userblog_id, + 'id' => 'blog-' . $blog->userblog_id . '-v', + 'title' => __( 'Read Site' ), + 'href' => $wp_admin_bar->proto . $blogdomain, + ) ); } - $counter++; } /* Add the "Manage Sites" menu item */ // @todo, use dashboard site. - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'manage-blogs', 'title' => __( 'Manage Sites' ), admin_url('my-sites.php') ) ); + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'manage-blogs', + 'title' => __( 'Manage Sites' ), + admin_url('my-sites.php'), + ) ); /* Add the 'My Dashboard' menu if the user only has one site. */ } else { - $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Site' ), 'href' => $wp_admin_bar->user->account_domain ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'my-blogs', + 'title' => __( 'My Site' ), + 'href' => $wp_admin_bar->user->account_domain, + ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-d', 'title' => __( 'Dashboard' ), 'href' => admin_url() ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-n', 'title' => __( 'New Post' ), 'href' => admin_url('post-new.php') ) ); + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'blog-1-d', + 'title' => __( 'Dashboard' ), + 'href' => admin_url(), + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'blog-1-n', + 'title' => __( 'New Post' ), + 'href' => admin_url('post-new.php'), + ) ); + // @todo Stats plugins should add this. //$wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-s', 'title' => __( 'Site Stats' ), 'href' => admin_ur;('index.php?page=stats') ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-c', 'title' => __( 'Manage Comments' ), 'href' => admin_url('edit-comments.php') ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-v', 'title' => __( 'Read Site' ), 'href' => home_url() ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'blog-1-c', + 'title' => __( 'Manage Comments' ), + 'href' => admin_url('edit-comments.php'), + ) ); + + $wp_admin_bar->add_menu( array( + 'parent' => 'my-blogs', + 'id' => 'blog-1-v', + 'title' => __( 'Read Site' ), + 'href' => home_url(), + ) ); } } -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_blogs_menu', 30 ); /** * Show the blavatar of the current site as a separator. + * + * @since 3.1.0 */ function wp_admin_bar_blog_separator() { - global $wp_admin_bar, $current_user, $current_blog; + global $wp_admin_bar, $current_blog; - if ( !is_object( $wp_admin_bar ) ) - return false; - $default = includes_url('images/wpmini-blue.png'); - $wp_admin_bar->add_menu( array( 'id' => 'blog', 'title' => '', 'href' => home_url() ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'blog', + 'title' => '', + 'href' => home_url(), + ) ); } -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_blog_separator', 40 ); /** - * Use the $wp_admin_bar global to add a menu for site info, accessable to all users. + * Site info menu + * + * @since 3.1.0 */ function wp_admin_bar_bloginfo_menu() { global $wp_admin_bar; - if ( !is_object( $wp_admin_bar ) ) - return false; - /* Add the Site Info menu */ - $wp_admin_bar->add_menu( array( 'id' => 'bloginfo', 'title' => __( 'Site Info' ), 'href' => '' ) ); + $wp_admin_bar->add_menu( array( + 'id' => 'bloginfo', + 'title' => __( 'Site Info' ), + 'href' => '', + ) ); - $wp_admin_bar->add_menu( array( 'parent' => 'bloginfo', 'title' => __( 'Get Shortlink' ), 'href' => '', 'meta' => array( 'onclick' => 'javascript:function wpcomshort() { var url=document.location;var links=document.getElementsByTagName('link');var found=0;for(var i = 0, l; l = links[i]; i++){if(l.getAttribute('rel')=='shortlink') {found=l.getAttribute('href');break;}}if (!found) {for (var i = 0; l = document.links[i]; i++) {if (l.getAttribute('rel') == 'shortlink') {found = l.getAttribute('href');break;}}}if (found) {prompt('URL:', found);} else {alert('No shortlink available for this page'); } } wpcomshort(); return false;' ) ) ); + $wp_admin_bar->add_menu( array( + 'parent' => 'bloginfo', + 'title' => __( 'Get Shortlink' ), + 'href' => '', + 'meta' => array( + 'onclick' => 'javascript:function wpcomshort() { var url=document.location;var links=document.getElementsByTagName('link');var found=0;for(var i = 0, l; l = links[i]; i++){if(l.getAttribute('rel')=='shortlink') {found=l.getAttribute('href');break;}}if (!found) {for (var i = 0; l = document.links[i]; i++) {if (l.getAttribute('rel') == 'shortlink') {found = l.getAttribute('href');break;}}}if (found) {prompt('' . esc_js( __( 'URL:' ) ) . '', found);} else {alert('' . esc_js( __( 'No shortlink available for this page.' ) ) . ''); } } wpcomshort(); return false;' ) ) ); } -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_bloginfo_menu', 50 ); /** - * Use the $wp_admin_bar global to add the "Edit Post" menu when viewing a single post. + * Provide an edit link for posts and terms. + * + * @since 3.1.0 */ function wp_admin_bar_edit_menu() { - global $post, $wp_admin_bar; + global $wp_admin_bar, $wp_query; - if ( !is_object( $wp_admin_bar ) ) - return false; + $current_object = $wp_query->get_queried_object(); - if ( !is_single() && !is_page() ) + if ( empty( $current_object ) ) return false; - if ( !$post_type_object = get_post_type_object( $post->post_type ) ) - return false; + if ( + ! empty( $current_object->post_type ) && + ( $post_type_object = get_post_type_object( $current_object->post_type ) ) && + current_user_can( $post_type_object->cap->edit_post, $current_object->ID ) + ) { - if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) - return false; + $wp_admin_bar->add_menu( array( + 'id' => 'edit', + 'title' => __( 'Edit' ), + 'href' => get_edit_post_link( $current_object->ID ), + ) ); - $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit' ), 'href' => get_edit_post_link( $post->ID ) ) ); -} -add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_edit_menu', 100 ); + } elseif ( + ! empty( $current_object->taxonomy ) && + ( $tax = get_taxonomy( $current_object->taxonomy ) ) && + current_user_can( $tax->cap->edit_terms ) + ) { -/** - * Load up the CSS needed to render the admin bar nice and pretty. - */ -function wp_admin_bar_css() { - global $pagenow, $wp_locale, $wp_admin_bar; + $wp_admin_bar->add_menu( array( + 'id' => 'edit', + 'title' => __( 'Edit' ), + 'href' => get_edit_term_link( $current_object->term_id, $current_object->taxonomy ), + ) ); - if ( !is_object( $wp_admin_bar ) ) - return false; - - if ( !is_user_logged_in() ) - return; - - $nobump = false; - - /* Wish we could use wp_enqueue_style() here, but it will not let us pass GET params to the stylesheet correctly. */ - ?> - - - + + + + \ No newline at end of file +?> Index: wp-includes/functions.php =================================================================== --- wp-includes/functions.php (revision 16029) +++ wp-includes/functions.php (working copy) @@ -4405,37 +4405,17 @@ } /** - * Retrieve or set the admin bar display state. + * Set the display status of the admin bar * * This can be called immediately upon plugin load. It does not need to be called from a function hooked to the init action. * - * @param bool $show Optional. True to show the admin bar, false to hide it. If not provided the current display state is returned. - * @return bool The current display state if $show is not provided, the previous disply state if $show is provided. - * * @since 3.1.0 + * + * @param bool $show Whether to allow the admin bar to show. + * @return void */ -function show_admin_bar( $show = null ) { - static $show_admin_bar = null; - - if ( !isset($show_admin_bar) ) { - if ( null !== $show ) - $show_admin_bar = $show; - elseif ( defined('WP_SHOW_ADMIN_BAR') ) - $show_admin_bar = WP_SHOW_ADMIN_BAR; - else - $show_admin_bar = true; - } - - if ( null === $show ) { - return $show_admin_bar; - } else { - $old_value = $show_admin_bar; - $show_admin_bar = $show; - - // Prevent rendering if already initiated. - if ( ! $show_admin_bar && isset( $GLOBALS['wp_admin_bar'] ) ) - $GLOBALS['wp_admin_bar'] = null; - - return $old_value; - } +function show_admin_bar( $show ) { + global $show_admin_bar; + $show_admin_bar = (bool) $show; } + Index: wp-includes/admin-bar/admin-bar-class.php =================================================================== --- wp-includes/admin-bar/admin-bar-class.php (revision 16029) +++ wp-includes/admin-bar/admin-bar-class.php (working copy) @@ -1,20 +1,31 @@ proto = 'https://'; + $this->user = new stdClass; $this->menu = new stdClass; /* Populate settings we need for the menu based on the current user. */ - $this->user->blogs = get_blogs_of_user( $current_user->id ); + $this->user->blogs = get_blogs_of_user( get_current_user_id() ); if ( is_multisite() ) { - $this->user->active_blog = get_active_blog_for_user( $current_user->id ); + $this->user->active_blog = get_active_blog_for_user( get_current_user_id() ); $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); $this->user->account_domain = $this->user->domain; } else { @@ -23,6 +34,17 @@ $this->user->account_domain = $this->user->domain; } $this->user->locale = get_locale(); + + add_action( 'wp_head', 'wp_admin_bar_header' ); + add_action( 'admin_head', 'wp_admin_bar_header' ); + + wp_enqueue_style( 'admin-bar' ); + + if ( is_super_admin() ) { + wp_enqueue_style( 'super-admin-bar' ); + } + + do_action( 'admin_bar_init' ); } function add_menu( $args = array() ) { @@ -44,7 +66,7 @@ if ( empty( $id ) ) $id = esc_attr( sanitize_title( trim( $title ) ) ); - if ( !empty( $parent ) ) { + if ( ! empty( $parent ) ) { /* Add the menu to the parent item */ $child = array( 'id' => $id, @@ -52,7 +74,7 @@ 'href' => $href ); - if ( !empty( $meta ) ) + if ( ! empty( $meta ) ) $child['meta'] = $meta; $this->add_node( $parent, $this->menu, $child ); @@ -63,7 +85,7 @@ 'href' => $href ); - if ( !empty( $meta ) ) + if ( ! empty( $meta ) ) $this->menu->{$id}['meta'] = $meta; } } @@ -73,7 +95,7 @@ } function render() { - ?> + ?>