Modificar la Admin Bar de Buddypress

/ / Programacion

Tener una franja de color negro en la cabecera de la página web no es una funcionalidad que hayamos pensado tener en nuestra página cuando la diseñamos, y desde que instalamos BuddyPress, esta función parece ser algo obligatorio para la navegación por toda la web; aunque he encontrado la manera de modificar la función bp_core_admin_bar que gestiona esta funcionalidad.

Para integrar la BuddyPress Admin Bar en mi diseño, he utilizado la siguiente función:

 if ( function_exists( 'bp_core_admin_bar' ) ) bp_core_admin_bar(); 

Y este es el código resultante de modificar el fichero bp-core-adminbar.php:

<?php

function bp_core_admin_bar() {
	global $bp, $wpdb, $current_blog, $doing_admin_bar;
	
	$doing_admin_bar = true;
	
	if ( (int)get_site_option( 'hide-loggedout-adminbar' ) && !is_user_logged_in() )
		return false;

	echo '';

	// **** Do bp-adminbar-menus Actions ********
	do_action( 'bp_adminbar_menus' );
}


// **** "Log In" and "Sign Up" links (Visible when not logged in) ********
function bp_adminbar_login_menu() {
	global $bp;

	if ( !is_user_logged_in() ) {	
		echo &#039;<li><a>root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp-&gt;root_domain ) . '"&gt;' . __( 'Log In', 'buddypress' ) . '</a></li>';
		
		// Show "Sign Up" link if registrations are allowed
		if ( get_site_option( 'registration' ) != 'none' ) {
			echo '<li><a href="' . bp_signup_page(false) . '">' . __( 'Sign Up', 'buddypress' ) . '</a></li>';
		}
	}
}

// **** "My Account" Menu ******
function bp_adminbar_account_menu() {
	global $bp;

	if ( !$bp-&gt;bp_nav )
		return false;

	/* Sort the nav by key as the array has been put together in different locations */
	$bp-&gt;bp_nav = bp_core_sort_nav_items( $bp-&gt;bp_nav );
	
	if ( is_user_logged_in() ) {
		
		echo '<li><span class="dir">';
		echo __( 'My Account', 'buddypress' ) . '</span>';
		echo '<ul>';
	
		/* Loop through each navigation item */
		$counter = 0;
		foreach( $bp-&gt;bp_nav as $nav_item ) {
			$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
			
			echo '<li>';
			echo '<a href="' . $nav_item&#91;'link'&#93; . '" class="dir">' . $nav_item['name'] . '</a>';

			if ( is_array( $bp-&gt;bp_options_nav[$nav_item['css_id']] ) ) {
				echo '<ul>';
				$sub_counter = 0;
				foreach( $bp-&gt;bp_options_nav[$nav_item['css_id']] as $subnav_item ) {
					$alt = ( 0 == $sub_counter % 2 ) ? ' class="alt"' : '';
					echo '<li><a id="bp-admin-' . $subnav_item&#91;'css_id'&#93; . '" href="' . $subnav_item&#91;'link'&#93; . '">' . $subnav_item['name'] . '</a></li>';				
					$sub_counter++;
				}
				echo '</ul>';
			}
			echo '</li>';
			$counter++;
		}
	
		$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
		if ( function_exists('wp_logout_url') ) { 
			echo '<li class="divider"><a href="' . wp_logout_url(site_url()) . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';                   
		} else {  
			echo '<li class="divider"><a href="' . site_url() . '/wp-login.php?action=logout&amp;amp;amp;redirect_to=' . site_url() . '">' . __( 'Log Out', 'buddypress' ) . '</a></li>';
		}
 		echo '</ul>';
		echo '</li>';
	}
}

