Changeset 65732
- Timestamp:
- 11/20/2026 09:17:39 PM (9 hours ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 3 edited
-
src/wp-admin/_index.php (modified) (1 diff)
-
src/wp-admin/css/dashboard.css (modified) (9 diffs)
-
src/wp-admin/includes/dashboard.php (modified) (10 diffs)
-
tests/phpunit/tests/admin/wpDashboardSiteActivity.php (deleted)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/_index.php
r64593 r65732 87 87 } 88 88 89 $help .= '<p>' . __( '<strong>Activity</strong> — Shows upcoming scheduled posts, recently published posts, and posts published on this day in previous years.' ) . '</p>'; 90 91 if ( _wp_dashboard_has_received_comments() ) { 92 $help .= '<p>' . __( '<strong>Recent Comments</strong> — Shows the most recent comments on your posts and allows you to moderate them.' ) . '</p>'; 93 } 89 $help .= '<p>' . __( '<strong>Activity</strong> — Shows the upcoming scheduled posts, recently published posts, and the most recent comments on your posts and allows you to moderate them.' ) . '</p>'; 94 90 95 91 if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { -
trunk/src/wp-admin/css/dashboard.css
r64799 r65732 880 880 /* Dashboard activity widget */ 881 881 882 #dashboard_ recent_comments.comment-meta span.approve::before {882 #dashboard_activity .comment-meta span.approve::before { 883 883 content: "\f227"; 884 884 content: "\f227" / ""; … … 891 891 } 892 892 893 #dashboard_activity .inside, 894 #dashboard_recent_comments .inside { 893 #dashboard_activity .inside { 895 894 margin: 0; 896 895 padding: 0 12px; … … 908 907 } 909 908 910 #dashboard_ recent_comments.subsubsub {909 #dashboard_activity .subsubsub { 911 910 float: none; 912 911 border-top: 1px solid #f0f0f1; … … 915 914 } 916 915 917 #dashboard_ recent_comments.subsubsub a .count,918 #dashboard_ recent_comments.subsubsub a.current .count {916 #dashboard_activity .subsubsub a .count, 917 #dashboard_activity .subsubsub a.current .count { 919 918 color: #646970; /* white background on the dashboard but #f0f0f1 on list tables */ 920 919 } 921 920 922 921 #future-posts ul, 923 #published-posts ul, 924 #on-this-day-posts ul { 922 #published-posts ul { 925 923 margin: 8px -12px 0 -12px; 926 924 } 927 925 928 926 #future-posts li, 929 #published-posts li, 930 #on-this-day-posts li { 927 #published-posts li { 931 928 display: grid; 932 929 grid-template-columns: clamp(160px, calc(2vw + 140px), 200px) auto; … … 937 934 938 935 #future-posts li:nth-child(odd), 939 #published-posts li:nth-child(odd), 940 #on-this-day-posts li:nth-child(odd) { 936 #published-posts li:nth-child(odd) { 941 937 background-color: #f6f7f7; 942 }943 944 #on-this-day-posts .wp-on-this-day-post-author {945 color: #646970;946 938 } 947 939 … … 964 956 /* @todo: needs serious de-duplication */ 965 957 966 # dashboard_recent_comments#the-comment-list tr.undo,967 # dashboard_recent_comments#the-comment-list div.undo {958 #activity-widget #the-comment-list tr.undo, 959 #activity-widget #the-comment-list div.undo { 968 960 background: none; 969 961 padding: 6px 0; … … 971 963 } 972 964 973 # dashboard_recent_comments#the-comment-list .comment-item {965 #activity-widget #the-comment-list .comment-item { 974 966 background: #f6f7f7; 975 967 padding: 12px; … … 977 969 } 978 970 979 # dashboard_recent_comments#the-comment-list .avatar {971 #activity-widget #the-comment-list .avatar { 980 972 position: absolute; 981 973 top: 12px; 982 974 } 983 975 984 # dashboard_recent_comments#the-comment-list .dashboard-comment-wrap.has-avatar {976 #activity-widget #the-comment-list .dashboard-comment-wrap.has-avatar { 985 977 padding-left: 63px; 986 978 } 987 979 988 # dashboard_recent_comments#the-comment-list .dashboard-comment-wrap blockquote {980 #activity-widget #the-comment-list .dashboard-comment-wrap blockquote { 989 981 margin: 1em 0; 990 982 } 991 983 992 # dashboard_recent_comments#the-comment-list .comment-item p.row-actions {984 #activity-widget #the-comment-list .comment-item p.row-actions { 993 985 margin: 4px 0 0; 994 986 } 995 987 996 # dashboard_recent_comments#the-comment-list .comment-item:first-child {988 #activity-widget #the-comment-list .comment-item:first-child { 997 989 border-top: 1px solid #f0f0f1; 998 990 } 999 991 1000 # dashboard_recent_comments#the-comment-list .unapproved {992 #activity-widget #the-comment-list .unapproved { 1001 993 background-color: #fcf9e8; 1002 994 } 1003 995 1004 # dashboard_recent_comments#the-comment-list .unapproved::before {996 #activity-widget #the-comment-list .unapproved::before { 1005 997 content: ""; 1006 998 display: block; … … 1013 1005 } 1014 1006 1015 # dashboard_recent_comments#the-comment-list .spam-undo-inside .avatar,1016 # dashboard_recent_comments#the-comment-list .trash-undo-inside .avatar {1007 #activity-widget #the-comment-list .spam-undo-inside .avatar, 1008 #activity-widget #the-comment-list .trash-undo-inside .avatar { 1017 1009 position: relative; 1018 1010 top: 0; -
trunk/src/wp-admin/includes/dashboard.php
r65317 r65732 6 6 * @subpackage Administration 7 7 */ 8 9 /**10 * Determines whether the site has ever received a comment.11 *12 * The result is persisted so the Recent Comments widget remains registered if13 * all comments are later deleted, preserving its Screen Options and position.14 *15 * @since 7.2.016 * @access private17 *18 * @return bool Whether the site has received a comment.19 */20 function _wp_dashboard_has_received_comments() {21 if ( get_option( 'dashboard_recent_comments_widget_registered' ) ) {22 return true;23 }24 25 $comment_count = wp_count_comments();26 27 if ( empty( $comment_count->all ) ) {28 return false;29 }30 31 update_option( 'dashboard_recent_comments_widget_registered', 1, false );32 33 return true;34 }35 8 36 9 /** … … 108 81 if ( is_blog_admin() ) { 109 82 wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' ); 110 }111 112 // Recent Comments Widget.113 if ( is_blog_admin() && _wp_dashboard_has_received_comments() ) {114 wp_add_dashboard_widget( 'dashboard_recent_comments', __( 'Recent Comments' ), 'wp_dashboard_recent_comments_widget' );115 83 } 116 84 … … 976 944 * 977 945 * @since 3.8.0 978 * @since 7.2.0 Added the On This Day section and moved Recent Comments to a dedicated widget.979 946 */ 980 947 function wp_dashboard_site_activity() { … … 982 949 echo '<div id="activity-widget">'; 983 950 984 $on_this_day_posts = wp_dashboard_on_this_day_get_posts(); 985 $future_posts = wp_dashboard_recent_posts( 951 $future_posts = wp_dashboard_recent_posts( 986 952 array( 987 953 'max' => 5, … … 992 958 ) 993 959 ); 994 $recent_posts = wp_dashboard_recent_posts(960 $recent_posts = wp_dashboard_recent_posts( 995 961 array( 996 'max' => 5, 997 'status' => 'publish', 998 'order' => 'DESC', 999 'title' => __( 'Recently Published' ), 1000 'id' => 'published-posts', 1001 'exclude' => wp_list_pluck( $on_this_day_posts, 'ID' ), 962 'max' => 5, 963 'status' => 'publish', 964 'order' => 'DESC', 965 'title' => __( 'Recently Published' ), 966 'id' => 'published-posts', 1002 967 ) 1003 968 ); 1004 969 1005 $ on_this_day_rendered = wp_dashboard_on_this_day( $on_this_day_posts);1006 1007 if ( ! $future_posts && ! $recent_posts && ! $ on_this_day_rendered) {970 $recent_comments = wp_dashboard_recent_comments(); 971 972 if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) { 1008 973 echo '<div class="no-activity">'; 1009 974 echo '<p>' . __( 'No activity yet!' ) . '</p>'; … … 1012 977 1013 978 echo '</div>'; 1014 }1015 1016 /**1017 * Outputs the On This Day section of the Activity widget.1018 *1019 * @since 7.2.01020 *1021 * @param WP_Post[]|null $posts Optional. Posts to render. Defaults to querying for posts.1022 * @return bool False if no posts were found. True otherwise.1023 */1024 function wp_dashboard_on_this_day( $posts = null ) {1025 if ( null === $posts ) {1026 $posts = wp_dashboard_on_this_day_get_posts();1027 }1028 1029 if ( empty( $posts ) ) {1030 return false;1031 }1032 1033 echo '<div id="on-this-day-posts" class="activity-block">';1034 echo '<h3>' . esc_html__( 'Published On This Day' ) . '</h3>';1035 echo '<ul>';1036 1037 foreach ( $posts as $post ) {1038 /* translators: Date format for posts published in a previous year. */1039 $date = get_the_date( __( 'M jS, Y' ), $post );1040 1041 $title = get_the_title( $post );1042 1043 if ( '' === trim( $title ) ) {1044 $title = __( '(no title)' );1045 1046 if ( current_user_can( 'read_post', $post->ID ) && ! post_password_required( $post ) ) {1047 $excerpt = get_the_excerpt( $post );1048 1049 if ( is_string( $excerpt ) && '' !== $excerpt ) {1050 $title .= ' ' . wp_trim_words( $excerpt, 15 );1051 }1052 }1053 }1054 1055 $can_edit = current_user_can( 'edit_post', $post->ID );1056 $link = $can_edit ? get_edit_post_link( $post->ID ) : get_permalink( $post );1057 1058 if ( $can_edit ) {1059 /* translators: %s: Post title. */1060 $aria_label = sprintf( __( 'Edit “%s”' ), $title );1061 } else {1062 /* translators: %s: Post title. */1063 $aria_label = sprintf( __( 'View “%s”' ), $title );1064 }1065 1066 $author_id = (int) $post->post_author;1067 $author_name = $author_id > 0 ? (string) get_the_author_meta( 'display_name', $author_id ) : '';1068 1069 printf(1070 '<li><span>%1$s</span><span><a href="%2$s" aria-label="%3$s">%4$s</a>',1071 esc_html( $date ),1072 esc_url( $link ),1073 esc_attr( $aria_label ),1074 esc_html( $title )1075 );1076 1077 if ( '' !== trim( $author_name ) && get_current_user_id() !== $author_id ) {1078 printf(1079 ' <span class="wp-on-this-day-post-author">%s</span>',1080 esc_html(1081 sprintf(1082 /* translators: %s: Post author's display name. */1083 __( 'by %s' ),1084 $author_name1085 )1086 )1087 );1088 }1089 1090 echo '</span></li>';1091 }1092 1093 echo '</ul>';1094 echo '</div>';1095 1096 return true;1097 }1098 1099 /**1100 * Retrieves posts published on this calendar day in previous years.1101 *1102 * Up to ten posts are returned by default. Use the1103 * {@see 'wp_dashboard_on_this_day_query_args'} filter to change the limit.1104 * Results are cached by WP_Query's native query caching.1105 *1106 * @since 7.2.01107 *1108 * @return WP_Post[] Array of posts ordered by newest first.1109 */1110 function wp_dashboard_on_this_day_get_posts() {1111 $today = current_datetime();1112 $year = (int) $today->format( 'Y' );1113 1114 $args = array(1115 'post_type' => 'post',1116 'post_status' => array( 'publish' ),1117 'posts_per_page' => 10,1118 'ignore_sticky_posts' => true,1119 'orderby' => 'date',1120 'order' => 'DESC',1121 'no_found_rows' => true,1122 'update_post_term_cache' => false,1123 'update_post_meta_cache' => false,1124 'date_query' => array(1125 'relation' => 'AND',1126 array(1127 'before' => array( 'year' => $year ),1128 ),1129 _wp_dashboard_on_this_day_date_query_clause( $today ),1130 ),1131 );1132 1133 /**1134 * Filters the arguments used to query posts for the On This Day section.1135 *1136 * @since 7.2.01137 *1138 * @param array $args WP_Query arguments.1139 */1140 $args = apply_filters( 'wp_dashboard_on_this_day_query_args', $args );1141 1142 $query = new WP_Query( $args );1143 1144 return $query->posts;1145 }1146 1147 /**1148 * Builds the date query clause for today's anniversary date.1149 *1150 * On February 28 in a non-leap year, February 29 posts are included so1151 * leap-day anniversaries still appear.1152 *1153 * @since 7.2.01154 * @access private1155 *1156 * @param DateTimeInterface $date Date to build the clause for.1157 * @return array Date query clause.1158 */1159 function _wp_dashboard_on_this_day_date_query_clause( $date ) {1160 $month = (int) $date->format( 'm' );1161 $day = (int) $date->format( 'd' );1162 $clause = array(1163 'month' => $month,1164 'day' => $day,1165 );1166 1167 // Display leap day posts on February 28 in non-leap years.1168 if (1169 28 === $day1170 && 2 === $month1171 && false === (bool) $date->format( 'L' )1172 ) {1173 $clause = array(1174 'relation' => 'OR',1175 $clause,1176 array(1177 'month' => 2,1178 'day' => 29,1179 ),1180 );1181 }1182 1183 return $clause;1184 979 } 1185 980 … … 1197 992 * @type string $title Section title. 1198 993 * @type string $id The container id. 1199 * @type int[] $exclude Optional. Post IDs to exclude.1200 994 * } 1201 995 * @return bool False if no posts were found. True otherwise. … … 1212 1006 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable', 1213 1007 ); 1214 1215 if ( ! empty( $args['exclude'] ) ) {1216 $query_args['post__not_in'] = array_map( 'intval', $args['exclude'] );1217 }1218 1008 1219 1009 /** … … 1288 1078 1289 1079 /** 1290 * Outputs the Recent Comments dashboard widget. 1291 * 1292 * Callback function for {@see 'dashboard_recent_comments'}. 1293 * 1294 * @since 7.2.0 1295 */ 1296 function wp_dashboard_recent_comments_widget() { 1297 if ( ! wp_dashboard_recent_comments( 5, false ) ) { 1298 echo '<p>' . esc_html__( 'No comments to show.' ) . '</p>'; 1299 } 1300 } 1301 1302 /** 1303 * Outputs recent comments. 1080 * Show Comments section. 1304 1081 * 1305 1082 * @since 3.8.0 1306 * @since 7.2.0 Moved from the Activity widget to a dedicated dashboard widget. 1307 * 1308 * @param int $total_items Optional. Number of comments to query. Default 5. 1309 * @param bool $show_title Optional. Whether to display the section title. Default true. 1083 * 1084 * @param int $total_items Optional. Number of comments to query. Default 5. 1310 1085 * @return bool False if no comments were found. True otherwise. 1311 1086 */ 1312 function wp_dashboard_recent_comments( $total_items = 5 , $show_title = true) {1087 function wp_dashboard_recent_comments( $total_items = 5 ) { 1313 1088 // Select all comment types and filter out spam later for better query performance. 1314 1089 $comments = array(); … … 1354 1129 if ( $comments ) { 1355 1130 echo '<div id="latest-comments" class="activity-block table-view-list">'; 1356 1357 if ( $show_title ) { 1358 echo '<h3>' . esc_html__( 'Recent Comments' ) . '</h3>'; 1359 } 1131 echo '<h3>' . __( 'Recent Comments' ) . '</h3>'; 1360 1132 1361 1133 echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
Note:
See TracChangeset
for help on using the changeset viewer.