Changeset 3817 for trunk/bp-core/bp-core-adminbar.php
- Timestamp:
- 01/22/2011 01:51:41 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-core/bp-core-adminbar.php
r3757 r3817 1 1 <?php 2 2 3 function bp_core_admin_bar() { 4 global $bp, $wpdb, $current_blog; 5 6 if ( defined( 'BP_DISABLE_ADMIN_BAR' ) ) 7 return false; 8 9 if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() ) 10 return false; 11 12 $bp->doing_admin_bar = true; 13 14 echo '<div id="wp-admin-bar"><div class="padder">'; 15 16 // **** Do bp-adminbar-logo Actions ******** 17 do_action( 'bp_adminbar_logo' ); 18 19 echo '<ul class="main-nav">'; 20 21 // **** Do bp-adminbar-menus Actions ******** 22 do_action( 'bp_adminbar_menus' ); 23 24 echo '</ul>'; 25 echo "</div></div><!-- #wp-admin-bar -->\n\n"; 26 27 $bp->doing_admin_bar = false; 28 } 29 30 // **** Default BuddyPress admin bar logo ******** 31 function bp_adminbar_logo() { 32 global $bp; 33 34 echo '<a href="' . $bp->root_domain . '" id="admin-bar-logo">' . get_blog_option( BP_ROOT_BLOG, 'blogname') . '</a>'; 35 } 36 37 // **** "Log In" and "Sign Up" links (Visible when not logged in) ******** 38 function bp_adminbar_login_menu() { 39 global $bp; 40 41 if ( is_user_logged_in() ) 42 return false; 43 44 echo '<li class="bp-login no-arrow"><a href="' . $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . '">' . __( 'Log In', 'buddypress' ) . '</a></li>'; 45 46 // Show "Sign Up" link if user registrations are allowed 47 if ( bp_get_signup_allowed() ) 48 echo '<li class="bp-signup no-arrow"><a href="' . bp_get_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>'; 49 } 50 51 52 // **** "My Account" Menu ****** 53 function bp_adminbar_account_menu() { 54 global $bp; 55 56 if ( !$bp->bp_nav || !is_user_logged_in() ) 57 return false; 58 59 echo '<li id="bp-adminbar-account-menu"><a href="' . bp_loggedin_user_domain() . '">'; 60 61 echo __( 'My Account', 'buddypress' ) . '</a>'; 62 echo '<ul>'; 63 64 /* Loop through each navigation item */ 65 $counter = 0; 66 foreach( (array)$bp->bp_nav as $nav_item ) { 67 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 68 69 echo '<li' . $alt . '>'; 70 echo '<a id="bp-admin-' . $nav_item['css_id'] . '" href="' . $nav_item['link'] . '">' . $nav_item['name'] . '</a>'; 71 72 if ( isset( $bp->bp_options_nav[$nav_item['slug']] ) && is_array( $bp->bp_options_nav[$nav_item['slug']] ) ) { 73 echo '<ul>'; 74 $sub_counter = 0; 75 76 foreach( (array)$bp->bp_options_nav[$nav_item['slug']] as $subnav_item ) { 77 $link = $subnav_item['link']; 78 $name = $subnav_item['name']; 79 80 if ( isset( $bp->displayed_user->domain ) ) 81 $link = str_replace( $bp->displayed_user->domain, $bp->loggedin_user->domain, $subnav_item['link'] ); 82 83 if ( isset( $bp->displayed_user->userdata->user_login ) ) 84 $name = str_replace( $bp->displayed_user->userdata->user_login, $bp->loggedin_user->userdata->user_login, $subnav_item['name'] ); 85 86 $alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : ''; 87 echo '<li' . $alt . '><a id="bp-admin-' . $subnav_item['css_id'] . '" href="' . $link . '">' . $name . '</a></li>'; 88 $sub_counter++; 89 } 90 echo '</ul>'; 91 } 92 93 echo '</li>'; 94 95 $counter++; 96 } 97 98 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 99 100 echo '<li' . $alt . '><a id="bp-admin-logout" class="logout" href="' . wp_logout_url( site_url() ) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>'; 101 echo '</ul>'; 102 echo '</li>'; 103 } 104 105 // *** "My Blogs" Menu ******** 106 function bp_adminbar_blogs_menu() { 107 global $bp; 108 109 if ( !is_user_logged_in() || !bp_is_active( 'blogs' ) ) 110 return false; 111 112 if ( !is_multisite() ) 113 return false; 114 115 if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', 'bp' ) ) { 116 $blogs = bp_blogs_get_blogs_for_user( $bp->loggedin_user->id, true ); 117 wp_cache_set( 'bp_blogs_of_user_' . $bp->loggedin_user->id . '_inc_hidden', $blogs, 'bp' ); 118 } 119 120 echo '<li id="bp-adminbar-blogs-menu"><a href="' . $bp->loggedin_user->domain . $bp->blogs->slug . '/">'; 121 122 _e( 'My Blogs', 'buddypress' ); 123 124 echo '</a>'; 125 echo '<ul>'; 126 127 $counter = 0; 128 if ( is_array( $blogs['blogs'] ) && (int)$blogs['count'] ) { 129 foreach ( (array)$blogs['blogs'] as $blog ) { 130 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 131 $site_url = esc_attr( $blog->siteurl ); 132 133 echo '<li' . $alt . '>'; 134 echo '<a href="' . $site_url . '">' . esc_html( $blog->name ) . '</a>'; 135 echo '<ul>'; 136 echo '<li class="alt"><a href="' . $site_url . 'wp-admin/">' . __( 'Dashboard', 'buddypress' ) . '</a></li>'; 137 echo '<li><a href="' . $site_url . 'wp-admin/post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>'; 138 echo '<li class="alt"><a href="' . $site_url . 'wp-admin/edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>'; 139 echo '<li><a href="' . $site_url . 'wp-admin/edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>'; 140 echo '</ul>'; 141 142 do_action( 'bp_adminbar_blog_items', $blog ); 143 144 echo '</li>'; 145 $counter++; 146 } 147 } 148 149 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; 150 151 if ( bp_blog_signup_enabled() ) { 152 echo '<li' . $alt . '>'; 153 echo '<a href="' . $bp->root_domain . '/' . $bp->blogs->slug . '/create/">' . __( 'Create a Blog!', 'buddypress' ) . '</a>'; 154 echo '</li>'; 155 } 156 157 echo '</ul>'; 158 echo '</li>'; 159 } 160 161 function bp_adminbar_thisblog_menu() { 162 if ( current_user_can( 'edit_posts' ) ) { 163 echo '<li id="bp-adminbar-thisblog-menu"><a href="' . admin_url() . '">'; 164 165 _e( 'Dashboard', 'buddypress' ); 166 167 echo '</a>'; 168 echo '<ul>'; 169 170 echo '<li class="alt"><a href="' . admin_url() . 'post-new.php">' . __( 'New Post', 'buddypress' ) . '</a></li>'; 171 echo '<li><a href="' . admin_url() . 'edit.php">' . __( 'Manage Posts', 'buddypress' ) . '</a></li>'; 172 echo '<li class="alt"><a href="' . admin_url() . 'edit-comments.php">' . __( 'Manage Comments', 'buddypress' ) . '</a></li>'; 173 174 do_action( 'bp_adminbar_thisblog_items' ); 175 176 echo '</ul>'; 177 echo '</li>'; 178 } 179 } 180 181 // **** "Notifications" Menu ********* 182 function bp_adminbar_notifications_menu() { 183 global $bp; 184 185 if ( !is_user_logged_in() ) 186 return false; 187 188 echo '<li id="bp-adminbar-notifications-menu"><a href="' . $bp->loggedin_user->domain . '">'; 189 _e( 'Notifications', 'buddypress' ); 190 191 if ( $notifications = bp_users_get_notifications_for_user( $bp->loggedin_user->id ) ) { ?> 192 <span><?php echo count( $notifications ) ?></span> 193 <?php 194 } 195 196 echo '</a>'; 197 echo '<ul>'; 198 199 if ( $notifications ) { 200 $counter = 0; 201 for ( $i = 0; $i < count($notifications); $i++ ) { 202 $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?> 203 204 <li<?php echo $alt ?>><?php echo $notifications[$i] ?></li> 205 206 <?php $counter++; 207 } 208 } else { ?> 209 210 <li><a href="<?php echo $bp->loggedin_user->domain ?>"><?php _e( 'No new notifications.', 'buddypress' ); ?></a></li> 211 212 <?php 213 } 214 215 echo '</ul>'; 216 echo '</li>'; 217 } 218 219 // **** "Blog Authors" Menu (visible when not logged in) ******** 220 function bp_adminbar_authors_menu() { 221 global $bp, $current_blog, $wpdb; 222 223 // Only for multisite 224 if ( !is_multisite() ) 225 return false; 226 227 // Hide on root blog 228 if ( $current_blog->blog_id == BP_ROOT_BLOG || !bp_is_active( 'blogs' ) ) 229 return false; 230 231 $blog_prefix = $wpdb->get_blog_prefix( $current_blog->blog_id ); 232 $authors = $wpdb->get_results( "SELECT user_id, user_login, user_nicename, display_name, user_email, meta_value as caps FROM $wpdb->users u, $wpdb->usermeta um WHERE u.ID = um.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY um.user_id" ); 233 234 if ( !empty( $authors ) ) { 235 // This is a blog, render a menu with links to all authors 236 echo '<li id="bp-adminbar-authors-menu"><a href="/">'; 237 _e('Blog Authors', 'buddypress'); 238 echo '</a>'; 239 240 echo '<ul class="author-list">'; 241 foreach( (array)$authors as $author ) { 242 $caps = maybe_unserialize( $author->caps ); 243 if ( isset( $caps['subscriber'] ) || isset( $caps['contributor'] ) ) continue; 244 245 echo '<li>'; 246 echo '<a href="' . bp_core_get_user_domain( $author->user_id, $author->user_nicename, $author->user_login ) . '">'; 247 echo bp_core_fetch_avatar( array( 'item_id' => $author->user_id, 'email' => $author->user_email, 'width' => 15, 'height' => 15 ) ) ; 248 echo ' ' . $author->display_name . '</a>'; 249 echo '<div class="admin-bar-clear"></div>'; 250 echo '</li>'; 251 } 252 echo '</ul>'; 253 echo '</li>'; 254 } 255 } 256 257 // **** "Random" Menu (visible when not logged in) ******** 258 function bp_adminbar_random_menu() { 259 global $bp; ?> 260 261 <li class="align-right" id="bp-adminbar-visitrandom-menu"> 262 <a href="#"><?php _e( 'Visit', 'buddypress' ) ?></a> 263 <ul class="random-list"> 264 <li><a href="<?php echo $bp->root_domain . '/' . BP_MEMBERS_SLUG . '/?random-member' ?>"><?php _e( 'Random Member', 'buddypress' ) ?></a></li> 265 266 <?php if ( bp_is_active( 'groups' ) ) : ?> 267 268 <li class="alt"><a href="<?php echo $bp->root_domain . '/' . $bp->groups->slug . '/?random-group' ?>"><?php _e( 'Random Group', 'buddypress' ) ?></a></li> 269 270 <?php endif; ?> 271 272 <?php if ( bp_is_active( 'blogs' ) && is_multisite() ) : ?> 273 274 <li><a href="<?php echo $bp->root_domain . '/' . $bp->blogs->slug . '/?random-blog' ?>"><?php _e( 'Random Blog', 'buddypress' ) ?></a></li> 275 276 <?php endif; ?> 277 278 <?php do_action( 'bp_adminbar_random_menu' ) ?> 279 280 </ul> 281 </li> 282 283 <?php 284 } 285 286 function bp_core_load_admin_bar() { 287 global $wp_version; 288 289 if ( defined( 'BP_USE_WP_ADMIN_BAR' ) && BP_USE_WP_ADMIN_BAR && $wp_version >= 3.1 ) { 290 // TODO: Add BP support to WP admin bar 291 return; 292 } elseif ( !defined( 'BP_DISABLE_ADMIN_BAR' ) || !BP_DISABLE_ADMIN_BAR ) { 293 // Keep the WP admin bar from loading 294 show_admin_bar( false ); 295 296 // Actions used to build the BP admin bar 297 add_action( 'bp_adminbar_logo', 'bp_adminbar_logo' ); 298 add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 ); 299 add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 ); 300 add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6 ); 301 add_action( 'bp_adminbar_menus', 'bp_adminbar_thisblog_menu', 6 ); 302 add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 ); 303 add_action( 'bp_adminbar_menus', 'bp_adminbar_authors_menu', 12 ); 304 add_action( 'bp_adminbar_menus', 'bp_adminbar_random_menu', 100 ); 305 306 // Actions used to append BP admin bar to footer 307 add_action( 'wp_footer', 'bp_core_admin_bar', 8 ); 308 add_action( 'admin_footer', 'bp_core_admin_bar' ); 309 } 310 } 3 /** 4 * Reserved for WordPress admin bar functions 5 */ 311 6 312 7 ?>
Note: See TracChangeset
for help on using the changeset viewer.