// return a string indicating user's role in that blog
function get_blog_role_for_user( $user, $blog ) {
	
	// If the user is a site admin, just display admin.
	if ( is_site_admin() ) 
		return __( 'Admin', 'buddypress');
	
	$roles = get_usermeta( $user, 'wp_' . $blog . '_capabilities' );

	if ( isset( $roles['subscriber'] ) )
		$role = __( 'Subscriber', 'buddypress' ); 
	elseif	( isset( $roles['contributor'] ) )
		$role = __( 'Contributor', 'buddypress' );
	elseif	( isset( $roles['author'] ) )
		$role = __( 'Author', 'buddypress' );
	elseif ( isset( $roles['editor'] ) )
		$role = __( 'Editor', 'buddypress' );
	elseif ( isset( $roles['administrator'] ) )
		$role = __( 'Admin', 'buddypress' );
	else
		return false;
	
	return $role;
}

// *** "My Blogs" Menu ********
function bp_adminbar_blogs_menu() {
	if ( is_user_logged_in() ) {
		global $bp; 
	
		if ( function_exists('bp_blogs_install') ) {
			
			if ( !$blogs = wp_cache_get( 'bp_blogs_of_user_' . $bp-&gt;loggedin_user-&gt;id, 'bp' ) ) {
				$blogs = get_blogs_of_user( $bp-&gt;loggedin_user-&gt;id );
				wp_cache_set( 'bp_blogs_of_user_' . $bp-&gt;loggedin_user-&gt;id, $blogs, 'bp' );
			}

			echo '<li><span class="dir">';
			_e( 'My Blogs', 'buddypress' );
			echo '</span>';
	
			echo '<ul>';			
			if ( is_array( $blogs )) {
		
				$counter = 0;
				foreach( $blogs as $blog ) {
					$role = get_blog_role_for_user( $bp-&gt;loggedin_user-&gt;id, $blog-&gt;userblog_id );

					$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';
					echo '<li>';
					echo '<a>siteurl . '" class="dir"&gt;' . $blog-&gt;blogname . ' (' . $role . ')</a>';
					if ( !( 'Subscriber' == $role ) ) { // then they have something to display on the flyout menu
						echo '<ul>';
						echo '<li class="alt"><a>siteurl  . '/wp-admin/"&gt;' . __('Dashboard', 'buddypress') . '</a></li>';
						echo '<li><a>siteurl  . '/wp-admin/post-new.php"&gt;' . __('New Post', 'buddypress') . '</a></li>';
						echo '<li class="alt"><a>siteurl  . '/wp-admin/edit.php"&gt;' . __('Manage Posts', 'buddypress') . '</a></li>';
						echo '<li><a>siteurl  . '/wp-admin/edit-comments.php"&gt;' . __('Manage Comments', 'buddypress') . '</a></li>';					
						if ( 'Admin' == $role ) {	
							echo '<li class="alt"><a>siteurl  . '/wp-admin/themes.php"&gt;' . __('Switch Theme', 'buddypress') . '</a></li>'; 
						}					
						echo '</ul>';					
					}
					echo '</li>';
					$counter++;
				}
			}
	
			$alt = ( 0 == $counter % 2 ) ? ' class="alt"' : '';

			echo '<li class="divider">';
			echo '<a>loggedin_user-&gt;domain . $bp-&gt;blogs-&gt;slug . '/create-a-blog"&gt;' . __('Create a Blog!', 'buddypress') . '</a>';
			echo '</li>';
	
			echo '</ul>';
			echo '</li>';
		}
	}
}	

// **** "Notifications" Menu *********
function bp_adminbar_notifications_menu() {	
	if ( is_user_logged_in() ) {
		global $bp;
		
		echo '<li><span class="dir">';
		_e( 'Notifications', 'buddypress' );
		if ( $notifications = bp_core_get_notifications_for_user( $bp-&gt;loggedin_user-&gt;id ) ) { ?&gt;
			<span></span>
		&lt;?php
		}
		
		echo &#039;</span>';
		echo '<ul>';
		
		if ( $notifications ) { ?&gt;
			
			&lt;?php for ( $i = 0; $i 
				
				<li></li>
				
			
		
			<li><a>domain ?&gt;"&gt;</a></li>
		&lt;?php
		}
		
		echo &#039;</ul>';
		echo '</li>';
	}
}
	

add_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 6 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_blogs_menu', 4 );
add_action( 'bp_adminbar_menus', 'bp_adminbar_notifications_menu', 8 );
?&gt;

Deja un comentario