Opened 9 years ago
Last modified 18 months ago
#17025 new enhancement
wp_list_authors() is not filterable
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | |
Component: | Query | Keywords: | has-patch dev-feedback needs-refresh |
Focuses: | Cc: |
Description
The template function wp_list_authors() is not filterable. Plugins may use existing WP_Query hooks to filter some authors' posts out of the result set, making the unfiltered authors list invalid.
The corresponding patch adds query filter 'list_authors_query'
Attachments (9)
Change History (36)
#2
@
9 years ago
- Summary changed from add hook for wp_list_authors() to wp_list_authors() is not filterable
#5
@
7 years ago
- Keywords commit added; needs-docs removed
17025.2.diff adds a docblock for the list_authors_query
filter hook.
#6
@
7 years ago
I would prefer to not add a filter that directly operates on SQL. This is not very flexible or fun.
Can we instead filter A) $authors, and/or B) $author_count?
Also: Unless I am reading it wrong, this function also appears to be very, unnecessarily heavy. By only asking for 'ids' from get_users(), none of the users are getting cached, which means each individual call to get_usermeta() is triggering a new query.
It would make more sense to run the raw query first, then fetch only those user objects (see also cache_users(); get_users() can also do this), unless $hide_empty is false, in which case you still need to fetch all objects as we're doing now.
#8
@
7 years ago
- Keywords needs-refresh added
see @nacin's comment - needs alternate filter approach
#9
@
7 years ago
- Keywords dev-feedback added; needs-refresh removed
Would something like 17025.3.diff work better?
#11
@
7 years ago
This request was part of a handful which I tossed out a couple years ago with an overall goal of allowing records to be filtered out of or into the result set. Filters applied in WP_Query and elsewhere make it possible to elevate the logged user to (or demote them from) author capabilities contextually based on criteria which WP core need not be aware of nor formally support. But some of the corresponding "user assignment" UI does not permit corresponding filtering.
wp_list_authors() is low-priority to me since it's not called by core. But inevitably some plugins and themes use it in a way that doesn't mesh with per-user inclusion/exclusion I do with WP_Query filters. Then I'll have to filter every query and use strpos() and preg_match() to determine if it is the wp_list_authors() query. Now that's not fun. So basically, the significance of this ticket is in setting a precedent for whether the API fully supports external modification of content and user queries, or whether it presumes to anticipate and regulate all implementations.
In this case, caching the "all objects" results of the default query is not sufficient since it is built on query clauses that do not account for post types other than 'post' nor visibility statuses other than 'private':
"SELECT DISTINCT post_author, COUNT(ID) AS count FROM $wpdb->posts WHERE post_type = 'post' AND " . get_private_posts_cap_sql( 'post' )
The 'pub_priv_sql_capability' filter in function get_posts_by_author_sql() would at least allow a different post type for the current user capability check, but even that is up for deprecation according to the inline comment. And then you still have this:
$sql .= " OR post_status = 'private'";
So a filter on the results would be better than nothing, but it has the disadvantage of forcing an additional query, which makes plugins look bad ;)
#13
@
7 years ago
- Keywords 3.8-early added
- Milestone changed from 3.7 to Future Release
There's a lot going on here. Moving to 3.8.
#14
@
6 years ago
- Keywords needs-refresh added; dev-feedback removed
- Milestone changed from Future Release to 4.0
@DrewAPicture probably wants to update his patch/docs
This ticket was mentioned in IRC in #wordpress-dev by helen. View the logs.
6 years ago
#17
@
6 years ago
- Keywords 4.1-early added; 3.8-early removed
- Milestone changed from 4.0 to Future Release
Let's work on this in 4.1. 17025.6.diff refreshes the patch at r29015. Unit tests might also need an update for $hide_empty
.
#19
@
4 years ago
- Keywords dev-feedback added; needs-refresh removed
Patch refreshed, updated code and splitted in two patch.
17025.7.diff contain the new filter and 17025.optimizeforeach.diff contain the optimization of the foreach of the original patch.
#20
@
4 years ago
@DrewAPicture and @boonebgorges Can you two take a look? Would love to know your thoughts.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
#24
@
2 years ago
- Keywords needs-refresh added
- Milestone changed from 5.0 to Future Release
17025.optimizeforeach.diff needs some coding standards: spacing, empty lines should not have spaces, etc.
query filter for wp_list_authors()