menu member var. * This is called very late on the footer actions so that it will render after anything else being * added to the footer. * * 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. */ function wp_admin_bar_render() { global $wp_admin_bar; if ( !is_object( $wp_admin_bar ) ) return false; $wp_admin_bar->load_user_locale_translations(); do_action( 'wp_before_admin_bar_render' ); $wp_admin_bar->render(); do_action( 'wp_after_admin_bar_render' ); $wp_admin_bar->unload_user_locale_translations(); } add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); add_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); /** * Show the logged in user's gravatar as a separator. */ function wp_admin_bar_me_separator() { global $wp_admin_bar, $current_user; 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' ) ); } 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. */ function wp_admin_bar_my_account_menu() { global $wp_admin_bar, $current_user; 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') ) ); /* 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() ) ); } add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_account_menu', 20 ); /** * Use the $wp_admin_bar global to add the "My Blogs/[Blog Name]" menu and all submenus. */ function wp_admin_bar_my_blogs_menu() { global $wpdb, $wp_admin_bar; if ( !is_object( $wp_admin_bar ) ) return false; /* Remove the global dashboard */ if ( is_multisite() ) { foreach ( (array) $wp_admin_bar->user->blogs as $key => $blog ) { if ( get_dashboard_blog() == $blog->domain ) unset( $wp_admin_bar->user->blogs[$key] ); } } /* Add the 'My Dashboards' menu if the user has more than one blog. */ if ( count( $wp_admin_bar->user->blogs ) > 1 ) { $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Blogs' ), '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 = 'Blavatar';; $marker = ''; if ( strlen($blog->blogname) > 35 ) $marker = '...'; if ( empty( $blog->blogname ) ) $blogname = $blog->domain; 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' ) ); // @todo, stats plugins should add this: //$wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-s', 'title' => __( 'Blog 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 Blog' ), 'href' => constant( 'PROTO' ) . $blogdomain ) ); } $counter++; } /* Add the "Manage Blogs" menu item */ // @todo, use dashboard blog. $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'manage-blogs', 'title' => __( 'Manage Blogs' ), admin_url('my-sites.php') ) ); /* Add the 'My Dashboard' menu if the user only has one blog. */ } else { $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Blog' ), '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') ) ); // @todo Stats plugins should add this. //$wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-s', 'title' => __( 'Blog 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 Blog' ), 'href' => home_url() ) ); } } add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_blogs_menu', 30 ); /** * Show the blavatar of the current blog as a separator. */ function wp_admin_bar_blog_separator() { global $wp_admin_bar, $current_user, $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' => '' . __( 'Current blog avatar' ) . '', '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 blog info, accessable to all users. */ function wp_admin_bar_bloginfo_menu() { global $wp_admin_bar; if ( !is_object( $wp_admin_bar ) ) return false; /* Add the Blog Info menu */ $wp_admin_bar->add_menu( array( 'id' => 'bloginfo', 'title' => __( 'Blog 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;' ) ) ); } 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. */ function wp_admin_bar_edit_menu() { global $post, $wp_admin_bar; if ( !is_object( $wp_admin_bar ) ) return false; if ( !is_single() && !is_page() ) return false; if ( !$post_type_object = get_post_type_object( $post->post_type ) ) return false; 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( $post->ID ) ) ); } add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_edit_menu', 100 ); /** * Load up the CSS needed to render the admin bar nice and pretty. */ function wp_admin_bar_css() { global $pagenow, $wp_locale; if ( !is_user_logged_in() || 'press-this.php' == $pagenow || 'update.php' == $pagenow || 'media-upload.php' == $pagenow ) return; $nobump = false; /* Wish we could use wp_enqueue_style() here, but it will not let us pass GET params to the stylesheet correctly. */ ?>