diff --git a/src/wp-admin/_index.php b/src/wp-admin/_index.php index 4af8d0d66485b..de5cc21b8ff4f 100644 --- a/src/wp-admin/_index.php +++ b/src/wp-admin/_index.php @@ -86,11 +86,7 @@ $help .= '
' . __( 'At a Glance — Displays a summary of the content on your site and identifies which theme and version of WordPress you are using.' ) . '
'; } -$help .= '' . __( 'Activity — Shows upcoming scheduled posts, recently published posts, and posts published on this day in previous years.' ) . '
'; - -if ( _wp_dashboard_has_received_comments() ) { - $help .= '' . __( 'Recent Comments — Shows the most recent comments on your posts and allows you to moderate them.' ) . '
'; -} +$help .= '' . __( 'Activity — Shows the upcoming scheduled posts, recently published posts, and the most recent comments on your posts and allows you to moderate them.' ) . '
'; if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { $help .= '' . __( "Quick Draft — Allows you to create a new post and save it as a draft. Also displays links to the 3 most recent draft posts you've started." ) . '
'; diff --git a/src/wp-admin/css/dashboard.css b/src/wp-admin/css/dashboard.css index 100c4df0a9633..c75eca12ee7be 100644 --- a/src/wp-admin/css/dashboard.css +++ b/src/wp-admin/css/dashboard.css @@ -879,7 +879,7 @@ body #dashboard-widgets .postbox form .submit { /* Dashboard activity widget */ -#dashboard_recent_comments .comment-meta span.approve::before { +#dashboard_activity .comment-meta span.approve::before { content: "\f227"; content: "\f227" / ""; font: 20px/0.5 dashicons; @@ -890,8 +890,7 @@ body #dashboard-widgets .postbox form .submit { margin-right: 2px; } -#dashboard_activity .inside, -#dashboard_recent_comments .inside { +#dashboard_activity .inside { margin: 0; padding: 0 12px; } @@ -907,27 +906,25 @@ body #dashboard-widgets .postbox form .submit { font-size: 16px; } -#dashboard_recent_comments .subsubsub { +#dashboard_activity .subsubsub { float: none; border-top: 1px solid #f0f0f1; margin: 0 -12px; padding: 8px 12px 4px; } -#dashboard_recent_comments .subsubsub a .count, -#dashboard_recent_comments .subsubsub a.current .count { +#dashboard_activity .subsubsub a .count, +#dashboard_activity .subsubsub a.current .count { color: #646970; /* white background on the dashboard but #f0f0f1 on list tables */ } #future-posts ul, -#published-posts ul, -#on-this-day-posts ul { +#published-posts ul { margin: 8px -12px 0 -12px; } #future-posts li, -#published-posts li, -#on-this-day-posts li { +#published-posts li { display: grid; grid-template-columns: clamp(160px, calc(2vw + 140px), 200px) auto; column-gap: 10px; @@ -936,15 +933,10 @@ body #dashboard-widgets .postbox form .submit { } #future-posts li:nth-child(odd), -#published-posts li:nth-child(odd), -#on-this-day-posts li:nth-child(odd) { +#published-posts li:nth-child(odd) { background-color: #f6f7f7; } -#on-this-day-posts .wp-on-this-day-post-author { - color: #646970; -} - .activity-block { border-bottom: 1px solid #f0f0f1; margin: 0 -12px 6px -12px; @@ -963,45 +955,45 @@ body #dashboard-widgets .postbox form .submit { /* Dashboard activity widget - Comments */ /* @todo: needs serious de-duplication */ -#dashboard_recent_comments #the-comment-list tr.undo, -#dashboard_recent_comments #the-comment-list div.undo { +#activity-widget #the-comment-list tr.undo, +#activity-widget #the-comment-list div.undo { background: none; padding: 6px 0; margin-left: 12px; } -#dashboard_recent_comments #the-comment-list .comment-item { +#activity-widget #the-comment-list .comment-item { background: #f6f7f7; padding: 12px; position: relative; } -#dashboard_recent_comments #the-comment-list .avatar { +#activity-widget #the-comment-list .avatar { position: absolute; top: 12px; } -#dashboard_recent_comments #the-comment-list .dashboard-comment-wrap.has-avatar { +#activity-widget #the-comment-list .dashboard-comment-wrap.has-avatar { padding-left: 63px; } -#dashboard_recent_comments #the-comment-list .dashboard-comment-wrap blockquote { +#activity-widget #the-comment-list .dashboard-comment-wrap blockquote { margin: 1em 0; } -#dashboard_recent_comments #the-comment-list .comment-item p.row-actions { +#activity-widget #the-comment-list .comment-item p.row-actions { margin: 4px 0 0; } -#dashboard_recent_comments #the-comment-list .comment-item:first-child { +#activity-widget #the-comment-list .comment-item:first-child { border-top: 1px solid #f0f0f1; } -#dashboard_recent_comments #the-comment-list .unapproved { +#activity-widget #the-comment-list .unapproved { background-color: #fcf9e8; } -#dashboard_recent_comments #the-comment-list .unapproved::before { +#activity-widget #the-comment-list .unapproved::before { content: ""; display: block; position: absolute; @@ -1012,8 +1004,8 @@ body #dashboard-widgets .postbox form .submit { width: 4px; } -#dashboard_recent_comments #the-comment-list .spam-undo-inside .avatar, -#dashboard_recent_comments #the-comment-list .trash-undo-inside .avatar { +#activity-widget #the-comment-list .spam-undo-inside .avatar, +#activity-widget #the-comment-list .trash-undo-inside .avatar { position: relative; top: 0; } diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 9ba75b74bc4c2..05e6e24f6b0c6 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -6,33 +6,6 @@ * @subpackage Administration */ -/** - * Determines whether the site has ever received a comment. - * - * The result is persisted so the Recent Comments widget remains registered if - * all comments are later deleted, preserving its Screen Options and position. - * - * @since 7.2.0 - * @access private - * - * @return bool Whether the site has received a comment. - */ -function _wp_dashboard_has_received_comments() { - if ( get_option( 'dashboard_recent_comments_widget_registered' ) ) { - return true; - } - - $comment_count = wp_count_comments(); - - if ( empty( $comment_count->all ) ) { - return false; - } - - update_option( 'dashboard_recent_comments_widget_registered', 1, false ); - - return true; -} - /** * Registers dashboard widgets. * @@ -109,11 +82,6 @@ function wp_dashboard_setup() { wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' ); } - // Recent Comments Widget. - if ( is_blog_admin() && _wp_dashboard_has_received_comments() ) { - wp_add_dashboard_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments_widget' ); - } - // QuickPress Widget. if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { $quick_draft_title = sprintf( ' ', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) ); @@ -975,14 +943,12 @@ function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { * Callback function for {@see 'dashboard_activity'}. * * @since 3.8.0 - * @since 7.2.0 Added the On This Day section and moved Recent Comments to a dedicated widget. */ function wp_dashboard_site_activity() { echo '' . __( 'No activity yet!' ) . '
'; echo '' . esc_html__( 'No comments to show.' ) . '
'; - } -} - -/** - * Outputs recent comments. + * Show Comments section. * * @since 3.8.0 - * @since 7.2.0 Moved from the Activity widget to a dedicated dashboard widget. * - * @param int $total_items Optional. Number of comments to query. Default 5. - * @param bool $show_title Optional. Whether to display the section title. Default true. + * @param int $total_items Optional. Number of comments to query. Default 5. * @return bool False if no comments were found. True otherwise. */ -function wp_dashboard_recent_comments( $total_items = 5, $show_title = true ) { +function wp_dashboard_recent_comments( $total_items = 5 ) { // Select all comment types and filter out spam later for better query performance. $comments = array(); @@ -1353,10 +1128,7 @@ function wp_dashboard_recent_comments( $total_items = 5, $show_title = true ) { if ( $comments ) { echo '
Recent Comments
', $comments_output ); - $this->assertStringContainsString( 'Recent Comments
', $direct_output ); - } - - /** - * @ticket 65116 - * - * @covers ::wp_dashboard_recent_comments_widget - */ - public function test_recent_comments_widget_renders_empty_state_when_user_has_no_visible_comments() { - $post_id = self::factory()->post->create( array( 'post_status' => 'publish' ) ); - self::factory()->comment->create( - array( - 'comment_post_ID' => $post_id, - 'comment_approved' => '0', - ) - ); - wp_set_current_user( self::factory()->user->create( array( 'role' => 'subscriber' ) ) ); - - ob_start(); - wp_dashboard_recent_comments_widget(); - $output = ob_get_clean(); - - $this->assertStringContainsString( 'No comments to show.', $output ); - } - - /** - * @ticket 65116 - * - * @covers ::_wp_dashboard_has_received_comments - * @covers ::wp_dashboard_setup - */ - public function test_recent_comments_widget_remains_registered_after_comments_are_deleted() { - add_filter( 'pre_http_request', array( $this, 'mock_http_request_failure' ) ); - - try { - wp_dashboard_setup(); - $this->assertArrayNotHasKey( 'dashboard_recent_comments', $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] ); - - unset( $GLOBALS['wp_meta_boxes']['dashboard'] ); - - $post_id = self::factory()->post->create(); - $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id ) ); - - wp_dashboard_setup(); - $this->assertArrayHasKey( 'dashboard_recent_comments', $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] ); - $this->assertSame( - 'wp_dashboard_recent_comments_widget', - $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core']['dashboard_recent_comments']['callback'] - ); - $this->assertSame( 1, get_option( 'dashboard_recent_comments_widget_registered' ) ); - - wp_delete_comment( $comment_id, true ); - unset( $GLOBALS['wp_meta_boxes']['dashboard'] ); - - wp_dashboard_setup(); - $this->assertArrayHasKey( 'dashboard_recent_comments', $GLOBALS['wp_meta_boxes']['dashboard']['normal']['core'] ); - } finally { - remove_filter( 'pre_http_request', array( $this, 'mock_http_request_failure' ) ); - } - } - - /** - * Mocks an HTTP request failure during dashboard setup. - * - * @return WP_Error Mock request error. - */ - public function mock_http_request_failure() { - return new WP_Error( 'http_request_failed' ); - } - - /** - * Sets the On This Day query limit to three. - * - * @param array $args Query arguments. - * @return array Filtered query arguments. - */ - public function filter_on_this_day_query_limit( $args ) { - $args['posts_per_page'] = 3; - - return $args; - } - - /** - * Filters the On This Day query to include private posts. - * - * @param array $args Query arguments. - * @return array Filtered query arguments. - */ - public function filter_on_this_day_query_private_posts( $args ) { - $args['post_status'] = array( 'private' ); - - return $args; - } -}