5 BuddyPress Tips and Tricks
BuddyPress is one of the most downloaded and most popular social plugins in WordPress repository. It is believed that more than 100,000 sites in today’s world operate with BuddyPress Site. It is a powerful plugin that transforms the site fully into social networking platform. And of course, it is a free plugin where you can customize, edit , and reuse on your WordPress site. In this article, I am going to write 5 buddyPress tips and tricks which you can use on your website. Make sure you have installed BuddyPress Plugin to work correctly.
5 BuddyPress Tips and Tricks
1. Disable Cover Image for BuddyPress Group and User Profiles
If you enable Group to be displayed on your site from your BuddyPress checkbox setting, you can create your own group. And inside that group, you can create your Forums and Topics. However, you may want to hide Cover Image for BuddyPress Group and User Profiles. A simple 2-line code will do this for you. Add the following code
into your functions.php
or bp-custom.php
file.
add_filter( 'bp_is_groups_cover_image_active', '__return_false' ); add_filter( 'bp_is_profile_cover_image_active', '__return_false' );
The first code will disable BuddyPress Group cover image and the second line of code will disable User’s Profile Cover Image. You can also disable the Cover Images from Dashboard menu. Go to BuddyPress->Settings screen, you’ll find your preferred settings. There is no need to use code.
2. Redirect Author Archive Page to BuddyPress User Profile
If someone tries to access the Author Archive Page, but you want them to redirect to User’s Profile Page instead, then add the following code in your functions.php
file of the active theme.
add_action( 'template_redirect', pp_author_redirect_to_profile); function pp_author_redirect_to_profile() { if ( is_author() && function_exists( 'bp_core_redirect' ) ) { $author_id = get_queried_object_id(); bp_core_redirect( bp_core_get_user_domain( $author_id ) ); } }
3. Redirect Users to their Profile Page after login
If you want your subscribers to be redirected to their Profile on your BuddyPress site, place the below code in your bp-custom.php or functions.php
function bp_redirect_to_profile(){ global $bp_unfiltered_uri; $bp_my_front_page = 'activity'; if ( !is_user_logged_in() && ( $bp_unfiltered_uri[0] != $bp_my_front_page ) ) bp_core_redirect( get_option('home') ); elseif( is_user_logged_in() && ( $bp_unfiltered_uri[0] == $bp_my_front_page ) ) bp_core_redirect( get_option('home') . '/members/' . bp_core_get_username( bp_loggedin_user_id() ) . '/profile' ); } add_action( 'wp', 'bp_redirect_to_profile', 3 );
Source: BuddyPress
4. Displaying User role on BuddyPress Profile
The user may get confused what their role on the website. For example, if a person has two user accounts and he has different roles, he may wish to know his roles on the site. We can do this by displaying the user’s role on User’s Profile. Add the following code in your bp-custom.php or child theme’s functions.php file.
add_action( 'bp_before_member_header_meta', 'pp_show_role_on_profile' ); function pp_show_role_on_profile() { global $wp_roles; $user_id = bp_displayed_user_id(); $user = get_userdata($user_id); $roles = $user->roles; if ( !$roles ) return; if ( !isset( $wp_roles ) ) $wp_roles = new WP_Roles(); $named_roles = array(); foreach ( $roles as $role ) { $named_roles [] = $wp_roles->role_names[$role]; } if ( $named_roles ) echo '<span class="user-role activity">' . join(', ', $named_roles) . '</span>'; }
Source: Buddydev
Here’s the Screenshot:
5. Automatically Add New Users to a BuddyPress Group
Have you ever wondered if you could add newly-registered subscriber automatically to specified or all BuddyPress Group? Yes, one of my clients wanted this feature and this was something that got me her attention. I researched through the BuddyPress Documentation and I found a simple little hack which successfully did what I wanted. Add the following lines of code in your bp-custom.php file or functions.php
function pp_automatic_group_membership( $user_id ) { if( !$user_id ) return false; groups_accept_invite( $user_id, <# group ID #> ); } add_action( 'bp_core_activated_user', 'pp_automatic_group_membership' );
And these are some of my favorite BuddyPress Tricks and Hacks. Feel free to comment below if you have any question or suggestion.