Skip to:
Content
Pages
Categories
Search
Top
Bottom

Define autocomplete for specific roles in private messages


  • honoluluman
    Participant

    @honoluluman

    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 the define( 'BP_MESSAGES_AUTOCOMPLETE_ALL', true ); from here

    The 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_jsblock function?

    Thank you all in advance 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

  • honoluluman
    Participant

    @honoluluman

    Or maybe the opposite, just dont allow Subscribers in the result.


    honoluluman
    Participant

    @honoluluman

    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+admins

    it could be a function that makes all of those users friends with out the need of bp friends component?


    honoluluman
    Participant

    @honoluluman

    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Skip to toolbar