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 ); + } +}