From 877f26a5418626a7477e03e8b9692f64e960571b Mon Sep 17 00:00:00 2001 From: Ankit Parmar Date: Tue, 24 Nov 2026 11:59:09 +0530 Subject: [PATCH] Administration: Pass the container ID to `dashboard_recent_posts_query_args`. The Recent Activity dashboard widget builds two lists, "Publishing Soon" and "Recently Published", with `wp_dashboard_recent_posts()`. The existing `dashboard_recent_posts_query_args` filter runs for both and gave callbacks no way to tell them apart. Pass the container ID (`future-posts` or `published-posts`) as a second argument so the query can be adjusted per list, without adding new hooks. See #37578. --- src/wp-admin/includes/dashboard.php | 7 ++- .../tests/admin/wpDashboardRecentPosts.php | 58 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/tests/admin/wpDashboardRecentPosts.php diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 05e6e24f6b0c6..d2d638d8018dd 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -1010,10 +1010,13 @@ function wp_dashboard_recent_posts( $args ) { * Filters the query arguments used for the Recent Posts widget. * * @since 4.2.0 + * @since X.Y.Z Added the `$id` parameter. * - * @param array $query_args The arguments passed to WP_Query to produce the list of posts. + * @param array $query_args The arguments passed to WP_Query to produce the list of posts. + * @param string $id The container id of the widget section being rendered, + * e.g. 'future-posts' or 'published-posts'. */ - $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args ); + $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args, $args['id'] ); $posts = new WP_Query( $query_args ); diff --git a/tests/phpunit/tests/admin/wpDashboardRecentPosts.php b/tests/phpunit/tests/admin/wpDashboardRecentPosts.php new file mode 100644 index 0000000000000..d4f1b24f8c9c1 --- /dev/null +++ b/tests/phpunit/tests/admin/wpDashboardRecentPosts.php @@ -0,0 +1,58 @@ + 5, + 'status' => 'future', + 'order' => 'ASC', + 'title' => 'Publishing Soon', + 'id' => 'future-posts', + ) + ); + wp_dashboard_recent_posts( + array( + 'max' => 5, + 'status' => 'publish', + 'order' => 'DESC', + 'title' => 'Recently Published', + 'id' => 'published-posts', + ) + ); + ob_end_clean(); + + $this->assertSame( array( 'future-posts', 'published-posts' ), $received_ids ); + } +}