How to customize the user navigation bar and user profile tabs
-
Hello. I’m still a newbie to buddypress and would like to find out if anyone can help. I’m using WPMU 2.9.2, Buddypress 1.2.3, and the BuddyPress Widget Theme 1.2.1.
I’m creating a social network of providers and subscribers where subscribers can gather information provided via the main blog (providers post the information), as well as ask questions in the forums, etc. There is no other blog but the main one.
Therefore, I’d like to remove the ‘Blogs’ tab in the user navigation bar as well as the ‘Blogs’ tab in the user profile.
Can anyone suggest how I may be able to accomplish this?
I would also like to remove the ‘My Blog’s tab from the admin bar of subscribers and the ‘Blogs’ item from the ‘My Account’ tab in the admin bar of all users. I found a plugin called ‘admin bar mods’ that will seem to allow these types of modifications to the admin bar but it doesn’t look like that capability will be available until the next release. I found an article on how to modify the admin bar (http://codex.buddypress.org/how-to-guides/modifying-the-buddypress-admin-bar/) and am planning on going that route. If anyone has any other suggestions on the best way for me to go about this, please let me know.
My main question however is on how to modify the user nav and user profile tabs, as I have not been able to find any posts that answer this issue. Thank you.
-
Do you need user blogs?
If not, disable the blog tracking component.
Login to the WP backend, navigate to “BuddyPress > Component setup”. Disable blog tracking.
I only need 1 blog – the main one. I disabled the blog tracking component and that worked, thank you. It disabled all the ‘Blog’ tabs.
The only thing I need now is a way for the providers (those who can post to the main blog) a way to create/edit posts. Other than adding a meta widget to the sidebar, is there a better way I can provide authors, contributors, etc. a way to get to the dashboard so they can post/edit blog entries?
Open up your functions.php file in your child theme and create a function that spits out the links you want. Wrap your links with code to check if the user has the correct capabilities. Hook that function into “bp_sidebar_me” and those links will only show up when the user is logged in and will be in the sidebar under their simple profile.
Thank you. After searching the forums for how to check the current user’s role, I added below to function.php and it’s working. Since I’m new to this, I’m very open to suggestions if there’s a better way to write this function.
function my_alter_bp_sidebar_login(){
global $bp;
$user = new WP_User( $bp->loggedin_user->id );
if ( !empty( $user->roles ) && is_array( $user->roles ) ) {
foreach ( $user->roles as $role )
if ($role != ‘subscriber’) {
echo ‘root_domain . ‘/wp-admin/”>Dashboard<p/>’;
}
}
}
add_action(‘bp_before_sidebar_me’,’my_alter_bp_sidebar_login’,1);
It might be cleaner to use the current_user_can function to test. Check out the Roles info on the WP Codex, specifically the table (it makes it easy to see what roles apply):
https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
To make it a little cleaner you could do the following:
function my_alter_bp_sidebar_login () {
if( current_user_can( 'edit_posts' ) ) {
printf( '<a href="%s" title="Dashboard">Dashboard</a>',(get_bloginfo( 'wpurl' ).'/wp-admin/') );
}
}This would show the link for any user who can “edit_posts” which is basically anyone other than Subscriber.
Thank you much for the better, cleaner, shorter code and the link! I’m learning every day!
Hello again. I posted this question on a new topic, no responses. I’ll try asking the question here since I have received responses on this thread. Thank you. Here goes:
I added the code below in wp-content/plugins/buddypress/bp-themes/bp-default/members/members-loop.php, to display additional profile fields in the member directory and to display the member’s role (either ‘Subscriber’ or ‘Provider’). In the code below, I specifically checked for the user’s role to determine whether I need to display ‘Subscriber’ or ‘Provider’.
Questions:
– is there a way to check for the capability instead – i.e., if the user can ‘edit posts’ then I will display ‘Subscriber’, otherwise I will display ‘Provider’? If so, can you please let me know how to do that as I have not been able to figure it out.
– is there a way to display a newline so that ‘Subscriber’ or ‘Provider’ will display on the next line, below the member’s title and company name. I tried to echo “n” but it’s not outputting a newline and I have no idea why.
Thank you for the help.
<?php
/***
* If you want to show specific profile fields here you can,
* but it’ll add an extra query for each member in the loop
* (only one regadless of the number of fields you show):
*
* bp_member_profile_data( ‘field=the field name’ );
*/
if( bp_get_member_profile_data ( ‘field=Title’ ) )
echo bp_member_profile_data( ‘field=Title’ ), ‘ (‘, bp_member_profile_data( ‘field=Company’ ), ‘)’, ‘ – ‘;
$user = new WP_User( bp_get_member_user_id() );
if ( $user->roles[0] == ‘subscriber’ )
echo ‘Subscriber’;
else
echo ‘Provider’;
?>
Hello again. I posted this question on a new topic, no responses. I’ll try asking the question here since I have received responses on this thread. Thank you. Here goes:
I added the code below in wp-content/plugins/buddypress/bp-themes/bp-default/members/members-loop.php, to display additional profile fields in the member directory and to display the member’s role (either ‘Subscriber’ or ‘Provider’). In the code below, I specifically checked for the user’s role to determine whether I need to display ‘Subscriber’ or ‘Provider’.
Questions:
– is there a way to check for the capability instead – i.e., if the user can ‘edit posts’ then I will display ‘Subscriber’, otherwise I will display ‘Provider’? If so, can you please let me know how to do that as I have not been able to figure it out.
– is there a way to display a newline so that ‘Subscriber’ or ‘Provider’ will display on the next line, below the member’s title and company name. I tried to echo “n” but it’s not outputting a newline and I have no idea why.
Thank you for the help.
<?php
/***
* If you want to show specific profile fields here you can,
* but it’ll add an extra query for each member in the loop
* (only one regadless of the number of fields you show):
*
* bp_member_profile_data( ‘field=the field name’ );
*/
if( bp_get_member_profile_data ( ‘field=Title’ ) )
echo bp_member_profile_data( ‘field=Title’ ), ‘ (‘, bp_member_profile_data( ‘field=Company’ ), ‘)’, ‘ – ‘;
$user = new WP_User( bp_get_member_user_id() );
if ( $user->roles[0] == ‘subscriber’ )
echo ‘Subscriber’;
else
echo ‘Provider’;
?>
how would you remove items from the menu without disabling the component? Still want to make use of blog tracking but don’t need the blogs menu item. If members are only allowed 1 blog there is really no need for this in the menu.
@nahummadrid
To remove the blog component from the top menu bar I think you can do:
remove_action(‘bp_adminbar_menus’, ‘bp_adminbar_blogs_menu’, 6);@techguy thanks but i did try that and it only removes from adminbar not the member profile nav bar. what i’ve ended up doing that works i guess is to use css.
#blogs-personal-li {
display:none;
}How about renaming the blog name to ‘ Welcome, [USER] ‘
Is this just a case of replacing the action with a new action ??
- The topic ‘How to customize the user navigation bar and user profile tabs’ is closed to new replies.