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( '' ) ) ); } /**