Created
November 19, 2022 19:58
-
-
Save contemplate/1657a9baacbb7f273ec181e9efbae724 to your computer and use it in GitHub Desktop.
Buddypress / Buddyboss exclude users from messaging & mention
This file contains hidden or 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
//array of restricted user IDs | |
function bp_restricted_user_list(){ | |
// These user's won't be able to receive the messages. | |
$restricted_user_ids = array( 102, 115, 220, 225 ); //Change these values to valid user IDs | |
return $restricted_user_ids; | |
} | |
/** | |
* Is user restricted from receiving message. | |
* | |
* @param int $user_id user id. | |
* | |
* @return bool | |
*/ | |
function buddydev_is_user_restricted( $user_id ) { | |
$restricted_user_ids = bp_restricted_user_list(); | |
return in_array( $user_id, $restricted_user_ids ); | |
} | |
/** | |
* Hide public message button if needed. | |
* | |
* @param array $r button args. | |
* | |
* @return array | |
*/ | |
function buddydev_hide_public_button( $r ) { | |
if ( bp_is_user() && buddydev_is_user_restricted( bp_displayed_user_id() ) ) { | |
$r = array(); | |
} | |
return $r; | |
} | |
add_filter( 'bp_get_send_public_message_button', 'buddydev_hide_public_button' ); | |
/** | |
* Hide private message button if needed. | |
* | |
* @param array $r args. | |
* | |
* @return array | |
*/ | |
function buddydev_hide_private_button( $r ) { | |
if ( bp_is_user() && buddydev_is_user_restricted( bp_displayed_user_id() ) ) { | |
$r = array(); | |
} | |
return $r; | |
} | |
add_filter( 'bp_get_send_message_button_args', 'buddydev_hide_private_button' ); | |
/*---- Exclude From Mention search -------*/ | |
function exclude_from_buddypress_auto_complete( $args ) { | |
$args['exclude'] = bp_restricted_user_list(); | |
return $args; | |
} | |
add_filter( 'bp_members_suggestions_query_args', 'exclude_from_buddypress_auto_complete' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment