| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Dashboard Widget Administration Screen API 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** 10 * Registers dashboard widgets. 11 * 12 * Handles POST data, sets up filters. 13 * 14 * @since 2.5.0 15 * 16 * @global array $wp_registered_widgets 17 * @global array $wp_registered_widget_controls 18 * @global callable[] $wp_dashboard_control_callbacks 19 */ 20 function wp_dashboard_setup() { 21 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks; 22 23 $screen = get_current_screen(); 24 25 /* Register Widgets and Controls */ 26 $wp_dashboard_control_callbacks = array(); 27 28 // Browser version 29 $check_browser = wp_check_browser_version(); 30 31 if ( $check_browser && $check_browser['upgrade'] ) { 32 add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' ); 33 34 if ( $check_browser['insecure'] ) { 35 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' ); 36 } else { 37 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' ); 38 } 39 } 40 41 // PHP Version. 42 $check_php = wp_check_php_version(); 43 44 if ( $check_php && current_user_can( 'update_php' ) ) { 45 // If "not acceptable" the widget will be shown. 46 if ( isset( $check_php['is_acceptable'] ) && ! $check_php['is_acceptable'] ) { 47 add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' ); 48 49 if ( $check_php['is_lower_than_future_minimum'] ) { 50 wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' ); 51 } else { 52 wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Recommended' ), 'wp_dashboard_php_nag' ); 53 } 54 } 55 } 56 57 // Site Health. 58 if ( current_user_can( 'view_site_health_checks' ) && ! is_network_admin() ) { 59 if ( ! class_exists( 'WP_Site_Health' ) ) { 60 require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php'; 61 } 62 63 WP_Site_Health::get_instance(); 64 65 wp_enqueue_style( 'site-health' ); 66 wp_enqueue_script( 'site-health' ); 67 68 wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' ); 69 } 70 71 // Right Now. 72 if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) { 73 wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' ); 74 } 75 76 if ( is_network_admin() ) { 77 wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' ); 78 } 79 80 // Activity Widget. 81 if ( is_blog_admin() ) { 82 wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' ); 83 } 84 85 // QuickPress Widget. 86 if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) { 87 $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Your Recent Drafts' ) ); 88 wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' ); 89 } 90 91 // WordPress Events and News. 92 wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' ); 93 94 if ( is_network_admin() ) { 95 96 /** 97 * Fires after core widgets for the Network Admin dashboard have been registered. 98 * 99 * @since 3.1.0 100 */ 101 do_action( 'wp_network_dashboard_setup' ); 102 103 /** 104 * Filters the list of widgets to load for the Network Admin dashboard. 105 * 106 * @since 3.1.0 107 * 108 * @param string[] $dashboard_widgets An array of dashboard widget IDs. 109 */ 110 $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() ); 111 } elseif ( is_user_admin() ) { 112 113 /** 114 * Fires after core widgets for the User Admin dashboard have been registered. 115 * 116 * @since 3.1.0 117 */ 118 do_action( 'wp_user_dashboard_setup' ); 119 120 /** 121 * Filters the list of widgets to load for the User Admin dashboard. 122 * 123 * @since 3.1.0 124 * 125 * @param string[] $dashboard_widgets An array of dashboard widget IDs. 126 */ 127 $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() ); 128 } else { 129 130 /** 131 * Fires after core widgets for the admin dashboard have been registered. 132 * 133 * @since 2.5.0 134 */ 135 do_action( 'wp_dashboard_setup' ); 136 137 /** 138 * Filters the list of widgets to load for the admin dashboard. 139 * 140 * @since 2.5.0 141 * 142 * @param string[] $dashboard_widgets An array of dashboard widget IDs. 143 */ 144 $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() ); 145 } 146 147 foreach ( $dashboard_widgets as $widget_id ) { 148 $name = empty( $wp_registered_widgets[ $widget_id ]['all_link'] ) ? $wp_registered_widgets[ $widget_id ]['name'] : $wp_registered_widgets[ $widget_id ]['name'] . " <a href='{$wp_registered_widgets[$widget_id]['all_link']}' class='edit-box open-box'>" . __( 'View all' ) . '</a>'; 149 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] ); 150 } 151 152 if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) { 153 check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' ); 154 ob_start(); // Hack - but the same hack wp-admin/widgets.php uses. 155 wp_dashboard_trigger_widget_control( $_POST['widget_id'] ); 156 ob_end_clean(); 157 wp_redirect( remove_query_arg( 'edit' ) ); 158 exit; 159 } 160 161 /** This action is documented in wp-admin/includes/meta-boxes.php */ 162 do_action( 'do_meta_boxes', $screen->id, 'normal', '' ); 163 164 /** This action is documented in wp-admin/includes/meta-boxes.php */ 165 do_action( 'do_meta_boxes', $screen->id, 'side', '' ); 166 } 167 168 /** 169 * Adds a new dashboard widget. 170 * 171 * @since 2.7.0 172 * @since 5.6.0 The `$context` and `$priority` parameters were added. 173 * 174 * @global callable[] $wp_dashboard_control_callbacks 175 * 176 * @param string $widget_id Widget ID (used in the 'id' attribute for the widget). 177 * @param string $widget_name Title of the widget. 178 * @param callable $callback Function that fills the widget with the desired content. 179 * The function should echo its output. 180 * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null. 181 * @param array $callback_args Optional. Data that should be set as the $args property of the widget array 182 * (which is the second parameter passed to your callback). Default null. 183 * @param string $context Optional. The context within the screen where the box should display. 184 * Accepts 'normal', 'side', 'column3', or 'column4'. Default 'normal'. 185 * @param string $priority Optional. The priority within the context where the box should show. 186 * Accepts 'high', 'core', 'default', or 'low'. Default 'core'. 187 */ 188 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null, $context = 'normal', $priority = 'core' ) { 189 global $wp_dashboard_control_callbacks; 190 191 $screen = get_current_screen(); 192 193 $private_callback_args = array( '__widget_basename' => $widget_name ); 194 195 if ( is_null( $callback_args ) ) { 196 $callback_args = $private_callback_args; 197 } elseif ( is_array( $callback_args ) ) { 198 $callback_args = array_merge( $callback_args, $private_callback_args ); 199 } 200 201 if ( $control_callback && is_callable( $control_callback ) && current_user_can( 'edit_dashboard' ) ) { 202 $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback; 203 204 if ( isset( $_GET['edit'] ) && $widget_id === $_GET['edit'] ) { 205 list($url) = explode( '#', add_query_arg( 'edit', false ), 2 ); 206 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>'; 207 $callback = '_wp_dashboard_control_callback'; 208 } else { 209 list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 ); 210 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>'; 211 } 212 } 213 214 $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' ); 215 216 if ( in_array( $widget_id, $side_widgets, true ) ) { 217 $context = 'side'; 218 } 219 220 $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' ); 221 222 if ( in_array( $widget_id, $high_priority_widgets, true ) ) { 223 $priority = 'high'; 224 } 225 226 if ( empty( $context ) ) { 227 $context = 'normal'; 228 } 229 230 if ( empty( $priority ) ) { 231 $priority = 'core'; 232 } 233 234 add_meta_box( $widget_id, $widget_name, $callback, $screen, $context, $priority, $callback_args ); 235 } 236 237 /** 238 * Outputs controls for the current dashboard widget. 239 * 240 * @access private 241 * @since 2.7.0 242 * 243 * @param mixed $dashboard 244 * @param array $meta_box 245 */ 246 function _wp_dashboard_control_callback( $dashboard, $meta_box ) { 247 echo '<form method="post" class="dashboard-widget-control-form wp-clearfix">'; 248 wp_dashboard_trigger_widget_control( $meta_box['id'] ); 249 wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' ); 250 echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />'; 251 submit_button( __( 'Save Changes' ) ); 252 echo '</form>'; 253 } 254 255 /** 256 * Displays the dashboard. 257 * 258 * @since 2.5.0 259 */ 260 function wp_dashboard() { 261 $screen = get_current_screen(); 262 $columns = absint( $screen->get_columns() ); 263 $columns_css = ''; 264 265 if ( $columns ) { 266 $columns_css = " columns-$columns"; 267 } 268 ?> 269 <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>"> 270 <div id="postbox-container-1" class="postbox-container"> 271 <?php do_meta_boxes( $screen->id, 'normal', '' ); ?> 272 </div> 273 <div id="postbox-container-2" class="postbox-container"> 274 <?php do_meta_boxes( $screen->id, 'side', '' ); ?> 275 </div> 276 <div id="postbox-container-3" class="postbox-container"> 277 <?php do_meta_boxes( $screen->id, 'column3', '' ); ?> 278 </div> 279 <div id="postbox-container-4" class="postbox-container"> 280 <?php do_meta_boxes( $screen->id, 'column4', '' ); ?> 281 </div> 282 </div> 283 284 <?php 285 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); 286 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); 287 } 288 289 // 290 // Dashboard Widgets. 291 // 292 293 /** 294 * Dashboard widget that displays some basic stats about the site. 295 * 296 * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8. 297 * 298 * @since 2.7.0 299 */ 300 function wp_dashboard_right_now() { 301 ?> 302 <div class="main"> 303 <ul> 304 <?php 305 // Posts and Pages. 306 foreach ( array( 'post', 'page' ) as $post_type ) { 307 $num_posts = wp_count_posts( $post_type ); 308 309 if ( $num_posts && $num_posts->publish ) { 310 if ( 'post' === $post_type ) { 311 /* translators: %s: Number of posts. */ 312 $text = _n( '%s Published post', '%s Published posts', $num_posts->publish ); 313 } else { 314 /* translators: %s: Number of pages. */ 315 $text = _n( '%s Published page', '%s Published pages', $num_posts->publish ); 316 } 317 318 $text = sprintf( $text, number_format_i18n( $num_posts->publish ) ); 319 $post_type_object = get_post_type_object( $post_type ); 320 321 if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) { 322 $url = add_query_arg( 323 array( 324 'post_status' => 'publish', 325 'post_type' => $post_type, 326 ), 327 admin_url( 'edit.php' ) 328 ); 329 printf( '<li class="%1$s-count"><a href="%2$s">%3$s</a></li>', $post_type, esc_url( $url ), esc_html( $text ) ); 330 } else { 331 printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text ); 332 } 333 } 334 } 335 336 // Comments. 337 $num_comm = wp_count_comments(); 338 339 if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) { 340 /* translators: %s: Number of comments. */ 341 $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) ); 342 ?> 343 <li class="comment-count"> 344 <a href="edit-comments.php"><?php echo $text; ?></a> 345 </li> 346 <?php 347 $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated ); 348 /* translators: %s: Number of comments. */ 349 $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n ); 350 ?> 351 <li class="comment-mod-count<?php echo ! $num_comm->moderated ? ' hidden' : ''; ?>"> 352 <a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a> 353 </li> 354 <?php 355 } 356 357 /** 358 * Filters the array of extra elements to list in the 'At a Glance' 359 * dashboard widget. 360 * 361 * Prior to 3.8.0, the widget was named 'Right Now'. Each element 362 * is wrapped in list-item tags on output. 363 * 364 * @since 3.8.0 365 * 366 * @param string[] $items Array of extra 'At a Glance' widget items. 367 */ 368 $elements = apply_filters( 'dashboard_glance_items', array() ); 369 370 if ( $elements ) { 371 echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n"; 372 } 373 374 ?> 375 </ul> 376 <?php 377 update_right_now_message(); 378 379 // Check if search engines are asked not to index this site. 380 if ( ! is_network_admin() && ! is_user_admin() 381 && current_user_can( 'manage_options' ) && ! get_option( 'blog_public' ) 382 ) { 383 384 /** 385 * Filters the link title attribute for the 'Search engines discouraged' 386 * message displayed in the 'At a Glance' dashboard widget. 387 * 388 * Prior to 3.8.0, the widget was named 'Right Now'. 389 * 390 * @since 3.0.0 391 * @since 4.5.0 The default for `$title` was updated to an empty string. 392 * 393 * @param string $title Default attribute text. 394 */ 395 $title = apply_filters( 'privacy_on_link_title', '' ); 396 397 /** 398 * Filters the link label for the 'Search engines discouraged' message 399 * displayed in the 'At a Glance' dashboard widget. 400 * 401 * Prior to 3.8.0, the widget was named 'Right Now'. 402 * 403 * @since 3.0.0 404 * 405 * @param string $content Default text. 406 */ 407 $content = apply_filters( 'privacy_on_link_text', __( 'Search engines discouraged' ) ); 408 409 $title_attr = '' === $title ? '' : " title='$title'"; 410 411 echo "<p class='search-engines-info'><a href='options-reading.php'$title_attr>$content</a></p>"; 412 } 413 ?> 414 </div> 415 <?php 416 /* 417 * activity_box_end has a core action, but only prints content when multisite. 418 * Using an output buffer is the only way to really check if anything's displayed here. 419 */ 420 ob_start(); 421 422 /** 423 * Fires at the end of the 'At a Glance' dashboard widget. 424 * 425 * Prior to 3.8.0, the widget was named 'Right Now'. 426 * 427 * @since 2.5.0 428 */ 429 do_action( 'rightnow_end' ); 430 431 /** 432 * Fires at the end of the 'At a Glance' dashboard widget. 433 * 434 * Prior to 3.8.0, the widget was named 'Right Now'. 435 * 436 * @since 2.0.0 437 */ 438 do_action( 'activity_box_end' ); 439 440 $actions = ob_get_clean(); 441 442 if ( ! empty( $actions ) ) : 443 ?> 444 <div class="sub"> 445 <?php echo $actions; ?> 446 </div> 447 <?php 448 endif; 449 } 450 451 /** 452 * @since 3.1.0 453 */ 454 function wp_network_dashboard_right_now() { 455 $actions = array(); 456 457 if ( current_user_can( 'create_sites' ) ) { 458 $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>'; 459 } 460 if ( current_user_can( 'create_users' ) ) { 461 $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>'; 462 } 463 464 $c_users = get_user_count(); 465 $c_blogs = get_blog_count(); 466 467 /* translators: %s: Number of users on the network. */ 468 $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) ); 469 /* translators: %s: Number of sites on the network. */ 470 $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) ); 471 472 /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */ 473 $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text ); 474 475 if ( $actions ) { 476 echo '<ul class="subsubsub">'; 477 foreach ( $actions as $class => $action ) { 478 $actions[ $class ] = "\t<li class='$class'>$action"; 479 } 480 echo implode( " |</li>\n", $actions ) . "</li>\n"; 481 echo '</ul>'; 482 } 483 ?> 484 <br class="clear" /> 485 486 <p class="youhave"><?php echo $sentence; ?></p> 487 488 489 <?php 490 /** 491 * Fires in the Network Admin 'Right Now' dashboard widget 492 * just before the user and site search form fields. 493 * 494 * @since MU (3.0.0) 495 */ 496 do_action( 'wpmuadminresult' ); 497 ?> 498 499 <form action="<?php echo esc_url( network_admin_url( 'users.php' ) ); ?>" method="get"> 500 <p> 501 <label class="screen-reader-text" for="search-users"> 502 <?php 503 /* translators: Hidden accessibility text. */ 504 _e( 'Search Users' ); 505 ?> 506 </label> 507 <input type="search" name="s" value="" size="30" autocomplete="off" id="search-users" /> 508 <?php submit_button( __( 'Search Users' ), '', false, false, array( 'id' => 'submit_users' ) ); ?> 509 </p> 510 </form> 511 512 <form action="<?php echo esc_url( network_admin_url( 'sites.php' ) ); ?>" method="get"> 513 <p> 514 <label class="screen-reader-text" for="search-sites"> 515 <?php 516 /* translators: Hidden accessibility text. */ 517 _e( 'Search Sites' ); 518 ?> 519 </label> 520 <input type="search" name="s" value="" size="30" autocomplete="off" id="search-sites" /> 521 <?php submit_button( __( 'Search Sites' ), '', false, false, array( 'id' => 'submit_sites' ) ); ?> 522 </p> 523 </form> 524 <?php 525 /** 526 * Fires at the end of the 'Right Now' widget in the Network Admin dashboard. 527 * 528 * @since MU (3.0.0) 529 */ 530 do_action( 'mu_rightnow_end' ); 531 532 /** 533 * Fires at the end of the 'Right Now' widget in the Network Admin dashboard. 534 * 535 * @since MU (3.0.0) 536 */ 537 do_action( 'mu_activity_box_end' ); 538 } 539 540 /** 541 * Displays the Quick Draft widget. 542 * 543 * @since 3.8.0 544 * @since 7.1.0 Added $notice_type parameter. 545 * 546 * @global int $post_ID 547 * 548 * @param string|false $message Optional. Error or success message. Default false. 549 * @param string $notice_type Optional. Admin notice type. Default 'error'. 550 */ 551 function wp_dashboard_quick_press( $message = false, $notice_type = 'error' ) { 552 global $post_ID; 553 554 if ( ! current_user_can( 'edit_posts' ) ) { 555 return; 556 } 557 558 // Check if a new auto-draft (= no new post_ID) is needed or if the old can be used. 559 $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID. 560 561 if ( $last_post_id ) { 562 $post = get_post( $last_post_id ); 563 564 if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore. 565 $post = get_default_post_to_edit( 'post', true ); 566 update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. 567 } else { 568 $post->post_title = ''; // Remove the auto draft title. 569 } 570 } else { 571 $post = get_default_post_to_edit( 'post', true ); 572 $user_id = get_current_user_id(); 573 574 // Don't create an option if this is a super admin who does not belong to this site. 575 if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) { 576 update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID. 577 } 578 } 579 580 $post_ID = (int) $post->ID; 581 ?> 582 583 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="hide-if-no-js"> 584 585 <?php 586 if ( $message ) { 587 wp_admin_notice( 588 $message, 589 array( 590 'type' => $notice_type, 591 'attributes' => array( 592 'role' => 'alert', 593 ), 594 ) 595 ); 596 } 597 ?> 598 599 <div class="input-text-wrap" id="title-wrap"> 600 <label for="title"> 601 <?php 602 /** This filter is documented in wp-admin/edit-form-advanced.php */ 603 echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); 604 ?> 605 </label> 606 <input type="text" name="post_title" id="title" autocomplete="off" /> 607 </div> 608 609 <div class="textarea-wrap" id="description-wrap"> 610 <label for="content"><?php _e( 'Content' ); ?></label> 611 <textarea name="content" id="content" placeholder="<?php esc_attr_e( 'What’s on your mind?' ); ?>" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea> 612 </div> 613 614 <p class="submit"> 615 <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" /> 616 <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" /> 617 <input type="hidden" name="post_type" value="post" /> 618 <?php wp_nonce_field( 'add-post' ); ?> 619 <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?> 620 <br class="clear" /> 621 </p> 622 623 </form> 624 <?php 625 wp_dashboard_recent_drafts(); 626 } 627 628 /** 629 * Show recent drafts of the user on the dashboard. 630 * 631 * @since 2.7.0 632 * 633 * @param WP_Post[]|false $drafts Optional. Array of posts to display. Default false. 634 */ 635 function wp_dashboard_recent_drafts( $drafts = false ) { 636 if ( ! $drafts ) { 637 $query_args = array( 638 'post_type' => 'post', 639 'post_status' => 'draft', 640 'author' => get_current_user_id(), 641 'posts_per_page' => 4, 642 'orderby' => 'modified', 643 'order' => 'DESC', 644 ); 645 646 /** 647 * Filters the post query arguments for the 'Recent Drafts' dashboard widget. 648 * 649 * @since 4.4.0 650 * 651 * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget. 652 */ 653 $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args ); 654 655 $drafts = get_posts( $query_args ); 656 if ( ! $drafts ) { 657 return; 658 } 659 } 660 661 echo '<div class="drafts">'; 662 663 if ( count( $drafts ) > 3 ) { 664 printf( 665 '<p class="view-all"><a href="%s">%s</a></p>' . "\n", 666 esc_url( admin_url( 'edit.php?post_status=draft' ) ), 667 __( 'View all drafts' ) 668 ); 669 } 670 671 echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n"; 672 echo '<ul>'; 673 674 /* translators: Maximum number of words used in a preview of a draft on the dashboard. */ 675 $draft_length = (int) _x( '10', 'draft_length' ); 676 677 $drafts = array_slice( $drafts, 0, 3 ); 678 foreach ( $drafts as $draft ) { 679 $url = get_edit_post_link( $draft->ID ); 680 $title = _draft_or_post_title( $draft->ID ); 681 682 echo "<li>\n"; 683 printf( 684 '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>', 685 esc_url( $url ), 686 /* translators: %s: Post title. */ 687 esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ), 688 esc_html( $title ), 689 get_the_time( 'c', $draft ), 690 get_the_time( __( 'F j, Y' ), $draft ) 691 ); 692 693 $the_content = wp_trim_words( $draft->post_content, $draft_length ); 694 695 if ( $the_content ) { 696 echo '<p class="draft-content">' . $the_content . '</p>'; 697 } 698 echo "</li>\n"; 699 } 700 701 echo "</ul>\n"; 702 echo '</div>'; 703 } 704 705 /** 706 * Outputs a row for the Recent Comments widget. 707 * 708 * @access private 709 * @since 2.7.0 710 * 711 * @global WP_Comment $comment Global comment object. 712 * 713 * @param WP_Comment $comment The current comment. 714 * @param bool $show_date Optional. Whether to display the date. 715 */ 716 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) { 717 $GLOBALS['comment'] = clone $comment; 718 719 if ( $comment->comment_post_ID > 0 ) { 720 $comment_post_title = _draft_or_post_title( $comment->comment_post_ID ); 721 $comment_post_url = get_the_permalink( $comment->comment_post_ID ); 722 $comment_post_link = '<a href="' . esc_url( $comment_post_url ) . '">' . $comment_post_title . '</a>'; 723 } else { 724 $comment_post_link = ''; 725 } 726 727 $actions_string = ''; 728 if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) { 729 // Pre-order it: Approve | Reply | Edit | Spam | Trash. 730 $actions = array( 731 'approve' => '', 732 'unapprove' => '', 733 'reply' => '', 734 'edit' => '', 735 'spam' => '', 736 'trash' => '', 737 'delete' => '', 738 'view' => '', 739 ); 740 741 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'approve-comment_' . $comment->comment_ID ) ); 742 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( 'delete-comment_' . $comment->comment_ID ) ); 743 744 $action_string = 'comment.php?action=%s&p=' . $comment->comment_post_ID . '&c=' . $comment->comment_ID . '&%s'; 745 746 $approve_url = sprintf( $action_string, 'approvecomment', $approve_nonce ); 747 $unapprove_url = sprintf( $action_string, 'unapprovecomment', $approve_nonce ); 748 $spam_url = sprintf( $action_string, 'spamcomment', $del_nonce ); 749 $trash_url = sprintf( $action_string, 'trashcomment', $del_nonce ); 750 $delete_url = sprintf( $action_string, 'deletecomment', $del_nonce ); 751 752 $actions['approve'] = sprintf( 753 '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>', 754 esc_url( $approve_url ), 755 "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved", 756 esc_attr__( 'Approve this comment' ), 757 __( 'Approve' ) 758 ); 759 760 $actions['unapprove'] = sprintf( 761 '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>', 762 esc_url( $unapprove_url ), 763 "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved", 764 esc_attr__( 'Unapprove this comment' ), 765 __( 'Unapprove' ) 766 ); 767 768 $actions['edit'] = sprintf( 769 '<a href="%s" aria-label="%s">%s</a>', 770 "comment.php?action=editcomment&c={$comment->comment_ID}", 771 esc_attr__( 'Edit this comment' ), 772 __( 'Edit' ) 773 ); 774 775 $actions['reply'] = sprintf( 776 '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>', 777 $comment->comment_ID, 778 $comment->comment_post_ID, 779 esc_attr__( 'Reply to this comment' ), 780 /* translators: Comment reply button text. */ 781 _x( 'Reply', 'verb' ) 782 ); 783 784 $actions['spam'] = sprintf( 785 '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 786 esc_url( $spam_url ), 787 "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1", 788 esc_attr__( 'Mark this comment as spam' ), 789 /* translators: "Mark as spam" link. */ 790 _x( 'Spam', 'verb' ) 791 ); 792 793 if ( ! EMPTY_TRASH_DAYS ) { 794 $actions['delete'] = sprintf( 795 '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 796 esc_url( $delete_url ), 797 "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1", 798 esc_attr__( 'Delete this comment permanently' ), 799 __( 'Delete Permanently' ) 800 ); 801 } else { 802 $actions['trash'] = sprintf( 803 '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>', 804 esc_url( $trash_url ), 805 "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1", 806 esc_attr__( 'Move this comment to the Trash' ), 807 _x( 'Trash', 'verb' ) 808 ); 809 } 810 811 $actions['view'] = sprintf( 812 '<a class="comment-link" href="%s" aria-label="%s">%s</a>', 813 esc_url( get_comment_link( $comment ) ), 814 esc_attr__( 'View this comment' ), 815 __( 'View' ) 816 ); 817 818 /** This filter is documented in wp-admin/includes/class-wp-comments-list-table.php */ 819 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); 820 821 $i = 0; 822 823 foreach ( $actions as $action => $link ) { 824 ++$i; 825 826 if ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) 827 || 1 === $i 828 ) { 829 $separator = ''; 830 } else { 831 $separator = ' | '; 832 } 833 834 // Reply and quickedit need a hide-if-no-js span. 835 if ( 'reply' === $action || 'quickedit' === $action ) { 836 $action .= ' hide-if-no-js'; 837 } 838 839 if ( 'view' === $action && '1' !== $comment->comment_approved ) { 840 $action .= ' hidden'; 841 } 842 843 $actions_string .= "<span class='$action'>{$separator}{$link}</span>"; 844 } 845 } 846 ?> 847 848 <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>> 849 850 <?php 851 $comment_row_class = ''; 852 853 if ( get_option( 'show_avatars' ) ) { 854 echo get_avatar( $comment, 50, 'mystery' ); 855 $comment_row_class .= ' has-avatar'; 856 } 857 ?> 858 859 <?php if ( ! $comment->comment_type || 'comment' === $comment->comment_type ) : ?> 860 861 <div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>"> 862 <p class="comment-meta"> 863 <?php 864 // Comments might not have a post they relate to, e.g. programmatically created ones. 865 if ( $comment_post_link ) { 866 printf( 867 /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */ 868 __( 'From %1$s on %2$s %3$s' ), 869 '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>', 870 $comment_post_link, 871 '<span class="approve">' . __( '[Pending]' ) . '</span>' 872 ); 873 } else { 874 printf( 875 /* translators: 1: Comment author, 2: Notification if the comment is pending. */ 876 __( 'From %1$s %2$s' ), 877 '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>', 878 '<span class="approve">' . __( '[Pending]' ) . '</span>' 879 ); 880 } 881 ?> 882 </p> 883 884 <?php 885 else : 886 switch ( $comment->comment_type ) { 887 case 'pingback': 888 $type = __( 'Pingback' ); 889 break; 890 case 'trackback': 891 $type = __( 'Trackback' ); 892 break; 893 default: 894 $type = ucwords( $comment->comment_type ); 895 } 896 $type = esc_html( $type ); 897 ?> 898 <div class="dashboard-comment-wrap has-row-actions"> 899 <p class="comment-meta"> 900 <?php 901 // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones. 902 if ( $comment_post_link ) { 903 printf( 904 /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */ 905 _x( '%1$s on %2$s %3$s', 'dashboard' ), 906 "<strong>$type</strong>", 907 $comment_post_link, 908 '<span class="approve">' . __( '[Pending]' ) . '</span>' 909 ); 910 } else { 911 printf( 912 /* translators: 1: Type of comment, 2: Notification if the comment is pending. */ 913 _x( '%1$s %2$s', 'dashboard' ), 914 "<strong>$type</strong>", 915 '<span class="approve">' . __( '[Pending]' ) . '</span>' 916 ); 917 } 918 ?> 919 </p> 920 <p class="comment-author"><?php comment_author_link( $comment ); ?></p> 921 922 <?php endif; // comment_type ?> 923 <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote> 924 <?php if ( $actions_string ) : ?> 925 <p class="row-actions"><?php echo $actions_string; ?></p> 926 <?php endif; ?> 927 </div> 928 </li> 929 <?php 930 $GLOBALS['comment'] = null; 931 } 932 933 /** 934 * Outputs the Activity widget. 935 * 936 * Callback function for {@see 'dashboard_activity'}. 937 * 938 * @since 3.8.0 939 */ 940 function wp_dashboard_site_activity() { 941 942 echo '<div id="activity-widget">'; 943 944 $future_posts = wp_dashboard_recent_posts( 945 array( 946 'max' => 5, 947 'status' => 'future', 948 'order' => 'ASC', 949 'title' => __( 'Publishing Soon' ), 950 'id' => 'future-posts', 951 ) 952 ); 953 $recent_posts = wp_dashboard_recent_posts( 954 array( 955 'max' => 5, 956 'status' => 'publish', 957 'order' => 'DESC', 958 'title' => __( 'Recently Published' ), 959 'id' => 'published-posts', 960 ) 961 ); 962 963 $recent_comments = wp_dashboard_recent_comments(); 964 965 if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) { 966 echo '<div class="no-activity">'; 967 echo '<p>' . __( 'No activity yet!' ) . '</p>'; 968 echo '</div>'; 969 } 970 971 echo '</div>'; 972 } 973 974 /** 975 * Generates Publishing Soon and Recently Published sections. 976 * 977 * @since 3.8.0 978 * 979 * @param array $args { 980 * An array of query and display arguments. 981 * 982 * @type int $max Number of posts to display. 983 * @type string $status Post status. 984 * @type string $order Designates ascending ('ASC') or descending ('DESC') order. 985 * @type string $title Section title. 986 * @type string $id The container id. 987 * } 988 * @return bool False if no posts were found. True otherwise. 989 */ 990 function wp_dashboard_recent_posts( $args ) { 991 $query_args = array( 992 'post_type' => 'post', 993 'post_status' => $args['status'], 994 'orderby' => 'date', 995 'order' => $args['order'], 996 'posts_per_page' => (int) $args['max'], 997 'no_found_rows' => true, 998 'cache_results' => true, 999 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable', 1000 ); 1001 1002 /** 1003 * Filters the query arguments used for the Recent Posts widget. 1004 * 1005 * @since 4.2.0 1006 * 1007 * @param array $query_args The arguments passed to WP_Query to produce the list of posts. 1008 */ 1009 $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args ); 1010 1011 $posts = new WP_Query( $query_args ); 1012 1013 if ( $posts->have_posts() ) { 1014 1015 echo '<div id="' . $args['id'] . '" class="activity-block">'; 1016 1017 echo '<h3>' . $args['title'] . '</h3>'; 1018 1019 echo '<ul>'; 1020 1021 $today = current_time( 'Y-m-d' ); 1022 $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' ); 1023 $year = current_time( 'Y' ); 1024 1025 while ( $posts->have_posts() ) { 1026 $posts->the_post(); 1027 1028 $time = get_the_time( 'U' ); 1029 1030 if ( ! is_int( $time ) ) { 1031 /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */ 1032 $date = get_the_date( __( 'M jS Y' ) ); 1033 } elseif ( gmdate( 'Y-m-d', $time ) === $today ) { 1034 $date = __( 'Today' ); 1035 } elseif ( gmdate( 'Y-m-d', $time ) === $tomorrow ) { 1036 $date = __( 'Tomorrow' ); 1037 } elseif ( gmdate( 'Y', $time ) !== $year ) { 1038 /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/manual/datetime.format.php */ 1039 $date = date_i18n( __( 'M jS Y' ), $time ); 1040 } else { 1041 /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/manual/datetime.format.php */ 1042 $date = date_i18n( __( 'M jS' ), $time ); 1043 } 1044 1045 // Use the post edit link for those who can edit, the permalink otherwise. 1046 $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink(); 1047 1048 $draft_or_post_title = _draft_or_post_title(); 1049 printf( 1050 '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>', 1051 /* translators: 1: Relative date, 2: Time. */ 1052 sprintf( _x( '%1$s, %2$s', 'dashboard' ), $date, get_the_time() ), 1053 $recent_post_link, 1054 /* translators: %s: Post title. */ 1055 esc_attr( sprintf( __( 'Edit “%s”' ), $draft_or_post_title ) ), 1056 $draft_or_post_title 1057 ); 1058 } 1059 1060 echo '</ul>'; 1061 echo '</div>'; 1062 1063 } else { 1064 return false; 1065 } 1066 1067 wp_reset_postdata(); 1068 1069 return true; 1070 } 1071 1072 /** 1073 * Show Comments section. 1074 * 1075 * @since 3.8.0 1076 * 1077 * @param int $total_items Optional. Number of comments to query. Default 5. 1078 * @return bool False if no comments were found. True otherwise. 1079 */ 1080 function wp_dashboard_recent_comments( $total_items = 5 ) { 1081 // Select all comment types and filter out spam later for better query performance. 1082 $comments = array(); 1083 1084 $comments_query = array( 1085 'number' => $total_items * 5, 1086 'offset' => 0, 1087 ); 1088 1089 if ( ! current_user_can( 'edit_posts' ) ) { 1090 $comments_query['status'] = 'approve'; 1091 } 1092 1093 $comments_count = 0; 1094 do { 1095 $possible = get_comments( $comments_query ); 1096 1097 if ( empty( $possible ) || ! is_array( $possible ) ) { 1098 break; 1099 } 1100 1101 foreach ( $possible as $comment ) { 1102 if ( ! current_user_can( 'edit_post', $comment->comment_post_ID ) 1103 && ( post_password_required( $comment->comment_post_ID ) 1104 || ! current_user_can( 'read_post', $comment->comment_post_ID ) ) 1105 ) { 1106 // The user has no access to the post and thus cannot see the comments. 1107 continue; 1108 } 1109 1110 $comments[] = $comment; 1111 $comments_count = count( $comments ); 1112 1113 if ( $comments_count === $total_items ) { 1114 break 2; 1115 } 1116 } 1117 1118 $comments_query['offset'] += $comments_query['number']; 1119 $comments_query['number'] = $total_items * 10; 1120 } while ( $comments_count < $total_items ); 1121 1122 if ( $comments ) { 1123 echo '<div id="latest-comments" class="activity-block table-view-list">'; 1124 echo '<h3>' . __( 'Recent Comments' ) . '</h3>'; 1125 1126 echo '<ul id="the-comment-list" data-wp-lists="list:comment">'; 1127 foreach ( $comments as $comment ) { 1128 _wp_dashboard_recent_comments_row( $comment ); 1129 } 1130 echo '</ul>'; 1131 1132 if ( current_user_can( 'edit_posts' ) ) { 1133 echo '<h3 class="screen-reader-text">' . 1134 /* translators: Hidden accessibility text. */ 1135 __( 'View more comments' ) . 1136 '</h3>'; 1137 _get_list_table( 'WP_Comments_List_Table' )->views(); 1138 } 1139 1140 wp_comment_reply( -1, false, 'dashboard', false ); 1141 wp_comment_trashnotice(); 1142 1143 echo '</div>'; 1144 } else { 1145 return false; 1146 } 1147 return true; 1148 } 1149 1150 /** 1151 * Display generic dashboard RSS widget feed. 1152 * 1153 * @since 2.5.0 1154 * 1155 * @param string $widget_id 1156 */ 1157 function wp_dashboard_rss_output( $widget_id ) { 1158 $widgets = get_option( 'dashboard_widget_options' ); 1159 echo '<div class="rss-widget">'; 1160 wp_widget_rss_output( $widgets[ $widget_id ] ); 1161 echo '</div>'; 1162 } 1163 1164 /** 1165 * Checks to see if all of the feed url in $check_urls are cached. 1166 * 1167 * If $check_urls is empty, look for the rss feed url found in the dashboard 1168 * widget options of $widget_id. If cached, call $callback, a function that 1169 * echoes out output for this widget. If not cache, echo a "Loading..." stub 1170 * which is later replaced by Ajax call (see top of /wp-admin/index.php) 1171 * 1172 * @since 2.5.0 1173 * @since 5.3.0 Formalized the existing and already documented `...$args` parameter 1174 * by adding it to the function signature. 1175 * 1176 * @param string $widget_id The widget ID. 1177 * @param callable $callback The callback function used to display each feed. 1178 * @param array $check_urls RSS feeds. 1179 * @param mixed ...$args Optional additional parameters to pass to the callback function. 1180 * @return bool True on success, false on failure. 1181 */ 1182 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) { 1183 $doing_ajax = wp_doing_ajax(); 1184 $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p>'; 1185 $loading .= wp_get_admin_notice( 1186 __( 'This widget requires JavaScript.' ), 1187 array( 1188 'type' => 'error', 1189 'additional_classes' => array( 'inline', 'hide-if-js' ), 1190 ) 1191 ); 1192 1193 if ( empty( $check_urls ) ) { 1194 $widgets = get_option( 'dashboard_widget_options' ); 1195 1196 if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) { 1197 echo $loading; 1198 return false; 1199 } 1200 1201 $check_urls = array( $widgets[ $widget_id ]['url'] ); 1202 } 1203 1204 $locale = get_user_locale(); 1205 $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); 1206 $output = get_transient( $cache_key ); 1207 1208 if ( false !== $output ) { 1209 echo $output; 1210 return true; 1211 } 1212 1213 if ( ! $doing_ajax ) { 1214 echo $loading; 1215 return false; 1216 } 1217 1218 if ( $callback && is_callable( $callback ) ) { 1219 array_unshift( $args, $widget_id, $check_urls ); 1220 ob_start(); 1221 call_user_func_array( $callback, $args ); 1222 // Default lifetime in cache of 12 hours (same as the feeds). 1223 set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); 1224 } 1225 1226 return true; 1227 } 1228 1229 // 1230 // Dashboard Widgets Controls. 1231 // 1232 1233 /** 1234 * Calls widget control callback. 1235 * 1236 * @since 2.5.0 1237 * 1238 * @global callable[] $wp_dashboard_control_callbacks 1239 * 1240 * @param int|false $widget_control_id Optional. Registered widget ID. Default false. 1241 */ 1242 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) { 1243 global $wp_dashboard_control_callbacks; 1244 1245 if ( is_scalar( $widget_control_id ) && $widget_control_id 1246 && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) 1247 && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) 1248 ) { 1249 call_user_func( 1250 $wp_dashboard_control_callbacks[ $widget_control_id ], 1251 '', 1252 array( 1253 'id' => $widget_control_id, 1254 'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ], 1255 ) 1256 ); 1257 } 1258 } 1259 1260 /** 1261 * Sets up the RSS dashboard widget control and $args to be used as input to wp_widget_rss_form(). 1262 * 1263 * Handles POST data from RSS-type widgets. 1264 * 1265 * @since 2.5.0 1266 * 1267 * @param string $widget_id 1268 * @param array $form_inputs 1269 */ 1270 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) { 1271 $widget_options = get_option( 'dashboard_widget_options' ); 1272 1273 if ( ! $widget_options ) { 1274 $widget_options = array(); 1275 } 1276 1277 if ( ! isset( $widget_options[ $widget_id ] ) ) { 1278 $widget_options[ $widget_id ] = array(); 1279 } 1280 1281 $number = 1; // Hack to use wp_widget_rss_form(). 1282 1283 $widget_options[ $widget_id ]['number'] = $number; 1284 1285 if ( 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) { 1286 $_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] ); 1287 $widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] ); 1288 $widget_options[ $widget_id ]['number'] = $number; 1289 1290 // Title is optional. If blank, fill it if possible. 1291 if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) { 1292 $rss = fetch_feed( $widget_options[ $widget_id ]['url'] ); 1293 if ( is_wp_error( $rss ) ) { 1294 $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) ); 1295 } else { 1296 $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) ); 1297 $rss->__destruct(); 1298 unset( $rss ); 1299 } 1300 } 1301 1302 update_option( 'dashboard_widget_options', $widget_options, false ); 1303 1304 $locale = get_user_locale(); 1305 $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale ); 1306 delete_transient( $cache_key ); 1307 } 1308 1309 wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs ); 1310 } 1311 1312 1313 /** 1314 * Renders the Events and News dashboard widget. 1315 * 1316 * @since 4.8.0 1317 */ 1318 function wp_dashboard_events_news() { 1319 wp_print_community_events_markup(); 1320 1321 ?> 1322 1323 <div class="wordpress-news hide-if-no-js"> 1324 <?php wp_dashboard_primary(); ?> 1325 </div> 1326 1327 <p class="community-events-footer"> 1328 <?php 1329 printf( 1330 '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', 1331 'https://make.wordpress.org/community/meetups-landing-page', 1332 __( 'Meetups' ), 1333 /* translators: Hidden accessibility text. */ 1334 __( '(opens in a new tab)' ) 1335 ); 1336 ?> 1337 1338 | 1339 1340 <?php 1341 printf( 1342 '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', 1343 'https://central.wordcamp.org/schedule/', 1344 __( 'WordCamps' ), 1345 /* translators: Hidden accessibility text. */ 1346 __( '(opens in a new tab)' ) 1347 ); 1348 ?> 1349 1350 | 1351 1352 <?php 1353 printf( 1354 '<a href="%1$s" target="_blank">%2$s <span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', 1355 /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */ 1356 esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ), 1357 __( 'News' ), 1358 /* translators: Hidden accessibility text. */ 1359 __( '(opens in a new tab)' ) 1360 ); 1361 ?> 1362 </p> 1363 1364 <?php 1365 } 1366 1367 /** 1368 * Prints the markup for the Community Events section of the Events and News Dashboard widget. 1369 * 1370 * @since 4.8.0 1371 */ 1372 function wp_print_community_events_markup() { 1373 $community_events_notice = '<p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>'; 1374 $community_events_notice .= '<p class="community-events-error-occurred" aria-hidden="true">' . __( 'An error occurred. Please try again.' ) . '</p>'; 1375 $community_events_notice .= '<p class="community-events-could-not-locate" aria-hidden="true"></p>'; 1376 1377 wp_admin_notice( 1378 $community_events_notice, 1379 array( 1380 'type' => 'error', 1381 'additional_classes' => array( 'community-events-errors', 'inline', 'hide-if-js' ), 1382 'paragraph_wrap' => false, 1383 ) 1384 ); 1385 1386 /* 1387 * Hide the main element when the page first loads, because the content 1388 * won't be ready until wp.communityEvents.renderEventsTemplate() has run. 1389 */ 1390 ?> 1391 <div id="community-events" class="community-events" aria-hidden="true"> 1392 <div class="activity-block"> 1393 <p> 1394 <span id="community-events-location-message"></span> 1395 1396 <button class="button-link community-events-toggle-location" aria-expanded="false"> 1397 <span class="dashicons dashicons-location" aria-hidden="true"></span> 1398 <span class="community-events-location-edit"><?php _e( 'Select location' ); ?></span> 1399 </button> 1400 </p> 1401 1402 <form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post"> 1403 <label for="community-events-location"> 1404 <?php _e( 'City:' ); ?> 1405 </label> 1406 <?php 1407 /* translators: Replace with a city related to your locale. 1408 * Test that it matches the expected location and has upcoming 1409 * events before including it. If no cities related to your 1410 * locale have events, then use a city related to your locale 1411 * that would be recognizable to most users. Use only the city 1412 * name itself, without any region or country. Use the endonym 1413 * (native locale name) instead of the English name if possible. 1414 */ 1415 ?> 1416 <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" /> 1417 1418 <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?> 1419 1420 <button class="community-events-cancel button-link" type="button" aria-expanded="false"> 1421 <?php _e( 'Cancel' ); ?> 1422 </button> 1423 1424 <span class="spinner"></span> 1425 </form> 1426 </div> 1427 1428 <ul class="community-events-results activity-block last"></ul> 1429 </div> 1430 1431 <?php 1432 } 1433 1434 /** 1435 * Renders the events templates for the Event and News widget. 1436 * 1437 * @since 4.8.0 1438 */ 1439 function wp_print_community_events_templates() { 1440 ?> 1441 1442 <script id="tmpl-community-events-attend-event-near" type="text/template"> 1443 <?php 1444 printf( 1445 /* translators: %s: The name of a city. */ 1446 __( 'Attend an upcoming event near %s.' ), 1447 '<strong>{{ data.location.description }}</strong>' 1448 ); 1449 ?> 1450 </script> 1451 1452 <script id="tmpl-community-events-could-not-locate" type="text/template"> 1453 <?php 1454 printf( 1455 /* translators: %s is the name of the city we couldn't locate. 1456 * Replace the examples with cities in your locale, but test 1457 * that they match the expected location before including them. 1458 * Use endonyms (native locale names) whenever possible. 1459 */ 1460 __( '%s could not be located. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ), 1461 '<em>{{data.unknownCity}}</em>' 1462 ); 1463 ?> 1464 </script> 1465 1466 <script id="tmpl-community-events-event-list" type="text/template"> 1467 <# _.each( data.events, function( event ) { #> 1468 <li class="event event-{{ event.type }} wp-clearfix"> 1469 <div class="event-info"> 1470 <div class="dashicons event-icon" aria-hidden="true"></div> 1471 <div class="event-info-inner"> 1472 <a class="event-title" href="{{ event.url }}">{{ event.title }}</a> 1473 <# if ( event.type ) { 1474 const titleCaseEventType = event.type.replace( 1475 /\w\S*/g, 1476 function ( type ) { return type.charAt(0).toUpperCase() + type.substr(1).toLowerCase(); } 1477 ); 1478 #> 1479 {{ 'wordcamp' === event.type ? 'WordCamp' : titleCaseEventType }} 1480 <span class="ce-separator" aria-hidden="true"></span> 1481 <# } #> 1482 <span class="event-city">{{ event.location.location }}</span> 1483 </div> 1484 </div> 1485 1486 <div class="event-date-time"> 1487 <span class="event-date">{{ event.user_formatted_date }}</span> 1488 <# if ( 'meetup' === event.type ) { #> 1489 <span class="event-time"> 1490 {{ event.user_formatted_time }} {{ event.timeZoneAbbreviation }} 1491 </span> 1492 <# } #> 1493 </div> 1494 </li> 1495 <# } ) #> 1496 1497 <# if ( data.events.length <= 2 ) { #> 1498 <li class="event-none"> 1499 <?php 1500 printf( 1501 /* translators: %s: Localized meetup organization documentation URL. */ 1502 __( 'Want more events? <a href="%s">Help organize the next one</a>!' ), 1503 __( 'https://make.wordpress.org/community/organize-event-landing-page/' ) 1504 ); 1505 ?> 1506 </li> 1507 <# } #> 1508 1509 </script> 1510 1511 <script id="tmpl-community-events-no-upcoming-events" type="text/template"> 1512 <li class="event-none"> 1513 <# if ( data.location.description ) { #> 1514 <?php 1515 printf( 1516 /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */ 1517 __( 'There are no events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize a WordPress event</a>?' ), 1518 '{{ data.location.description }}', 1519 __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' ) 1520 ); 1521 ?> 1522 1523 <# } else { #> 1524 <?php 1525 printf( 1526 /* translators: %s: Meetup organization documentation URL. */ 1527 __( 'There are no events scheduled near you at the moment. Would you like to <a href="%s">organize a WordPress event</a>?' ), 1528 __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' ) 1529 ); 1530 ?> 1531 <# } #> 1532 </li> 1533 </script> 1534 <?php 1535 } 1536 1537 /** 1538 * 'WordPress Events and News' dashboard widget. 1539 * 1540 * @since 2.7.0 1541 * @since 4.8.0 Removed popular plugins feed. 1542 */ 1543 function wp_dashboard_primary() { 1544 $feeds = array( 1545 'news' => array( 1546 1547 /** 1548 * Filters the primary link URL for the 'WordPress Events and News' dashboard widget. 1549 * 1550 * @since 2.5.0 1551 * 1552 * @param string $link The widget's primary link URL. 1553 */ 1554 'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ), 1555 1556 /** 1557 * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget. 1558 * 1559 * @since 2.3.0 1560 * 1561 * @param string $url The widget's primary feed URL. 1562 */ 1563 'url' => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ), 1564 1565 /** 1566 * Filters the primary link title for the 'WordPress Events and News' dashboard widget. 1567 * 1568 * @since 2.3.0 1569 * 1570 * @param string $title Title attribute for the widget's primary link. 1571 */ 1572 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ), 1573 'items' => 2, 1574 'show_summary' => 0, 1575 'show_author' => 0, 1576 'show_date' => 0, 1577 ), 1578 'planet' => array( 1579 1580 /** 1581 * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget. 1582 * 1583 * @since 2.3.0 1584 * 1585 * @param string $link The widget's secondary link URL. 1586 */ 1587 'link' => apply_filters( 1588 'dashboard_secondary_link', 1589 /* translators: Link to the Planet website of the locale. */ 1590 __( 'https://planet.wordpress.org/' ) 1591 ), 1592 1593 /** 1594 * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget. 1595 * 1596 * @since 2.3.0 1597 * 1598 * @param string $url The widget's secondary feed URL. 1599 */ 1600 'url' => apply_filters( 1601 'dashboard_secondary_feed', 1602 /* translators: Link to the Planet feed of the locale. */ 1603 __( 'https://planet.wordpress.org/feed/' ) 1604 ), 1605 1606 /** 1607 * Filters the secondary link title for the 'WordPress Events and News' dashboard widget. 1608 * 1609 * @since 2.3.0 1610 * 1611 * @param string $title Title attribute for the widget's secondary link. 1612 */ 1613 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ), 1614 1615 /** 1616 * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget. 1617 * 1618 * @since 4.4.0 1619 * 1620 * @param string $items How many items to show in the secondary feed. 1621 */ 1622 'items' => apply_filters( 'dashboard_secondary_items', 3 ), 1623 'show_summary' => 0, 1624 'show_author' => 0, 1625 'show_date' => 0, 1626 ), 1627 ); 1628 1629 wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds ); 1630 } 1631 1632 /** 1633 * Displays the WordPress events and news feeds. 1634 * 1635 * @since 3.8.0 1636 * @since 4.8.0 Removed popular plugins feed. 1637 * 1638 * @param string $widget_id Widget ID. 1639 * @param array $feeds Array of RSS feeds. 1640 */ 1641 function wp_dashboard_primary_output( $widget_id, $feeds ) { 1642 foreach ( $feeds as $type => $args ) { 1643 $args['type'] = $type; 1644 echo '<div class="rss-widget">'; 1645 wp_widget_rss_output( $args['url'], $args ); 1646 echo '</div>'; 1647 } 1648 } 1649 1650 /** 1651 * Displays file upload quota on dashboard. 1652 * 1653 * Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now(). 1654 * 1655 * @since 3.0.0 1656 * 1657 * @return true|null True if not multisite, user can't upload files, or the space check option is disabled. 1658 */ 1659 function wp_dashboard_quota() { 1660 if ( ! is_multisite() || ! current_user_can( 'upload_files' ) 1661 || get_site_option( 'upload_space_check_disabled' ) 1662 ) { 1663 return true; 1664 } 1665 1666 $quota = get_space_allowed(); 1667 $used = get_space_used(); 1668 1669 if ( $used > $quota ) { 1670 $percentused = '100'; 1671 } else { 1672 $percentused = ( $used / $quota ) * 100; 1673 } 1674 1675 $used_class = ( $percentused >= 70 ) ? ' warning' : ''; 1676 $used = round( $used, 2 ); 1677 $percentused = number_format( $percentused ); 1678 1679 ?> 1680 <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3> 1681 <div class="mu-storage"> 1682 <ul> 1683 <li class="storage-count"> 1684 <?php 1685 $text = sprintf( 1686 /* translators: %s: Number of megabytes. */ 1687 __( '%s MB Space Allowed' ), 1688 number_format_i18n( $quota ) 1689 ); 1690 printf( 1691 '<a href="%1$s">%2$s<span class="screen-reader-text"> (%3$s)</span></a>', 1692 esc_url( admin_url( 'upload.php' ) ), 1693 $text, 1694 /* translators: Hidden accessibility text. */ 1695 __( 'Manage Uploads' ) 1696 ); 1697 ?> 1698 </li><li class="storage-count <?php echo $used_class; ?>"> 1699 <?php 1700 $text = sprintf( 1701 /* translators: 1: Number of megabytes, 2: Percentage. */ 1702 __( '%1$s MB (%2$s%%) Space Used' ), 1703 number_format_i18n( $used, 2 ), 1704 $percentused 1705 ); 1706 printf( 1707 '<a href="%1$s" class="musublink">%2$s<span class="screen-reader-text"> (%3$s)</span></a>', 1708 esc_url( admin_url( 'upload.php' ) ), 1709 $text, 1710 /* translators: Hidden accessibility text. */ 1711 __( 'Manage Uploads' ) 1712 ); 1713 ?> 1714 </li> 1715 </ul> 1716 </div> 1717 <?php 1718 return null; 1719 } 1720 1721 /** 1722 * Displays the browser update nag. 1723 * 1724 * @since 3.2.0 1725 * @since 5.8.0 Added a special message for Internet Explorer users. 1726 * 1727 * @global bool $is_IE 1728 */ 1729 function wp_dashboard_browser_nag() { 1730 global $is_IE; 1731 1732 $notice = ''; 1733 $response = wp_check_browser_version(); 1734 1735 if ( $response ) { 1736 if ( $is_IE ) { 1737 $msg = __( 'Internet Explorer does not give you the best WordPress experience. Switch to Microsoft Edge, or another more modern browser to get the most from your site.' ); 1738 } elseif ( $response['insecure'] ) { 1739 $msg = sprintf( 1740 /* translators: %s: Browser name and link. */ 1741 __( "It looks like you're using an insecure version of %s. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), 1742 sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) ) 1743 ); 1744 } else { 1745 $msg = sprintf( 1746 /* translators: %s: Browser name and link. */ 1747 __( "It looks like you're using an old version of %s. For the best WordPress experience, please update your browser." ), 1748 sprintf( '<a href="%s">%s</a>', esc_url( $response['update_url'] ), esc_html( $response['name'] ) ) 1749 ); 1750 } 1751 1752 $browser_nag_class = ''; 1753 if ( ! empty( $response['img_src'] ) ) { 1754 $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) ) ? $response['img_src_ssl'] : $response['img_src']; 1755 1756 $notice .= '<div class="alignright browser-icon"><img src="' . esc_url( $img_src ) . '" alt="" /></div>'; 1757 $browser_nag_class = ' has-browser-icon'; 1758 } 1759 $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>"; 1760 1761 $browsehappy = 'https://browsehappy.com/'; 1762 $locale = get_user_locale(); 1763 if ( 'en_US' !== $locale ) { 1764 $browsehappy = add_query_arg( 'locale', $locale, $browsehappy ); 1765 } 1766 1767 if ( $is_IE ) { 1768 $msg_browsehappy = sprintf( 1769 /* translators: %s: Browse Happy URL. */ 1770 __( 'Learn how to <a href="%s" class="update-browser-link">browse happy</a>' ), 1771 esc_url( $browsehappy ) 1772 ); 1773 } else { 1774 $msg_browsehappy = sprintf( 1775 /* translators: 1: Browser update URL, 2: Browser name, 3: Browse Happy URL. */ 1776 __( '<a href="%1$s" class="update-browser-link">Update %2$s</a> or learn how to <a href="%3$s" class="browse-happy-link">browse happy</a>' ), 1777 esc_attr( $response['update_url'] ), 1778 esc_html( $response['name'] ), 1779 esc_url( $browsehappy ) 1780 ); 1781 } 1782 1783 $notice .= '<p>' . $msg_browsehappy . '</p>'; 1784 $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss" aria-label="' . esc_attr__( 'Dismiss the browser warning panel' ) . '">' . __( 'Dismiss' ) . '</a></p>'; 1785 $notice .= '<div class="clear"></div>'; 1786 } 1787 1788 /** 1789 * Filters the notice output for the 'Browse Happy' nag meta box. 1790 * 1791 * @since 3.2.0 1792 * 1793 * @param string $notice The notice content. 1794 * @param array|false $response An array containing web browser information, or 1795 * false on failure. See wp_check_browser_version(). 1796 */ 1797 echo apply_filters( 'browse-happy-notice', $notice, $response ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 1798 } 1799 1800 /** 1801 * Adds an additional class to the browser nag if the current version is insecure. 1802 * 1803 * @since 3.2.0 1804 * 1805 * @param string[] $classes Array of meta box classes. 1806 * @return string[] Modified array of meta box classes. 1807 */ 1808 function dashboard_browser_nag_class( $classes ) { 1809 $response = wp_check_browser_version(); 1810 1811 if ( $response && $response['insecure'] ) { 1812 $classes[] = 'browser-insecure'; 1813 } 1814 1815 return $classes; 1816 } 1817 1818 /** 1819 * Checks if the user needs a browser update. 1820 * 1821 * @since 3.2.0 1822 * 1823 * @return array|false Array of browser data on success, false on failure. 1824 */ 1825 function wp_check_browser_version() { 1826 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) ) { 1827 return false; 1828 } 1829 1830 $key = md5( $_SERVER['HTTP_USER_AGENT'] ); 1831 1832 $response = get_site_transient( 'browser_' . $key ); 1833 1834 if ( false === $response ) { 1835 $url = 'http://api.wordpress.org/core/browse-happy/1.1/'; 1836 $options = array( 1837 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ), 1838 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ), 1839 ); 1840 1841 if ( wp_http_supports( array( 'ssl' ) ) ) { 1842 $url = set_url_scheme( $url, 'https' ); 1843 } 1844 1845 $response = wp_remote_post( $url, $options ); 1846 1847 if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { 1848 return false; 1849 } 1850 1851 /** 1852 * Response should be an array with: 1853 * 'platform' - string - A user-friendly platform name, if it can be determined 1854 * 'name' - string - A user-friendly browser name 1855 * 'version' - string - The version of the browser the user is using 1856 * 'current_version' - string - The most recent version of the browser 1857 * 'upgrade' - boolean - Whether the browser needs an upgrade 1858 * 'insecure' - boolean - Whether the browser is deemed insecure 1859 * 'update_url' - string - The url to visit to upgrade 1860 * 'img_src' - string - An image representing the browser 1861 * 'img_src_ssl' - string - An image (over SSL) representing the browser 1862 */ 1863 $response = json_decode( wp_remote_retrieve_body( $response ), true ); 1864 1865 if ( ! is_array( $response ) ) { 1866 return false; 1867 } 1868 1869 set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS ); 1870 } 1871 1872 return $response; 1873 } 1874 1875 /** 1876 * Displays the PHP update nag. 1877 * 1878 * @since 5.1.0 1879 */ 1880 function wp_dashboard_php_nag() { 1881 $response = wp_check_php_version(); 1882 1883 if ( ! $response ) { 1884 return; 1885 } 1886 1887 if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) { 1888 // The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates. 1889 1890 if ( $response['is_lower_than_future_minimum'] ) { 1891 $message = sprintf( 1892 /* translators: %s: The server PHP version. */ 1893 __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ), 1894 PHP_VERSION 1895 ); 1896 } else { 1897 $message = sprintf( 1898 /* translators: %s: The server PHP version. */ 1899 __( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ), 1900 PHP_VERSION 1901 ); 1902 } 1903 } elseif ( $response['is_lower_than_future_minimum'] ) { 1904 $message = sprintf( 1905 /* translators: %s: The server PHP version. */ 1906 __( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress. Ensure that PHP is updated on your server as soon as possible. Otherwise you will not be able to upgrade WordPress.' ), 1907 PHP_VERSION 1908 ); 1909 } else { 1910 $message = sprintf( 1911 /* translators: %s: The server PHP version. */ 1912 __( 'Your site is running on an outdated version of PHP (%s), which should be updated.' ), 1913 PHP_VERSION 1914 ); 1915 } 1916 ?> 1917 <p class="bigger-bolder-text"><?php echo $message; ?></p> 1918 1919 <p><?php _e( 'What is PHP and how does it affect my site?' ); ?></p> 1920 <p> 1921 <?php _e( 'PHP is one of the programming languages used to build WordPress. Newer versions of PHP receive regular security updates and may increase your site’s performance.' ); ?> 1922 <?php 1923 if ( ! empty( $response['recommended_version'] ) ) { 1924 printf( 1925 /* translators: %s: The minimum recommended PHP version. */ 1926 __( 'The minimum recommended version of PHP is %s.' ), 1927 $response['recommended_version'] 1928 ); 1929 } 1930 ?> 1931 </p> 1932 1933 <p class="button-container"> 1934 <?php 1935 printf( 1936 '<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>', 1937 esc_url( wp_get_update_php_url() ), 1938 __( 'Learn more about updating PHP' ), 1939 /* translators: Hidden accessibility text. */ 1940 __( '(opens in a new tab)' ) 1941 ); 1942 ?> 1943 </p> 1944 <?php 1945 1946 wp_update_php_annotation(); 1947 wp_direct_php_update_button(); 1948 } 1949 1950 /** 1951 * Adds an additional class to the PHP nag if the current version is insecure. 1952 * 1953 * @since 5.1.0 1954 * 1955 * @param string[] $classes Array of meta box classes. 1956 * @return string[] Modified array of meta box classes. 1957 */ 1958 function dashboard_php_nag_class( $classes ) { 1959 $response = wp_check_php_version(); 1960 1961 if ( ! $response ) { 1962 return $classes; 1963 } 1964 1965 if ( isset( $response['is_secure'] ) && ! $response['is_secure'] ) { 1966 $classes[] = 'php-no-security-updates'; 1967 } elseif ( $response['is_lower_than_future_minimum'] ) { 1968 $classes[] = 'php-version-lower-than-future-minimum'; 1969 } 1970 1971 return $classes; 1972 } 1973 1974 /** 1975 * Displays the Site Health Status widget. 1976 * 1977 * @since 5.4.0 1978 */ 1979 function wp_dashboard_site_health() { 1980 $get_issues = get_transient( 'health-check-site-status-result' ); 1981 1982 $issue_counts = array(); 1983 1984 if ( false !== $get_issues ) { 1985 $issue_counts = json_decode( $get_issues, true ); 1986 } 1987 1988 if ( ! is_array( $issue_counts ) || ! $issue_counts ) { 1989 $issue_counts = array( 1990 'good' => 0, 1991 'recommended' => 0, 1992 'critical' => 0, 1993 ); 1994 } 1995 1996 $issues_total = $issue_counts['recommended'] + $issue_counts['critical']; 1997 ?> 1998 <div class="health-check-widget"> 1999 <div class="health-check-widget-title-section site-health-progress-wrapper loading hide-if-no-js"> 2000 <div class="site-health-progress"> 2001 <svg aria-hidden="true" focusable="false" width="100%" height="100%" viewBox="0 0 200 200" version="1.1" xmlns="http://www.w3.org/2000/svg"> 2002 <circle r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 2003 <circle id="bar" r="90" cx="100" cy="100" fill="transparent" stroke-dasharray="565.48" stroke-dashoffset="0"></circle> 2004 </svg> 2005 </div> 2006 <div class="site-health-progress-label"> 2007 <?php if ( false === $get_issues ) : ?> 2008 <?php _e( 'No information yet…' ); ?> 2009 <?php else : ?> 2010 <?php _e( 'Results are still loading…' ); ?> 2011 <?php endif; ?> 2012 </div> 2013 </div> 2014 2015 <div class="site-health-details"> 2016 <?php if ( false === $get_issues ) : ?> 2017 <p> 2018 <?php 2019 printf( 2020 /* translators: %s: URL to Site Health screen. */ 2021 __( 'Site health checks will automatically run periodically to gather information about your site. You can also <a href="%s">visit the Site Health screen</a> to gather information about your site now.' ), 2022 esc_url( admin_url( 'site-health.php' ) ) 2023 ); 2024 ?> 2025 </p> 2026 <?php else : ?> 2027 <p> 2028 <?php if ( $issues_total <= 0 ) : ?> 2029 <?php _e( 'Great job! Your site currently passes all site health checks.' ); ?> 2030 <?php elseif ( 1 === (int) $issue_counts['critical'] ) : ?> 2031 <?php _e( 'Your site has a critical issue that should be addressed as soon as possible to improve its performance and security.' ); ?> 2032 <?php elseif ( $issue_counts['critical'] > 1 ) : ?> 2033 <?php _e( 'Your site has critical issues that should be addressed as soon as possible to improve its performance and security.' ); ?> 2034 <?php elseif ( 1 === (int) $issue_counts['recommended'] ) : ?> 2035 <?php _e( 'Your site’s health is looking good, but there is still one thing you can do to improve its performance and security.' ); ?> 2036 <?php else : ?> 2037 <?php _e( 'Your site’s health is looking good, but there are still some things you can do to improve its performance and security.' ); ?> 2038 <?php endif; ?> 2039 </p> 2040 <?php endif; ?> 2041 2042 <?php if ( $issues_total > 0 && false !== $get_issues ) : ?> 2043 <p> 2044 <?php 2045 printf( 2046 /* translators: 1: Number of issues. 2: URL to Site Health screen. */ 2047 _n( 2048 'Take a look at the <strong>%1$d item</strong> on the <a href="%2$s">Site Health screen</a>.', 2049 'Take a look at the <strong>%1$d items</strong> on the <a href="%2$s">Site Health screen</a>.', 2050 $issues_total 2051 ), 2052 $issues_total, 2053 esc_url( admin_url( 'site-health.php' ) ) 2054 ); 2055 ?> 2056 </p> 2057 <?php endif; ?> 2058 </div> 2059 </div> 2060 2061 <?php 2062 } 2063 2064 /** 2065 * Outputs empty dashboard widget to be populated by JS later. 2066 * 2067 * Usable by plugins. 2068 * 2069 * @since 2.5.0 2070 */ 2071 function wp_dashboard_empty() {} 2072 2073 /** 2074 * Displays a welcome panel to introduce users to WordPress. 2075 * 2076 * @since 3.3.0 2077 * @since 5.9.0 Send users to the Site Editor if the active theme is block-based. 2078 */ 2079 function wp_welcome_panel() { 2080 list( $display_version ) = explode( '-', wp_get_wp_version() ); 2081 $can_customize = current_user_can( 'customize' ); 2082 $is_block_theme = wp_is_block_theme(); 2083 ?> 2084 <div class="welcome-panel-content"> 2085 <div class="welcome-panel-header-wrap"> 2086 <div class="welcome-panel-header"> 2087 <div class="welcome-panel-header-image"> 2088 <?php echo file_get_contents( dirname( __DIR__ ) . '/images/dashboard-background.svg' ); ?> 2089 </div> 2090 <h2><?php _e( 'Welcome to WordPress!' ); ?></h2> 2091 <p> 2092 <a href="<?php echo esc_url( admin_url( 'about.php' ) ); ?>"> 2093 <?php 2094 /* translators: %s: Current WordPress version. */ 2095 printf( __( 'Learn more about the %s version.' ), esc_html( $display_version ) ); 2096 ?> 2097 </a> 2098 </p> 2099 </div> 2100 </div> 2101 <div class="welcome-panel-column-container"> 2102 <div class="welcome-panel-column"> 2103 <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"> 2104 <rect width="48" height="48" rx="4" fill="#1E1E1E"/> 2105 <path fill-rule="evenodd" clip-rule="evenodd" d="M32.0668 17.0854L28.8221 13.9454L18.2008 24.671L16.8983 29.0827L21.4257 27.8309L32.0668 17.0854ZM16 32.75H24V31.25H16V32.75Z" fill="white"/> 2106 </svg> 2107 <div class="welcome-panel-column-content"> 2108 <h3><?php _e( 'Author rich content with blocks and patterns' ); ?></h3> 2109 <p><?php _e( 'Block patterns are pre-configured block layouts. Use them to get inspired or create new pages in a flash.' ); ?></p> 2110 <a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=page' ) ); ?>"><?php _e( 'Add a new page' ); ?></a> 2111 </div> 2112 </div> 2113 <div class="welcome-panel-column"> 2114 <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"> 2115 <rect width="48" height="48" rx="4" fill="#1E1E1E"/> 2116 <path fill-rule="evenodd" clip-rule="evenodd" d="M18 16h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H18a2 2 0 0 1-2-2V18a2 2 0 0 1 2-2zm12 1.5H18a.5.5 0 0 0-.5.5v3h13v-3a.5.5 0 0 0-.5-.5zm.5 5H22v8h8a.5.5 0 0 0 .5-.5v-7.5zm-10 0h-3V30a.5.5 0 0 0 .5.5h2.5v-8z" fill="#fff"/> 2117 </svg> 2118 <div class="welcome-panel-column-content"> 2119 <?php if ( $is_block_theme ) : ?> 2120 <h3><?php _e( 'Customize your entire site with block themes' ); ?></h3> 2121 <p><?php _e( 'Design everything on your site — from the header down to the footer, all using blocks and patterns.' ); ?></p> 2122 <a href="<?php echo esc_url( admin_url( 'site-editor.php' ) ); ?>"><?php _e( 'Open site editor' ); ?></a> 2123 <?php else : ?> 2124 <h3><?php _e( 'Start Customizing' ); ?></h3> 2125 <p><?php _e( 'Configure your site’s logo, header, menus, and more in the Customizer.' ); ?></p> 2126 <?php if ( $can_customize ) : ?> 2127 <a class="load-customize hide-if-no-customize" href="<?php echo wp_customize_url(); ?>"><?php _e( 'Open the Customizer' ); ?></a> 2128 <?php endif; ?> 2129 <?php endif; ?> 2130 </div> 2131 </div> 2132 <div class="welcome-panel-column"> 2133 <svg width="48" height="48" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"> 2134 <rect width="48" height="48" rx="4" fill="#1E1E1E"/> 2135 <path fill-rule="evenodd" clip-rule="evenodd" d="M31 24a7 7 0 0 1-7 7V17a7 7 0 0 1 7 7zm-7-8a8 8 0 1 1 0 16 8 8 0 0 1 0-16z" fill="#fff"/> 2136 </svg> 2137 <div class="welcome-panel-column-content"> 2138 <?php if ( $is_block_theme ) : ?> 2139 <h3><?php _e( 'Switch up your site’s look & feel with Styles' ); ?></h3> 2140 <p><?php _e( 'Tweak your site, or give it a whole new look! Get creative — how about a new color palette or font?' ); ?></p> 2141 <a href="<?php echo esc_url( add_query_arg( 'p', rawurlencode( '/styles' ), admin_url( 'site-editor.php' ) ) ); ?>"><?php _e( 'Edit styles' ); ?></a> 2142 <?php else : ?> 2143 <h3><?php _e( 'Discover a new way to build your site.' ); ?></h3> 2144 <p><?php _e( 'There is a new kind of WordPress theme, called a block theme, that lets you build the site you’ve always wanted — with blocks and styles.' ); ?></p> 2145 <a href="<?php echo esc_url( __( 'https://wordpress.org/documentation/article/block-themes/' ) ); ?>"><?php _e( 'Learn about block themes' ); ?></a> 2146 <?php endif; ?> 2147 </div> 2148 </div> 2149 </div> 2150 </div> 2151 <?php 2152 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Aug 6 08:20:21 2026 | Cross-referenced by PHPXref |