[buddypress-trac] [BuddyPress Trac] #8488: Support date queries for members, groups and sites

buddypress-trac noreply at wordpress.org
Tue Jun 15 00:17:17 UTC 2021


#8488: Support date queries for members, groups and sites
-------------------------+-----------------------------
 Reporter:  r-a-y        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Core         |    Version:
 Severity:  normal       |   Keywords:
-------------------------+-----------------------------
 We already support date queries for the [/ticket/5803 activity] and
 [/ticket/6257 notification] loops. Let's introduce date queries for the
 rest of our component loops -- members, groups and sites!

 As I began adding date query to these components, there are two things I
 wanted to address:


 1. For our existing date query integrations, we manually strip the initial
 'AND' SQL clause created by `WP_Date_Query`

 See:
 -
 https://github.com/buddypress/buddypress/blob/e724c6a797eae15d374720fbeecec3277baf2f3b/src
 /bp-activity/classes/class-bp-activity-activity.php#L1029
 -
 https://github.com/buddypress/buddypress/blob/e724c6a797eae15d374720fbeecec3277baf2f3b/src
 /bp-notifications/classes/class-bp-notifications-notification.php#L826

 This is a little messy. `WP_Date_Query` has seen some improvements to
 abstract some of this behavior.

 So in the attached patch, I've modified our `BP_Date_Query` class so we
 can choose to prepend the `AND` SQL operator if we wanted to. See
 `BP_Date_Query::__construct()` for the new `$prepend_and` function
 argument, which I've defaulted to `false`. The only time we set this to
 `true` is for the sites component, which uses a messy SQL clause.

 I've also created a new utility static method,
 `BP_Date_Query::get_where_sql()`. This is to be used where we want to
 initialize a new date query. See the new date query additions to members,
 groups and sites.

 2. Blogs component needs some love to use array as a function argument

 Similar to what we did with the members component in #3797, I wanted to do
 the same thing for the blogs loop. So that's what I did here.

 I've also cleaned up the PHPDoc as well.

 ----

 Now that we've gotten that out of the way, let me explain how date queries
 will work in each of the components:

 - For members, we will only allow date queries if the `$type` in
 `bp_has_members()` is either `active`, `newest`, `random` or `online`.
 - For groups, we will only allow date queries if the `$type` in
 `bp_has_groups()` is either `active` or `newest`.
 - For sites, we will only allow date queries if the `$type` in
 `bp_has_blogs()` is either `active` or `newest`.

 This is done because these types use a date to compare against. The other
 types like `alphabetical` or `popular` do not make much sense to use a
 date query with.

 I've also added some unit tests for each component as well. Let me know
 what you think.

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/8488>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list