PageRenderTime 71ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/includes/dashboard.php

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