BuddyPress Tuts


BUDDYPRESS HOOKS AND FILTERS FOR YOUR BP-CUSTOM.PHP

DISABLE BUDDYPRESS REGISTRATION PROCESS AND FALLBACK TO WORDPRESS

function my_disable_bp_registration() {
remove_action( 'bp_init', 'bp_core_wpsignup_redirect' );
remove_action( 'bp_screens', 'bp_core_screen_signup' );
}
add_action( 'bp_loaded', 'my_disable_bp_registration' );

function firmasite_redirect_bp_signup_page($page ){
return bp_get_root_domain() . '/wp-login.php?action=register';
}
add_filter( 'bp_get_signup_page', "firmasite_redirect_bp_signup_page");

CHANGE BUDDYPRESS SITEWIDE ACTIVITY PAGE TITLE

function change_activity_title( $title ) {
if ( $title == __( 'Site-Wide Activity', 'ActiveTitle' ) ) {
$title = __( 'MySiteName Community', 'ActiveTitle' );
}
return $title;
}
add_filter( 'bp_get_directory_title', 'change_activity_title', 999 );

CHANGE BUDDYPRESS MEMBERS PAGE TITLE

function change_member_title( $title ) {
if ( $title == __( 'Members', 'MembersTitle' ) ) {
$title = __( 'MySiteName Members', 'MembersTitle' );
}
return $title;
}
add_filter( 'bp_get_directory_title', 'change_member_title', 999 );

ONLY SHOW FRIENDS STREAM IN ACTIVITY

if( !function_exists('only_show_friend_in_activity') ):
function my_is_atme_check( $content ) {
global $bp;
if ( !is_user_logged_in() )
return false;
if (!$content)
return false;
$pattern = '/[@]+([A-Za-z0-9-_]+)/';
preg_match_all( $pattern, $content, $usernames );
/* Make sure there's only one instance of each username */
if ( !$usernames = array_unique( $usernames[1] ) )
return false;
if ( in_array( bp_core_get_username( $bp->loggedin_user->id ), $usernames ) )
return true;
return false;
}
function my_is_friend_check( $friend_id = false) {
global $bp;
if ( !is_user_logged_in() )
return false;
if ( is_site_admin() )
return true;
if ( !$friend_id ) {
$potential_friend_id = $bp->displayed_user->id;
} else {
$potential_friend_id = $friend_id;
}
if ( $bp->loggedin_user->id == $potential_friend_id )
return false;
if ( friends_check_friendship_status($bp->loggedin_user->id, $potential_friend_id) == 'is_friend' )
return true;
return false;
}
function my_is_follower_check( $friend_id = false) {
global $bp;

if ( !is_user_logged_in() )
return false;

if ( is_site_admin() )
return true;

if ( !$friend_id ) {
$potential_friend_id = $bp->displayed_user->id;
} else {
$potential_friend_id = $friend_id;
}

if ( $bp->loggedin_user->id == $potential_friend_id )
return false;

if ( bp_follow_is_following( array( 'leader_id' => $potential_friend_id, 'follower_id' => $bp->loggedin_user->id ) ) )
return true;
}
function only_show_friend_in_activity( $a, $activities ) {
global $bp;
//if admin we want to know
if ( is_site_admin() )
return $activities;
foreach ( $activities->activities as $key => $activity ) {
/* if member of a group - we want the activity even if nonfriend */
if ( $activity->user_id != $bp->loggedin_user->id && $activity->component != 'groups' && $activity->component != 'blogs' && $activity->user_id != 0 && !my_is_friend_check($activity->user_id) && !my_is_follower_check($activity->user_id) && !my_is_atme_check($activity->content) ) {
unset( $activities->activities[$key] );
$activities->activity_count = $activities->activity_count-1;
$activities->total_activity_count = $activities->total_activity_count-1;
$activities->pag_num = $activities->pag_num -1;
}
}
/* Renumber the array keys to account for missing items */
$activities_new = array_values( $activities->activities );
$activities->activities = $activities_new;
return $activities;
}
add_action( 'bp_has_activities', 'only_show_friend_in_activity', 10, 2 );
endif;

CHECK IF MEMBER IS FRIEND

function bp_displayed_user_is_friend() {
global $bp;
if ( bp_is_profile_component() || bp_is_member() ) {
if ( ('is_friend' != BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $bp->displayed_user->id )) && (bp_loggedin_user_id() != bp_displayed_user_id()) )
if ( !is_super_admin( bp_loggedin_user_id() ) )
return true;
}
}

REMOVE FRIENDS BUTTON FROM NON-FRIENDS MEMBER

function custom_hide_friends_if_not_self(){
if(bp_is_my_profile()|| is_super_admin())
return ;
bp_core_remove_nav_item('friends');
}
add_action('bp_friends_setup_nav',
'custom_hide_friends_if_not_self');

ADD TRASH GLYPH-ICON TO DELETE LINK

function change_delete_text( $link ) {
$trash = ' Delete';
$link = str_replace("Delete", $trash, $link);
return $link;
}
add_filter( 'bp_get_activity_delete_link', 'change_delete_text', 1, 1 );

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.