Opened 10 years ago
Last modified 4 weeks ago
#37578 new enhancement
Dashboard Recent Activity widget - new filters to manipulate output
| Reported by: | Jonnyauk | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Administration | Version: | 4.6 |
| Severity: | normal | Keywords: | has-patch good-first-bug has-test-info |
| Cc: | Focuses: |
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 (15)
This ticket was mentioned in Slack in #core by peterwilsoncc. View the logs.
5 years ago
#3
@
22 months ago
- Focuses ui administration removed
- Keywords changes-requested good-first-bug added
- Milestone → 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.
@
16 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
@
16 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
@
15 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
@
15 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.
15 months ago
#9
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/37578
#10
@
6 weeks ago
- Keywords has-test-info added
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/9026
Environment
- WordPress: 7.1-beta3 (trunk, c213aec5a6)
- PHP: 8.3.30
- Server: Apache
- Database: MySQL 8.0.40
- OS: Fedora Linux (Docker)
- Browser: n/a (verified server-side via WP-CLI)
- Theme: Twenty Twenty-Five 1.5
- MU Plugins: none
- Plugins: none
Steps taken
- Registered a callback on
dashboard_recent_posts_query_argswithaccepted_args = 2, logging the second parameter. - Triggered both calls made by
wp_dashboard_site_activity()(statusfuture/ idfuture-postsand statuspublish/ idpublished-posts) viawp eval-file. - Without the patch, the callback receives no second argument.
- ✅ Patch is solving the problem: with the PR applied, the callback receives
'future-posts'and'published-posts'respectively, so the two Activity widget queries can now be distinguished.
Expected result
- The existing
dashboard_recent_posts_query_argsfilter receives the widget id as a second parameter, as suggested by @desrosj, instead of introducing new filters.
Additional Notes
- The PR is based on 6.9-alpha but cherry-picks cleanly onto current trunk (7.1-beta3) and works there as well.
- The
@since 6.9.0annotation needs to be bumped to the next release open for enhancements.
Support Content
<?php require_once ABSPATH . 'wp-admin/includes/dashboard.php'; add_filter( 'dashboard_recent_posts_query_args', function ( $query_args, ...$extra ) { printf( "Filter received 2nd param: %s\n", $extra ? var_export( $extra[0], true ) : '(none)' ); return $query_args; }, 10, 2 ); ob_start(); wp_dashboard_recent_posts( array( 'max' => 5, 'status' => 'future', 'order' => 'ASC', 'title' => 'Publishing Soon', 'id' => 'future-posts' ) ); wp_dashboard_recent_posts( array( 'max' => 5, 'status' => 'puitle' => 'Recently Published', 'id' => 'published-posts' ) ); ob_end_clean();
This ticket was mentioned in PR #12960 on WordPress/wordpress-develop by @welcher.
4 weeks ago
#11
Opened from the WordPress Contributor Toolkit.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
New filters for Dashboard Recent Activity widget future and recent posts.