diff --git a/src/wp-admin/includes/dashboard-on-this-day.php b/src/wp-admin/includes/dashboard-on-this-day.php index 1939f8ca4b0e3..23a411e7e34e8 100644 --- a/src/wp-admin/includes/dashboard-on-this-day.php +++ b/src/wp-admin/includes/dashboard-on-this-day.php @@ -7,48 +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 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. - * - * @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' ), - 'wp_dashboard_on_this_day' - ); -} - -/** - * 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 +18,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/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 471324f9648ec..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,71 +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_and_postbox_class_filter() { - $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'] ); - $this->assertNotFalse( - has_filter( - 'postbox_classes_dashboard_wp_dashboard_on_this_day', - 'wp_dashboard_on_this_day_postbox_classes' - ) - ); - } - - /** - * @ticket 65116 - * - * @covers ::wp_dashboard_on_this_day_postbox_classes - */ - public function test_postbox_classes_hides_widget_without_matching_posts() { - wp_set_current_user( self::$user_id ); - - $this->assertContains( 'hidden', wp_dashboard_on_this_day_postbox_classes( array( '' ) ) ); - } - - /** - * @ticket 65116 - * - * @covers ::wp_dashboard_on_this_day_postbox_classes - */ - public function test_postbox_classes_does_not_hide_widget_with_matching_posts() { - wp_set_current_user( self::$user_id ); - $this->create_matching_post( self::$user_id ); - - $this->assertNotContains( 'hidden', wp_dashboard_on_this_day_postbox_classes( array( '' ) ) ); - } - - /** - * @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 *