From 5b4dec71b4165ba3fcfc675a72203d69b69e1c90 Mon Sep 17 00:00:00 2001 From: Deepak Kumar Date: Fri, 17 Jul 2026 10:25:09 +0530 Subject: [PATCH 1/2] Administration: Always display the On This Day dashboard widget --- .../includes/dashboard-on-this-day.php | 34 +++---------------- tests/phpunit/tests/admin/wpOnThisDay.php | 29 +--------------- 2 files changed, 6 insertions(+), 57 deletions(-) diff --git a/src/wp-admin/includes/dashboard-on-this-day.php b/src/wp-admin/includes/dashboard-on-this-day.php index 1939f8ca4b0e3..b2cc7c161975a 100644 --- a/src/wp-admin/includes/dashboard-on-this-day.php +++ b/src/wp-admin/includes/dashboard-on-this-day.php @@ -11,16 +11,14 @@ * Registers the On This Day dashboard widget. * * Designed to be the single entry point called from the dashboard setup - * routine. The widget is always registered so that it remains available in - * Screen Options and keeps its user-customized position. When there are no - * matching posts, a marker class is added to the postbox so the widget can be - * hidden with CSS. + * routine. The widget is always registered and always visible, keeping its + * Screen Options entry consistent with what is shown on screen. When there are + * no matching posts, a placeholder message is displayed. Users who do not want + * the widget can hide it via Screen Options, and that preference is preserved. * * @since 7.1.0 */ function wp_dashboard_on_this_day_setup() { - add_filter( 'postbox_classes_dashboard_wp_dashboard_on_this_day', 'wp_dashboard_on_this_day_postbox_classes' ); - wp_add_dashboard_widget( 'wp_dashboard_on_this_day', __( 'On This Day' ), @@ -28,27 +26,6 @@ function wp_dashboard_on_this_day_setup() { ); } -/** - * Hides the On This Day postbox when there are no posts to show. - * - * Adds the core `hidden` class so the widget stays registered — preserving its - * Screen Options entry and user-customized position — while being hidden when - * empty. A user can still reveal it via Screen Options, in which case the - * placeholder message is shown. - * - * @since 7.1.0 - * - * @param string[] $classes An array of postbox classes. - * @return string[] Filtered postbox classes. - */ -function wp_dashboard_on_this_day_postbox_classes( $classes ) { - if ( empty( wp_dashboard_on_this_day_get_posts() ) ) { - $classes[] = 'hidden'; - } - - return $classes; -} - /** * Renders the On This Day dashboard widget. * @@ -60,8 +37,7 @@ function wp_dashboard_on_this_day() { $posts = wp_dashboard_on_this_day_get_posts(); if ( empty( $posts ) ) { - // Placeholder shown when a user reveals the hidden widget via Screen - // Options on a day with no matching posts. + // Placeholder shown on a day with no matching posts in previous years. echo '

' . esc_html__( 'No posts were published on this day in previous years.' ) . '

'; return; } diff --git a/tests/phpunit/tests/admin/wpOnThisDay.php b/tests/phpunit/tests/admin/wpOnThisDay.php index 61aef6401683a..6740caa3a0ac6 100644 --- a/tests/phpunit/tests/admin/wpOnThisDay.php +++ b/tests/phpunit/tests/admin/wpOnThisDay.php @@ -94,7 +94,7 @@ private static function get_date_query_clause( $date ) { /** * @covers ::wp_dashboard_on_this_day_setup */ - public function test_setup_always_registers_widget_and_postbox_class_filter() { + public function test_setup_always_registers_widget() { $this->set_up_dashboard_screen(); $user_id = self::factory()->user->create( array( 'role' => 'author' ) ); @@ -106,33 +106,6 @@ public function test_setup_always_registers_widget_and_postbox_class_filter() { $this->assertArrayHasKey( 'wp_dashboard_on_this_day', $dashboard_widgets ); $this->assertSame( 'On This Day', $dashboard_widgets['wp_dashboard_on_this_day']['title'] ); - $this->assertNotFalse( - has_filter( - 'postbox_classes_dashboard_wp_dashboard_on_this_day', - 'wp_dashboard_on_this_day_postbox_classes' - ) - ); - } - - /** - * @covers ::wp_dashboard_on_this_day_postbox_classes - */ - public function test_postbox_classes_hides_widget_without_matching_posts() { - $user_id = self::factory()->user->create( array( 'role' => 'author' ) ); - wp_set_current_user( $user_id ); - - $this->assertContains( 'hidden', wp_dashboard_on_this_day_postbox_classes( array( '' ) ) ); - } - - /** - * @covers ::wp_dashboard_on_this_day_postbox_classes - */ - public function test_postbox_classes_does_not_hide_widget_with_matching_posts() { - $user_id = self::factory()->user->create( array( 'role' => 'author' ) ); - wp_set_current_user( $user_id ); - $this->create_matching_post( $user_id ); - - $this->assertNotContains( 'hidden', wp_dashboard_on_this_day_postbox_classes( array( '' ) ) ); } /** From d218c56c885149a07deb1d1782dfa5c3d71db745 Mon Sep 17 00:00:00 2001 From: Aki Hamano Date: Wed, 29 Jul 2026 10:33:39 +0900 Subject: [PATCH 2/2] Inline wp_dashboard_on_this_day_setup() into wp_dashboard_setup(). The setup function only wrapped a single wp_add_dashboard_widget() call, which added an indirection every other core dashboard widget does without. Registering the widget directly in wp_dashboard_setup() keeps the On This Day widget consistent with At a Glance, Activity, and Quick Draft. The file guard now checks for wp_dashboard_on_this_day(), the render callback that remains in dashboard-on-this-day.php. The two unit tests for the removed function only asserted that wp_add_dashboard_widget() had been called, which no other core widget is tested for, so they are dropped along with their now unused helpers. Query and rendering behavior stays covered by the remaining tests. Co-Authored-By: Claude --- .../includes/dashboard-on-this-day.php | 19 ------- src/wp-admin/includes/dashboard.php | 4 +- .../tests/admin/wpDashboardOnThisDay.php | 55 ------------------- 3 files changed, 2 insertions(+), 76 deletions(-) diff --git a/src/wp-admin/includes/dashboard-on-this-day.php b/src/wp-admin/includes/dashboard-on-this-day.php index b2cc7c161975a..23a411e7e34e8 100644 --- a/src/wp-admin/includes/dashboard-on-this-day.php +++ b/src/wp-admin/includes/dashboard-on-this-day.php @@ -7,25 +7,6 @@ * @since 7.1.0 */ -/** - * Registers the On This Day dashboard widget. - * - * Designed to be the single entry point called from the dashboard setup - * routine. The widget is always registered and always visible, keeping its - * Screen Options entry consistent with what is shown on screen. When there are - * no matching posts, a placeholder message is displayed. Users who do not want - * the widget can hide it via Screen Options, and that preference is preserved. - * - * @since 7.1.0 - */ -function wp_dashboard_on_this_day_setup() { - wp_add_dashboard_widget( - 'wp_dashboard_on_this_day', - __( 'On This Day' ), - 'wp_dashboard_on_this_day' - ); -} - /** * Renders the On This Day dashboard widget. * diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 5fdbaf7a4fa40..a0c2a23189644 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -89,11 +89,11 @@ function wp_dashboard_setup() { } // On This Day. - if ( ! function_exists( 'wp_dashboard_on_this_day_setup' ) ) { + if ( ! function_exists( 'wp_dashboard_on_this_day' ) ) { require_once ABSPATH . 'wp-admin/includes/dashboard-on-this-day.php'; } - wp_dashboard_on_this_day_setup(); + wp_add_dashboard_widget( 'wp_dashboard_on_this_day', __( 'On This Day' ), 'wp_dashboard_on_this_day' ); // WordPress Events and News. wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' ); diff --git a/tests/phpunit/tests/admin/wpDashboardOnThisDay.php b/tests/phpunit/tests/admin/wpDashboardOnThisDay.php index c2f2f50922193..ed6d7bfc18842 100644 --- a/tests/phpunit/tests/admin/wpDashboardOnThisDay.php +++ b/tests/phpunit/tests/admin/wpDashboardOnThisDay.php @@ -32,25 +32,6 @@ public static function wpTearDownAfterClass() { self::delete_user( self::$other_user_id ); } - public function tear_down() { - unset( $GLOBALS['wp_meta_boxes']['dashboard'] ); - - parent::tear_down(); - } - - /** - * Sets up the globals needed to register dashboard widgets. - */ - private function set_up_dashboard_screen() { - if ( ! function_exists( 'wp_add_dashboard_widget' ) ) { - require_once ABSPATH . 'wp-admin/includes/dashboard.php'; - } - - set_current_screen( 'dashboard' ); - - $GLOBALS['wp_meta_boxes']['dashboard'] = array(); - } - /** * Creates a published post on the widget's prior-year calendar day. * @@ -114,42 +95,6 @@ private static function get_date_query_clause( string $date ): array { return _wp_dashboard_on_this_day_date_query_clause( new DateTimeImmutable( $date, wp_timezone() ) ); } - /** - * @ticket 65116 - * - * @covers ::wp_dashboard_on_this_day_setup - */ - public function test_setup_always_registers_widget() { - $this->set_up_dashboard_screen(); - - wp_set_current_user( self::$user_id ); - - wp_dashboard_on_this_day_setup(); - - $dashboard_widgets = $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] ?? array(); - - $this->assertArrayHasKey( 'wp_dashboard_on_this_day', $dashboard_widgets ); - $this->assertSame( 'On This Day', $dashboard_widgets['wp_dashboard_on_this_day']['title'] ); - } - - /** - * @ticket 65116 - * - * @covers ::wp_dashboard_on_this_day_setup - */ - public function test_setup_adds_dashboard_widget_with_matching_post_from_another_author() { - $this->set_up_dashboard_screen(); - - wp_set_current_user( self::$user_id ); - $this->create_matching_post( self::$other_user_id ); - - wp_dashboard_on_this_day_setup(); - - $dashboard_widgets = $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] ?? array(); - - $this->assertArrayHasKey( 'wp_dashboard_on_this_day', $dashboard_widgets ); - } - /** * @ticket 65116 *