Skip to:
Content

BuddyPress.org

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#5823 closed defect (bug) (no action required)

bp_ajax_querystring('members') does not work with exclude

Reported by: weirdpress Owned by:
Milestone: Priority: normal
Severity: normal Version: 1.2
Component: Members Keywords: reporter-feedback
Cc:

Description

hiya :)

i am running into issues using the bp_ajax_querystring filter.

I omitted some of the if conditions and did not add the function that concatenates the user ids i get from the database since they are not part of the problem,
the issue arises as soon as i replace the $args['include'] with $args['exclude'], at which point the members list includes all members again.
Since i have way more members to include (around 1700) than i have to exclude (around 300) i would love to turn this around.

tracked this down through:
bp-members-template.php: bp_has_members -> BP_Core_Members_Template
bp-members-functions.php: bp_core_get_users
bp-core-classes.php: BP_User_Query

and the problem shows itself here, line 333 of bp-core-classes.php:

    print_r($include);
    $include     = false !== $include ? wp_parse_id_list( $include ) : array();
    $include_ids = $this->get_include_ids( $include );
    if ( ! empty( $include_ids ) ) {
        $include_ids    = implode( ',', wp_parse_id_list( $include_ids ) );
        $sql['where'][] = "u.{$this->uid_name} IN ({$include_ids})";
    }

    // 'exclude' - User ids to exclude from the results
    print_r($exclude);
    if ( false !== $exclude ) {
        $exclude_ids    = implode( ',', wp_parse_id_list( $exclude ) );
        $sql['where'][] = "u.{$this->uid_name} NOT IN ({$exclude_ids})";
    }

if i pass include to the args, then i get all the include ids in that print_r,
if i pass exclude i only get one id.

i will definitely track this down further through the files referenced above,
but right now i don't have the time so i figured i would throw this into trac.


private function __construct() {
    add_filter( 'bp_ajax_querystring', array($this, 'bp_include_users'), 20, 2);
}

public function bp_include_users( $qs=false, $object=false ) {
    // hide for members page OR if searching for friends
    if($object !== 'members' || ! empty($args['user_id']))
        return $qs;

    //list of users to exclude
    $x_users = '1,2,3,4,5,6';
    //get the existing args if there are any
    $args = wp_parse_args($qs);

    //including works
    $args['include'] = $x_users;

    //excluding does not
    //$args['exclude'] = $x_users;

    return build_query($args);
}

thanks for everything, buddypress is awesome :)
greetings
j.

Change History (2)

#1 @r-a-y
7 years ago

  • Keywords reporter-feedback added
  • Version changed from 2.0 to 1.2

Are you using any other plugins that run on the 'bp_ajax_querystring' filter?

I would recommend bumping your priority from 20 to something larger like 99 and then test your 'exclude' parameter and see if anything shows up.

#2 @weirdpress
7 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

We are doing quite a big customization job here, it may be that there is one plugin that hooks into the query as well, i will have a look at that,

grep -nHIrF -- bp_ajax_querystring
tells me that my plugin and buddypress are the only two places that use bp_ajax_querystring,
the one plugin that we use that is not produced in house might be the culprit though,
they are using bp_pre_user_query_construct instead of bp_ajax_querystring,
i guess thats the reason for this bug.

Thanks for the hint, r-a-y, i closed this for now and will reopen if needed.

Last edited 7 years ago by weirdpress (previous) (diff)
Note: See TracTickets for help on using tickets.