Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/wp-admin/includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
58 changes: 58 additions & 0 deletions tests/phpunit/tests/admin/wpDashboardRecentPosts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* Tests for wp_dashboard_recent_posts().
*
* @group admin
* @group dashboard
*
* @covers ::wp_dashboard_recent_posts
*/
class Tests_Admin_wpDashboardRecentPosts extends WP_UnitTestCase {

public static function set_up_before_class() {
parent::set_up_before_class();

require_once ABSPATH . 'wp-admin/includes/dashboard.php';
}

/**
* @ticket 37578
*/
public function test_query_args_filter_receives_container_id() {
$received_ids = array();

add_filter(
'dashboard_recent_posts_query_args',
static function ( $query_args, $id ) use ( &$received_ids ) {
$received_ids[] = $id;
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' => 'publish',
'order' => 'DESC',
'title' => 'Recently Published',
'id' => 'published-posts',
)
);
ob_end_clean();

$this->assertSame( array( 'future-posts', 'published-posts' ), $received_ids );
}
}
Loading