Skip to:
Content

BuddyPress.org

Opened 2 years ago

Closed 23 months ago

#7573 closed enhancement (fixed)

BP_Group_Member_Query should support multiple group IDs

Reported by: r-a-y Owned by: r-a-y
Milestone: 3.0 Priority: normal
Severity: normal Version: 1.8
Component: Groups Keywords: needs-patch commit
Cc:

Description

Sometimes it is useful to query for members from multiple groups.

Currently, we cannot do this with BP_Group_Member_Query since it only supports one group ID.

Attached patch allows for passing multiple group IDs.

Attachments (2)

7573.01.patch (5.6 KB) - added by r-a-y 2 years ago.
7573.02.patch (5.4 KB) - added by r-a-y 2 years ago.

Download all attachments as: .zip

Change History (14)

@r-a-y
2 years ago

#1 @dcavins
2 years ago

Hi @r-a-y-

I think this is a great idea. In your attached patch, what would trigger the else condition:

else { 
    $group_ids_sql = $wpdb->prepare( "group_id = %d", $this->query_vars['group_id'] );  
}


Maybe if an empty array or empty string was passed into the function? I guess I'm wondering, is there a value that you could pass that would be stripped down to an empty array by wp_parse_id_list(), but would be useful to do an equals check on?

Thanks for setting me straight. :)

@r-a-y
2 years ago

#2 follow-up: @r-a-y
2 years ago

@dcavins - You're right. The else condition is not necessary.

I guess I was just being extra cautious, but wp_parse_id_list() should handle most empty instances and default to array( 0 ), so we should be safe to remove the else condition.

Last edited 2 years ago by r-a-y (previous) (diff)

#3 in reply to: ↑ 2 @dcavins
2 years ago

Replying to r-a-y:

@dcavins - You're right. The else condition is not necessary.

I guess I was just being extra cautious, but wp_parse_id_list() should handle most empty instances and default to array( 0 ), so we should be safe to remove the else condition.

Not so fast! :)

I think we need an else condition, because wp_parse_id_list( array() ) does return an empty array. But maybe the else condition should be explicitly not made to work, like group_id = 0 or something. I was just wondering, could there be a passed arg that would be useful? I can't think of one.

Thanks again for this good idea!

#4 @r-a-y
2 years ago

Well, if you're passing an empty array, then you're SOL :)

I suppose we could do something like this:

$group_ids = wp_parse_id_list( $this->query_vars['group_id'] ); 
$group_ids = ! empty( $group_ids ) ? $group_ids : array( 0 );

Feels a little unnecessary, but meh!

#5 @DJPaul
2 years ago

  • Keywords commit added
  • Milestone changed from Awaiting Review to 3.0

if someone passes a null-ish value to group_id and if we don't explicitly support that already, we do not need to protect against developer stupidity. This is our lowest-level query function for Groups Members queries, and any handholding like this should happen up the chain.

tl;dr 02 patch looks good

#6 @DJPaul
2 years ago

@r-a-y Are you still up for committing this to trunk?

#7 @DJPaul
2 years ago

  • Owner set to DJPaul
  • Status changed from new to assigned

Fair warning, I'm going to add this next week @r-a-y unless you say otherwise.

Last edited 2 years ago by DJPaul (previous) (diff)

#8 @DJPaul
2 years ago

  • Keywords needs-patch added; has-patch commit removed

This needs a bit more work, I don't think the else clause in the patch is ever going to be hit.

#9 @r-a-y
2 years ago

Second patch doesn't use the else condition.

#10 @DJPaul
23 months ago

  • Keywords commit added
  • Owner DJPaul deleted

Yeah I like it, get it in!

#11 @DJPaul
23 months ago

  • Owner set to r-a-y

#12 @djpaul
23 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 11792:

Groups: add support to query for members from multiple groups.

Fixes #7573

Props r-a-y, dcavins

Note: See TracTickets for help on using tickets.