Last active
May 27, 2021 02:10
-
-
Save KaineLabs/44d87a638e885e397464e8f4b773ff3f to your computer and use it in GitHub Desktop.
Hide Private Profiles From Members Directory And Buddypress Widgets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Hide Private Profiles From Members Directory And Buddypress Widgets. | |
*/ | |
function yzc_exclude_private_users( $args ) { | |
if ( ! bp_is_active( 'friends' ) ) { | |
return $args; | |
} | |
//do not exclude in admin | |
if ( ( is_admin() && ! defined( 'DOING_AJAX' ) ) || bp_is_user_friend_requests() ) { | |
return $args; | |
} | |
$excluded = isset( $args['exclude'] )? $args['exclude'] : array(); | |
if( ! is_array( $excluded ) ) { | |
$excluded = explode(',', $excluded ); | |
} | |
$user_ids = youzify_get_private_user_profiles(); // enter user ids here | |
if ( ! empty( $user_ids ) && is_user_logged_in() ) { | |
foreach ( $user_ids as $key => $user_id ) { | |
if ( friends_check_friendship_status( bp_loggedin_user_id(), $user_id ) != 'not_friends' ) { | |
unset( $user_ids[ $key ] ); | |
} | |
} | |
} | |
$args['exclude'] = array_merge( $excluded, $user_ids ); | |
return $args; | |
} | |
add_filter( 'bp_after_has_members_parse_args', 'yzc_exclude_private_users' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment