Changeset 5289 for trunk/bp-core/bp-core-adminbar.php
- Timestamp:
- 11/06/2011 06:52:09 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-adminbar.php
r5213 r5289 1 1 <?php 2 2 3 /** 3 4 * BuddyPress Core Admin Bar … … 16 17 17 18 /** 18 * Unhook the WordPress core menus.19 * Adds the secondary BuddyPress area to the my-account menu 19 20 * 20 * @since BuddyPress (r4151) 21 * 22 * @uses remove_action 23 * @uses is_network_admin() 24 * @uses is_user_admin() 21 * @since BuddyPress 1.6 22 * @global WP_Admin_Bar $wp_admin_bar 23 * @return If doing ajax 25 24 */ 26 function bp_admin_bar_remove_wp_menus() { 25 function bp_admin_bar_my_account_secondary() { 26 global $wp_admin_bar; 27 27 28 /** 29 * WP 3.2 hooks 30 */ 31 remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 10 ); 32 remove_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 ); 33 remove_action( 'admin_bar_menu', 'wp_admin_bar_dashboard_view_site_menu', 25 ); 34 remove_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 ); 28 // Bail if this is an ajax request 29 if ( defined( 'DOING_AJAX' ) ) 30 return; 35 31 36 // Don't show the 'Edit Page' menu on BP pages 37 if ( !bp_is_blog_page() ) 38 remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 30 ); 32 // Only add menu for logged in user 33 if ( is_user_logged_in() ) { 39 34 40 if ( !is_network_admin() && !is_user_admin() ) { 41 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 50 ); 42 remove_action( 'admin_bar_menu', 'wp_admin_bar_appearance_menu', 60 ); 43 remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 70 ); 44 } 45 46 /** 47 * WP 3.3+ 48 */ 49 remove_action( 'admin_bar_menu', 'wp_admin_bar_blog_front_menu', 30 ); 50 remove_action( 'admin_bar_menu', 'wp_admin_bar_shortlink_menu', 80 ); 51 52 // Menus specific to blog posts shouldn't show on BP pages 53 if ( !bp_is_blog_page() && !is_network_admin() && !is_admin() ) { 54 remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 50 ); 55 remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); 56 } 57 58 // Don't show the Updates menu on the front end 59 if ( !is_network_admin() && !is_admin() ) { 60 remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 40 ); 35 // Add secondary parent item for all BuddyPress components 36 $wp_admin_bar->add_menu( array( 37 'parent' => 'my-account', 38 'id' => 'my-account-buddypress', 39 'title' => ' ', 40 'meta' => array( 41 'class' => 'secondary', 42 ) 43 ) ); 61 44 } 62 45 } 63 add_action( 'bp_init', 'bp_admin_bar_remove_wp_menus', 2 ); 64 65 /** 66 * Add a menu for the root site of this BuddyPress network 67 * 68 * @global type $bp 69 * @global type $wp_admin_bar 70 * @return If in ajax 71 */ 72 function bp_admin_bar_root_site() { 73 global $bp, $wp_admin_bar; 74 75 // Create the root blog menu 76 $wp_admin_bar->add_menu( array( 77 'id' => 'bp-root-blog', 78 'title' => get_blog_option( bp_get_root_blog_id(), 'blogname' ), 79 'href' => bp_get_root_domain() 80 ) ); 81 82 // Logged in user 83 if ( is_user_logged_in() ) { 84 85 // Dashboard links 86 if ( is_super_admin() ) { 87 88 // Add site admin link 89 $wp_admin_bar->add_menu( array( 90 'id' => 'dashboard', 91 'parent' => 'bp-root-blog', 92 'title' => __( 'Admin Dashboard', 'buddypress' ), 93 'href' => get_admin_url( bp_get_root_blog_id() ) 94 ) ); 95 96 // Add network admin link 97 if ( is_multisite() ) { 98 99 // Link to the network admin dashboard 100 $wp_admin_bar->add_menu( array( 101 'id' => 'network-dashboard', 102 'parent' => 'bp-root-blog', 103 'title' => __( 'Network Dashboard', 'buddypress' ), 104 'href' => network_admin_url() 105 ) ); 106 } 107 } 108 } 109 } 110 add_action( 'admin_bar_menu', 'bp_admin_bar_root_site', 15 ); 111 112 /** 113 * Add the "My Sites/[Site Name]" menu and all submenus. 114 */ 115 function bp_admin_bar_my_sites_menu() { 116 global $wpdb, $wp_admin_bar; 117 118 /* Add the 'My Sites' menu if the user has more than one site. */ 119 if ( count( $wp_admin_bar->user->blogs ) <= 1 ) 120 return; 121 122 $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Sites' ), 'href' => admin_url( 'my-sites.php' ) ) ); 123 124 $default = includes_url( 'images/wpmini-blue.png' ); 125 126 foreach ( (array)$wp_admin_bar->user->blogs as $blog ) { 127 // @todo Replace with some favicon lookup. 128 //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $default ) ) . '" alt="Blavatar" width="16" height="16" />'; 129 $blavatar = '<img src="' . esc_url( $default ) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>'; 130 131 $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname; 132 133 $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-' . $blog->userblog_id, 'title' => $blavatar . $blogname, 'href' => get_admin_url( $blog->userblog_id ) ) ); 134 $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-d', 'title' => __( 'Dashboard' ), 'href' => get_admin_url( $blog->userblog_id ) ) ); 135 136 if ( current_user_can_for_blog( $blog->userblog_id, 'edit_posts' ) ) { 137 $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-n', 'title' => __( 'New Post' ), 'href' => get_admin_url( $blog->userblog_id, 'post-new.php' ) ) ); 138 $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-c', 'title' => __( 'Manage Comments' ), 'href' => get_admin_url( $blog->userblog_id, 'edit-comments.php' ) ) ); 139 } 140 141 $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-v', 'title' => __( 'Visit Site' ), 'href' => get_home_url( $blog->userblog_id ) ) ); 142 } 143 } 144 add_action( 'admin_bar_menu', 'bp_admin_bar_my_sites_menu', 17 ); 145 146 /** 147 * Add edit comments link with awaiting moderation count bubble 148 */ 149 function bp_admin_bar_comments_menu( $wp_admin_bar ) { 150 global $wp_admin_bar; 151 152 if ( !current_user_can( 'edit_posts' ) ) 153 return; 154 155 $awaiting_mod = wp_count_comments(); 156 $awaiting_mod = $awaiting_mod->moderated; 157 158 $awaiting_mod = $awaiting_mod ? "<span id='ab-awaiting-mod' class='pending-count'>" . number_format_i18n( $awaiting_mod ) . "</span>" : ''; 159 $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'comments', 'title' => sprintf( __( 'Comments %s' ), $awaiting_mod ), 'href' => admin_url( 'edit-comments.php' ) ) ); 160 } 161 add_action( 'bp_setup_admin_bar', 'bp_admin_bar_comments_menu', 3 ); 162 163 /** 164 * Add "Appearance" menu with widget and nav menu submenu 165 */ 166 function bp_admin_bar_appearance_menu() { 167 global $wp_admin_bar; 168 169 // You can have edit_theme_options but not switch_themes. 170 if ( !current_user_can( 'switch_themes' ) && !current_user_can( 'edit_theme_options' ) ) 171 return; 172 173 $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'appearance', 'title' => __( 'Appearance' ), 'href' => admin_url( 'themes.php' ) ) ); 174 175 if ( !current_user_can( 'edit_theme_options' ) ) 176 return; 177 178 if ( current_user_can( 'switch_themes' ) ) 179 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'themes', 'title' => __( 'Themes' ), 'href' => admin_url( 'themes.php' ) ) ); 180 181 if ( current_theme_supports( 'widgets' ) ) 182 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'widgets', 'title' => __( 'Widgets' ), 'href' => admin_url( 'widgets.php' ) ) ); 183 184 if ( current_theme_supports( 'menus' ) || current_theme_supports( 'widgets' ) ) 185 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'menus', 'title' => __( 'Menus' ), 'href' => admin_url( 'nav-menus.php' ) ) ); 186 187 if ( current_theme_supports( 'custom-background' ) ) 188 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'background', 'title' => __( 'Background' ), 'href' => admin_url( 'themes.php?page=custom-background' ) ) ); 189 190 if ( current_theme_supports( 'custom-header' ) ) 191 $wp_admin_bar->add_menu( array( 'parent' => 'appearance', 'id' => 'header', 'title' => __( 'Header' ), 'href' => admin_url( 'themes.php?page=custom-header' ) ) ); 192 } 193 add_action( 'bp_setup_admin_bar', 'bp_admin_bar_appearance_menu', 3 ); 194 195 /** 196 * Provide an update link if theme/plugin/core updates are available 197 */ 198 function bp_admin_bar_updates_menu() { 199 global $wp_admin_bar; 200 201 if ( !current_user_can( 'install_plugins' ) ) 202 return; 203 204 $plugin_update_count = $theme_update_count = $wordpress_update_count = 0; 205 $update_plugins = get_site_transient( 'update_plugins' ); 206 if ( !empty( $update_plugins->response ) ) 207 $plugin_update_count = count( $update_plugins->response ); 208 $update_themes = get_site_transient( 'update_themes' ); 209 if ( !empty( $update_themes->response ) ) 210 $theme_update_count = count( $update_themes->response ); 211 /* @todo get_core_updates() is only available on admin page loads 212 $update_wordpress = get_core_updates( array('dismissed' => false) ); 213 if ( !empty($update_wordpress) && !in_array( $update_wordpress[0]->response, array('development', 'latest') ) ) 214 $wordpress_update_count = 1; 215 */ 216 217 $update_count = $plugin_update_count + $theme_update_count + $wordpress_update_count; 218 219 if ( !$update_count ) 220 return; 221 222 $update_title = array( ); 223 if ( $wordpress_update_count ) 224 $update_title[] = sprintf( __( '%d WordPress Update' ), $wordpress_update_count ); 225 if ( $plugin_update_count ) 226 $update_title[] = sprintf( _n( '%d Plugin Update', '%d Plugin Updates', $plugin_update_count ), $plugin_update_count ); 227 if ( $theme_update_count ) 228 $update_title[] = sprintf( _n( '%d Theme Update', '%d Theme Updates', $theme_update_count ), $theme_update_count ); 229 230 $update_title = !empty( $update_title ) ? esc_attr( implode( ', ', $update_title ) ) : ''; 231 232 $update_title = "<span title='$update_title'>"; 233 $update_title .= sprintf( __( 'Updates %s' ), "<span id='ab-updates' class='update-count'>" . number_format_i18n( $update_count ) . '</span>' ); 234 $update_title .= '</span>'; 235 236 $wp_admin_bar->add_menu( array( 'parent' => 'dashboard', 'id' => 'updates', 'title' => $update_title, 'href' => network_admin_url( 'update-core.php' ) ) ); 237 } 238 add_action( 'bp_setup_admin_bar', 'bp_admin_bar_updates_menu', 3 ); 46 add_action( 'admin_bar_menu', 'bp_admin_bar_my_account_secondary', 9999 ); 239 47 240 48 /** 241 49 * Handle the Admin Bar CSS 50 * 51 * @since BuddyPress 1.5 242 52 */ 243 53 function bp_core_load_admin_bar_css() { 244 global $wp_version; 54 55 $version = '2011116'; 245 56 246 57 if ( !bp_use_wp_admin_bar() ) … … 253 64 $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar.css'; 254 65 255 wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array( 'admin-bar' ), '20110723');66 wp_enqueue_style( 'bp-admin-bar', apply_filters( 'bp_core_admin_bar_css', $stylesheet ), array( 'admin-bar' ), $version ); 256 67 257 68 if ( !is_rtl() ) … … 263 74 $stylesheet = BP_PLUGIN_URL . '/bp-core/css/admin-bar-rtl.css'; 264 75 265 wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_admin_bar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), '20110723');76 wp_enqueue_style( 'bp-admin-bar-rtl', apply_filters( 'bp_core_admin_bar_rtl_css', $stylesheet ), array( 'bp-admin-bar' ), $version ); 266 77 } 267 78 add_action( 'bp_init', 'bp_core_load_admin_bar_css' ); 79 268 80 ?>
Note: See TracChangeset
for help on using the changeset viewer.