Changeset 50689
- Timestamp:
- 04/07/2021 06:32:01 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/dashboard.php
r50556 r50689 20 20 function wp_dashboard_setup() { 21 21 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; 22 22 23 $wp_dashboard_control_callbacks = array(); 23 24 $screen = get_current_screen(); … … 29 30 if ( $response && $response['upgrade'] ) { 30 31 add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); 32 31 33 if ( $response['insecure'] ) { 32 34 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); … … 38 40 // PHP Version. 39 41 $response = wp_check_php_version(); 40 if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] && current_user_can( 'update_php' ) ) { 42 43 if ( $response && isset( $response['is_acceptable'] ) && ! $response['is_acceptable'] 44 && current_user_can( 'update_php' ) 45 ) { 41 46 add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' ); 47 42 48 wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' ); 43 49 } … … 175 181 */ 176 182 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) { 183 global $wp_dashboard_control_callbacks; 184 177 185 $screen = get_current_screen(); 178 global $wp_dashboard_control_callbacks;179 186 180 187 $private_callback_args = array( '__widget_basename' => $widget_name ); … … 186 193 } 187 194 188 if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback) ) {195 if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) { 189 196 $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback; 190 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) { 197 198 if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) { 191 199 list($url) = explode( '#', add_query_arg( 'edit', false ), 2 ); 192 200 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>'; … … 213 221 $context = 'normal'; 214 222 } 223 215 224 if ( empty( $priority ) ) { 216 225 $priority = 'core'; … … 247 256 $columns = absint( $screen->get_columns() ); 248 257 $columns_css = ''; 258 249 259 if ( $columns ) { 250 260 $columns_css = " columns-$columns"; 251 261 } 252 253 262 ?> 254 263 <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>"> … … 292 301 foreach ( array( 'post', 'page' ) as $post_type ) { 293 302 $num_posts = wp_count_posts( $post_type ); 303 294 304 if ( $num_posts && $num_posts->publish ) { 295 305 if ( 'post' === $post_type ) { … … 300 310 $text = _n( '%s Page', '%s Pages', $num_posts->publish ); 301 311 } 312 302 313 $text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); 303 314 $post_type_object = get_post_type_object( $post_type ); 315 304 316 if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { 305 317 printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text ); … … 309 321 } 310 322 } 323 311 324 // Comments. 312 325 $num_comm = wp_count_comments(); 326 313 327 if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) { 314 328 /* translators: %s: Number of comments. */ 315 329 $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) ); 316 330 ?> 317 <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li> 331 <li class="comment-count"> 332 <a href="edit-comments.php"><?php echo $text; ?></a> 333 </li> 318 334 <?php 319 335 $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated ); … … 321 337 $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n ); 322 338 ?> 323 <li class="comment-mod-count 324 <?php 325 if ( ! $num_comm->moderated ) { 326 echo ' hidden'; 327 } 328 ?> 329 "><a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a></li> 339 <li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>"> 340 <a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a> 341 </li> 330 342 <?php 331 343 } … … 354 366 355 367 // Check if search engines are asked not to index this site. 356 if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) { 368 if ( ! is_network_admin() && ! is_user_admin() 369 && current_user_can( 'manage_options' ) && ! get_option( 'blog_public' ) 370 ) { 357 371 358 372 /** … … 379 393 * @param string $content Default text. 380 394 */ 381 $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) ); 395 $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) ); 396 382 397 $title_attr = '' === $title ? '' : " title='$title'"; 383 398 … … 427 442 function wp_network_dashboard_right_now() { 428 443 $actions = array(); 444 429 445 if ( current_user_can( 'create_sites' ) ) { 430 446 $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>'; … … 516 532 } 517 533 518 / * Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */534 // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used. 519 535 $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID. 536 520 537 if ( $last_post_id ) { 521 538 $post = get_post( $last_post_id ); 539 522 540 if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore. 523 541 $post = get_default_post_to_edit( 'post', true ); … … 529 547 $post = get_default_post_to_edit( 'post', true ); 530 548 $user_id = get_current_user_id(); 549 531 550 // Don't create an option if this is a super admin who does not belong to this site. 532 551 if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) { … … 607 626 608 627 echo '<div class="drafts">'; 628 609 629 if ( count( $drafts ) > 3 ) { 610 630 printf( … … 614 634 ); 615 635 } 616 echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>"; 636 637 echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n"; 638 echo '<ul>'; 617 639 618 640 /* translators: Maximum number of words used in a preview of a draft on the dashboard. */ … … 623 645 $url = get_edit_post_link( $draft->ID ); 624 646 $title = _draft_or_post_title( $draft->ID ); 647 625 648 echo "<li>\n"; 626 649 printf( … … 633 656 get_the_time( __( 'F j, Y' ), $draft ) 634 657 ); 658 635 659 $the_content = wp_trim_words( $draft->post_content, $draft_length ); 660 636 661 if ( $the_content ) { 637 662 echo '<p>' . $the_content . '</p>'; … … 639 664 echo "</li>\n"; 640 665 } 641 echo "</ul>\n</div>"; 666 667 echo "</ul>\n"; 668 echo '</div>'; 642 669 } 643 670 … … 657 684 658 685 if ( $comment->comment_post_ID > 0 ) { 659 660 686 $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); 661 687 $comment_post_url = get_the_permalink( $comment->comment_post_ID ); … … 953 979 */ 954 980 $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args ); 955 $posts = new WP_Query( $query_args ); 981 982 $posts = new WP_Query( $query_args ); 956 983 957 984 if ( $posts->have_posts() ) { … … 971 998 972 999 $time = get_the_time( 'U' ); 973 if ( gmdate( 'Y-m-d', $time ) == $today ) { 1000 1001 if ( gmdate( 'Y-m-d', $time ) === $today ) { 974 1002 $relative = __( 'Today' ); 975 } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) {1003 } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) { 976 1004 $relative = __( 'Tomorrow' ); 977 1005 } elseif ( gmdate( 'Y', $time ) !== $year ) { … … 1026 1054 'offset' => 0, 1027 1055 ); 1056 1028 1057 if ( ! current_user_can( 'edit_posts' ) ) { 1029 1058 $comments_query['status'] = 'approve'; … … 1034 1063 break; 1035 1064 } 1065 1036 1066 foreach ( $possible as $comment ) { 1037 1067 if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) { 1038 1068 continue; 1039 1069 } 1070 1040 1071 $comments[] = $comment; 1041 if ( count( $comments ) == $total_items ) { 1072 1073 if ( count( $comments ) === $total_items ) { 1042 1074 break 2; 1043 1075 } 1044 1076 } 1077 1045 1078 $comments_query['offset'] += $comments_query['number']; 1046 1079 $comments_query['number'] = $total_items * 10; … … 1110 1143 if ( empty( $check_urls ) ) { 1111 1144 $widgets = get_option( 'dashboard_widget_options' ); 1145 1112 1146 if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) { 1113 1147 echo $loading; 1114 1148 return false; 1115 1149 } 1150 1116 1151 $check_urls = array( $widgets[ $widget_id ]['url'] ); 1117 1152 } … … 1120 1155 $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); 1121 1156 $output = get_transient( $cache_key ); 1157 1122 1158 if ( false !== $output ) { 1123 1159 echo $output; … … 1157 1193 global $wp_dashboard_control_callbacks; 1158 1194 1159 if ( is_scalar( $widget_control_id ) && $widget_control_id && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) ) { 1195 if ( is_scalar( $widget_control_id ) && $widget_control_id 1196 && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) 1197 && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) 1198 ) { 1160 1199 call_user_func( 1161 1200 $wp_dashboard_control_callbacks[ $widget_control_id ], … … 1182 1221 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { 1183 1222 $widget_options = get_option( 'dashboard_widget_options' ); 1223 1184 1224 if ( ! $widget_options ) { 1185 1225 $widget_options = array(); … … 1210 1250 } 1211 1251 } 1252 1212 1253 update_option( 'dashboard_widget_options', $widget_options ); 1254 1213 1255 $locale = get_user_locale(); 1214 1256 $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); … … 1555 1597 */ 1556 1598 function wp_dashboard_quota() { 1557 if ( ! is_multisite() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) { 1599 if ( ! is_multisite() || ! current_user_can( 'upload_files' ) 1600 || get_site_option( 'upload_space_check_disabled' ) 1601 ) { 1558 1602 return true; 1559 1603 } … … 1567 1611 $percentused = ( $used / $quota ) * 100; 1568 1612 } 1613 1569 1614 $used_class = ( $percentused >= 70 ) ? ' warning' : ''; 1570 1615 $used = round( $used, 2 ); … … 1704 1749 1705 1750 $response = get_site_transient( 'browser_' . $key ); 1751 1706 1752 if ( false === $response ) { 1707 1753 // Include an unmodified $wp_version. … … 1720 1766 $response = wp_remote_post( $url, $options ); 1721 1767 1722 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {1768 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { 1723 1769 return false; 1724 1770 }
Note: See TracChangeset
for help on using the changeset viewer.