Opened 9 years ago
Last modified 5 months ago
#37578 new enhancement
Dashboard Recent Activity widget - new filters to manipulate output
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Future Release | Priority: | normal |
| Severity: | normal | Version: | 4.6 |
| Component: | Administration | Keywords: | has-patch good-first-bug |
| Focuses: | Cc: |
Description
It is currently not possible to manipulate the recent post activity dashboard widget. Output is built using wp_dashboard_recent_posts(). 2 filters could be introduced for the parameters for future and recent posts.
This would allow easy interaction with the parameters array, for instance increasing the amount of posts shown, changing order, post status, CSS ID etc - would definitely make it more useful!
I realise that there is a filter dashboard_recent_posts_query_args inside thewp_dashboard_recent_posts() function (used to build the queries, useful for switching post type etc), but there is currently no way to interact with the calls to this function.
Attachments (4)
Change History (13)
This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.
5 years ago
#3
@
12 months ago
- Focuses ui administration removed
- Keywords changes-requested good-first-bug added
- Milestone set to Future Release
Hi @Jonnyauk,
My apologies that this took so long to receive a response!
Instead of adding new filters, what if the $id passed to wp_dashboard_recent_posts() were also passed to the filter as an additional parameter? Then the preexisting dashboard_recent_posts_query_args filter could be used for this in any context by providing a bit more control.
@
6 months ago
Added a patch using the existing 'dashboard_recent_posts_query_args' filter with support for passing the $id to wp_dashboard_recent_posts() for better control.
#6
@
6 months ago
- Keywords needs-test-info added; needs-testing removed
@pmbaldha
For this filters, please provide an use-case for testing.
#7
follow-up:
↓ 8
@
6 months ago
@SirLouen
Usecases:
- If you want to show 10 posts instead of the default 5:
add_filter( 'dashboard_recent_posts_query_args', 'increase_dashboard_post_count', 10, 2 );
function increase_dashboard_post_count( $args, $id ) {
$args['max'] = 10;
return $args;
}
2. Show Only Posts from a Specific Category in "Recently Published"
If your site has multiple categories and you want the widget to only show posts from the "Announcements" category:
add_filter( 'dashboard_recent_posts_query_args', 'dashboard_recent_posts_announcements_only', 10, 2 );
function dashboard_recent_posts_announcements_only( $args, $id ) {
if ( 'published-posts' === $id ) {
$args['cat'] = get_cat_ID( 'Announcements' );
}
return $args;
}
#8
in reply to:
↑ 7
@
6 months ago
- Keywords needs-refresh added; needs-test-info removed
Replying to pmbaldha:
Usecases:
Did you check JD comment on a possible alternative?
Adding new hooks is the worst thing possible when there is an alternative. They should always be the last resort.
This ticket was mentioned in PR #9026 on WordPress/wordpress-develop by @sukhendu2002.
5 months ago
#9
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/37578
New filters for Dashboard Recent Activity widget future and recent posts.