Define autocomplete for specific roles in private messages
-
Hello ,
I am running a small blog site with mainly 3 roles on it . Subscriber, Contributor, Admin.
I don’t have enabled the friends bp component, so in order for a user to have autocomplete in private messages i am using thedefine( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true );from hereThe problem is that the query give all users as a result. Is there a way to allow only contributor+admins in the results? Maybe by
messages_autocomplete_init_jsblockfunction?Thank you all in advance 🙂
-
Or maybe the opposite, just dont allow Subscribers in the result.
I was also thinking that i could skip the use of
define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true );and since i just want to have in the autocomplete contributors+adminsit could be a function that makes all of those users friends with out the need of bp friends component?
So i managed to find the appropriate code in case someone also needs it:
define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true ); /** * Filter and remove subscribers and user's own mail from all BuddyPress auto complete box. * * @param array $args BP_User_Query args. * * @return array */ function buddydev_filter_buddypress_auto_complete_ids( $args ) { $user_ids = isset( $args['exclude'] ) ? $args['exclude'] : array(); if ( $user_ids && ! is_array( $user_ids ) ) { $user_ids = wp_parse_id_list( $user_ids ); } $excluded = get_users( array( 'role' => 'subscriber', 'fields' => 'ID' ) ); if ( is_user_logged_in() ) { array_push( $excluded, get_current_user_id() ); } $args['exclude'] = array_merge( $excluded, $user_ids ); return $args; } add_filter( 'bp_members_suggestions_query_args', 'buddydev_filter_buddypress_auto_complete_ids' );with this i can have excluded from autocomplete all subscribes by hooking to
bp_members_suggestions_query_args
- You must be logged in to reply to this topic.