• Hi,

    As the current plugin version, your code overrides the exclude argument of the members query. This is just a quick fix to operate on bpb-queries.php
    I’ve updated the function so it won’t override and check the argument type as it supports String and Array.

    /**
     * Adjust BP_User_Query
     * @since 1.0
     * @version 1.0
     */
    function bpb_adjust_user_query( &$data ) {
    	if ( !is_user_logged_in() ) return;
    
    	$_list = bpb_get_blocked_users( get_current_user_id() );
    	update_option( 'catch_query_users_query', $_list );
    
        if ( ! empty( $_list ) ) {
    		$list = implode( ',', $_list );
    
            if( empty( $data->query_vars_raw['exclude'] ) )
                $data->query_vars_raw['exclude'] = $_list;
            else if( is_array( $data->query_vars_raw['exclude'] ) )
                array_merge( $data->query_vars_raw['exclude'], $_list );
            else
                $data->query_vars_raw['exclude'] .= ',' . $list;
    
            if( empty( $data->query_vars['exclude'] ) )
                $data->query_vars['exclude'] = $_list;
            else if( is_array( $data->query_vars['exclude'] ) )
                array_merge( $data->query_vars['exclude'], $_list );
            else
                $data->query_var_raw['exclude'] .= ',' . $list;
    
    	}
    }

    https://www.ads-software.com/plugins/bp-you-are-blocked/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mathieuhays

    (@mathieuhays)

    Actually I’ve got a little error here. Forgot to apply the array merge to the query.

    /**
     * Adjust BP_User_Query
     * @since 1.0
     * @version 1.0
     */
    function bpb_adjust_user_query( &$data ) {
    	if ( !is_user_logged_in() ) return;
    
    	$_list = bpb_get_blocked_users( get_current_user_id() );
    	update_option( 'catch_query_users_query', $_list );
    
        if ( ! empty( $_list ) ) {
    		$list = implode( ',', $_list );
    
            if( empty( $data->query_vars_raw['exclude'] ) )
                $data->query_vars_raw['exclude'] = $_list;
            else if( is_array( $data->query_vars_raw['exclude'] ) )
                $data->query_vars_raw['exclude'] = array_merge( $data->query_vars_raw['exclude'], $_list );
            else
                $data->query_vars_raw['exclude'] .= ',' . $list;
    
            if( empty( $data->query_vars['exclude'] ) )
                $data->query_vars['exclude'] = $_list;
            else if( is_array( $data->query_vars['exclude'] ) )
                $data->query_vars['exclude'] = array_merge( $data->query_vars['exclude'], $_list );
            else
                $data->query_var_raw['exclude'] .= ',' . $list;
    
    	}
    }

    Thank you very much, Mathieu! This has been most helpful.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Override query arguments’ is closed to new replies.