Opened 3 years ago
Closed 3 years ago
#8488 closed enhancement (fixed)
Support date queries for members, groups and sites
Reported by: | r-a-y | Owned by: | imath |
---|---|---|---|
Milestone: | 10.0.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Core | Keywords: | has-patch dev-reviewed |
Cc: |
Description
We already support date queries for the activity and 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:
- 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.
- 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
inbp_has_members()
is eitheractive
,newest
,random
oronline
. - For groups, we will only allow date queries if the
$type
inbp_has_groups()
is eitheractive
ornewest
. - For sites, we will only allow date queries if the
$type
inbp_has_blogs()
is eitheractive
ornewest
.
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.
Attachments (2)
Change History (7)
#2
@
3 years ago
- Milestone changed from 9.0.0 to Up Next
Hi @r-a-y
I'm really sorry I couldn't find the time to test your patch. We've decided 9.0.0 would be a short development cycle focused on Widget Blocks (as 5.8 is introducing new features about this area).
Let's have date queries ready for 10.0.0 !!
#3
@
3 years ago
- Milestone changed from Up Next to 10.0.0
Let's try to progress on it during 10.0.0 dev cycle.
#4
@
3 years ago
- Keywords dev-reviewed added
Hi @r-a-y
I just had a deeper look at the patch. I've run the unit tests successfully and edited some parts (minor edits to improve WP Coding Standards compliance + updated @since
to 10.0.0
).
I seems promising, if you're confident with the patch, don't hesitate to commit it 👍
Hi @r-a-y
I haven't tested it yet, but I believe it's a great idea. Thanks for working on it.