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

/wp-admin/includes/dashboard.php

http://github.com/markjaquith/WordPress
PHP | 1927 lines | 1173 code | 234 blank | 520 comment | 183 complexity | 700250f407f84d1828a0bc01cc94bcab MD5 | raw file
Possible License(s): 0BSD

Large files files are truncated, but you can click here to view the full file

  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 array $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'] && current_user_can( 'update_php' ) ) {
  36. add_filter( 'postbox_classes_dashboard_dashboard_php_nag', 'dashboard_php_nag_class' );
  37. wp_add_dashboard_widget( 'dashboard_php_nag', __( 'PHP Update Required' ), 'wp_dashboard_php_nag' );
  38. }
  39. // Site Health.
  40. if ( current_user_can( 'view_site_health_checks' ) && ! is_network_admin() ) {
  41. if ( ! class_exists( 'WP_Site_Health' ) ) {
  42. require_once ABSPATH . 'wp-admin/includes/class-wp-site-health.php';
  43. }
  44. WP_Site_Health::get_instance();
  45. wp_enqueue_style( 'site-health' );
  46. wp_enqueue_script( 'site-health' );
  47. wp_add_dashboard_widget( 'dashboard_site_health', __( 'Site Health Status' ), 'wp_dashboard_site_health' );
  48. }
  49. // Right Now.
  50. if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
  51. wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
  52. }
  53. if ( is_network_admin() ) {
  54. wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
  55. }
  56. // Activity Widget.
  57. if ( is_blog_admin() ) {
  58. wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
  59. }
  60. // QuickPress Widget.
  61. if ( is_blog_admin() && current_user_can( get_post_type_object( 'post' )->cap->create_posts ) ) {
  62. $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' ) );
  63. wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
  64. }
  65. // WordPress Events and News.
  66. wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress Events and News' ), 'wp_dashboard_events_news' );
  67. if ( is_network_admin() ) {
  68. /**
  69. * Fires after core widgets for the Network Admin dashboard have been registered.
  70. *
  71. * @since 3.1.0
  72. */
  73. do_action( 'wp_network_dashboard_setup' );
  74. /**
  75. * Filters the list of widgets to load for the Network Admin dashboard.
  76. *
  77. * @since 3.1.0
  78. *
  79. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  80. */
  81. $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
  82. } elseif ( is_user_admin() ) {
  83. /**
  84. * Fires after core widgets for the User Admin dashboard have been registered.
  85. *
  86. * @since 3.1.0
  87. */
  88. do_action( 'wp_user_dashboard_setup' );
  89. /**
  90. * Filters the list of widgets to load for the User Admin dashboard.
  91. *
  92. * @since 3.1.0
  93. *
  94. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  95. */
  96. $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
  97. } else {
  98. /**
  99. * Fires after core widgets for the admin dashboard have been registered.
  100. *
  101. * @since 2.5.0
  102. */
  103. do_action( 'wp_dashboard_setup' );
  104. /**
  105. * Filters the list of widgets to load for the admin dashboard.
  106. *
  107. * @since 2.5.0
  108. *
  109. * @param string[] $dashboard_widgets An array of dashboard widget IDs.
  110. */
  111. $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
  112. }
  113. foreach ( $dashboard_widgets as $widget_id ) {
  114. $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>';
  115. wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[ $widget_id ]['callback'], $wp_registered_widget_controls[ $widget_id ]['callback'] );
  116. }
  117. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget_id'] ) ) {
  118. check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
  119. ob_start(); // Hack - but the same hack wp-admin/widgets.php uses.
  120. wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
  121. ob_end_clean();
  122. wp_redirect( remove_query_arg( 'edit' ) );
  123. exit;
  124. }
  125. /** This action is documented in wp-admin/includes/meta-boxes.php */
  126. do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
  127. /** This action is documented in wp-admin/includes/meta-boxes.php */
  128. do_action( 'do_meta_boxes', $screen->id, 'side', '' );
  129. }
  130. /**
  131. * Adds a new dashboard widget.
  132. *
  133. * @since 2.7.0
  134. *
  135. * @global array $wp_dashboard_control_callbacks
  136. *
  137. * @param string $widget_id Widget ID (used in the 'id' attribute for the widget).
  138. * @param string $widget_name Title of the widget.
  139. * @param callable $callback Function that fills the widget with the desired content.
  140. * The function should echo its output.
  141. * @param callable $control_callback Optional. Function that outputs controls for the widget. Default null.
  142. * @param array $callback_args Optional. Data that should be set as the $args property of the widget array
  143. * (which is the second parameter passed to your callback). Default null.
  144. */
  145. function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
  146. $screen = get_current_screen();
  147. global $wp_dashboard_control_callbacks;
  148. $private_callback_args = array( '__widget_basename' => $widget_name );
  149. if ( is_null( $callback_args ) ) {
  150. $callback_args = $private_callback_args;
  151. } elseif ( is_array( $callback_args ) ) {
  152. $callback_args = array_merge( $callback_args, $private_callback_args );
  153. }
  154. if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
  155. $wp_dashboard_control_callbacks[ $widget_id ] = $control_callback;
  156. if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
  157. list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
  158. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
  159. $callback = '_wp_dashboard_control_callback';
  160. } else {
  161. list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
  162. $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
  163. }
  164. }
  165. $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
  166. $location = 'normal';
  167. if ( in_array( $widget_id, $side_widgets, true ) ) {
  168. $location = 'side';
  169. }
  170. $high_priority_widgets = array( 'dashboard_browser_nag', 'dashboard_php_nag' );
  171. $priority = 'core';
  172. if ( in_array( $widget_id, $high_priority_widgets, true ) ) {
  173. $priority = 'high';
  174. }
  175. add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
  176. }
  177. /**
  178. * Outputs controls for the current dashboard widget.
  179. *
  180. * @access private
  181. * @since 2.7.0
  182. *
  183. * @param mixed $dashboard
  184. * @param array $meta_box
  185. */
  186. function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
  187. echo '<form method="post" class="dashboard-widget-control-form wp-clearfix">';
  188. wp_dashboard_trigger_widget_control( $meta_box['id'] );
  189. wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
  190. echo '<input type="hidden" name="widget_id" value="' . esc_attr( $meta_box['id'] ) . '" />';
  191. submit_button( __( 'Submit' ) );
  192. echo '</form>';
  193. }
  194. /**
  195. * Displays the dashboard.
  196. *
  197. * @since 2.5.0
  198. */
  199. function wp_dashboard() {
  200. $screen = get_current_screen();
  201. $columns = absint( $screen->get_columns() );
  202. $columns_css = '';
  203. if ( $columns ) {
  204. $columns_css = " columns-$columns";
  205. }
  206. ?>
  207. <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
  208. <div id="postbox-container-1" class="postbox-container">
  209. <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
  210. </div>
  211. <div id="postbox-container-2" class="postbox-container">
  212. <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
  213. </div>
  214. <div id="postbox-container-3" class="postbox-container">
  215. <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
  216. </div>
  217. <div id="postbox-container-4" class="postbox-container">
  218. <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
  219. </div>
  220. </div>
  221. <?php
  222. wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
  223. wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
  224. }
  225. //
  226. // Dashboard Widgets.
  227. //
  228. /**
  229. * Dashboard widget that displays some basic stats about the site.
  230. *
  231. * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
  232. *
  233. * @since 2.7.0
  234. */
  235. function wp_dashboard_right_now() {
  236. ?>
  237. <div class="main">
  238. <ul>
  239. <?php
  240. // Posts and Pages.
  241. foreach ( array( 'post', 'page' ) as $post_type ) {
  242. $num_posts = wp_count_posts( $post_type );
  243. if ( $num_posts && $num_posts->publish ) {
  244. if ( 'post' == $post_type ) {
  245. /* translators: %s: Number of posts. */
  246. $text = _n( '%s Post', '%s Posts', $num_posts->publish );
  247. } else {
  248. /* translators: %s: Number of pages. */
  249. $text = _n( '%s Page', '%s Pages', $num_posts->publish );
  250. }
  251. $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
  252. $post_type_object = get_post_type_object( $post_type );
  253. if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
  254. printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
  255. } else {
  256. printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
  257. }
  258. }
  259. }
  260. // Comments.
  261. $num_comm = wp_count_comments();
  262. if ( $num_comm && ( $num_comm->approved || $num_comm->moderated ) ) {
  263. /* translators: %s: Number of comments. */
  264. $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->approved ), number_format_i18n( $num_comm->approved ) );
  265. ?>
  266. <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
  267. <?php
  268. $moderated_comments_count_i18n = number_format_i18n( $num_comm->moderated );
  269. /* translators: %s: Number of comments. */
  270. $text = sprintf( _n( '%s Comment in moderation', '%s Comments in moderation', $num_comm->moderated ), $moderated_comments_count_i18n );
  271. ?>
  272. <li class="comment-mod-count
  273. <?php
  274. if ( ! $num_comm->moderated ) {
  275. echo ' hidden';
  276. }
  277. ?>
  278. "><a href="edit-comments.php?comment_status=moderated" class="comments-in-moderation-text"><?php echo $text; ?></a></li>
  279. <?php
  280. }
  281. /**
  282. * Filters the array of extra elements to list in the 'At a Glance'
  283. * dashboard widget.
  284. *
  285. * Prior to 3.8.0, the widget was named 'Right Now'. Each element
  286. * is wrapped in list-item tags on output.
  287. *
  288. * @since 3.8.0
  289. *
  290. * @param string[] $items Array of extra 'At a Glance' widget items.
  291. */
  292. $elements = apply_filters( 'dashboard_glance_items', array() );
  293. if ( $elements ) {
  294. echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
  295. }
  296. ?>
  297. </ul>
  298. <?php
  299. update_right_now_message();
  300. // Check if search engines are asked not to index this site.
  301. if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '0' == get_option( 'blog_public' ) ) {
  302. /**
  303. * Filters the link title attribute for the 'Search Engines Discouraged'
  304. * message displayed in the 'At a Glance' dashboard widget.
  305. *
  306. * Prior to 3.8.0, the widget was named 'Right Now'.
  307. *
  308. * @since 3.0.0
  309. * @since 4.5.0 The default for `$title` was updated to an empty string.
  310. *
  311. * @param string $title Default attribute text.
  312. */
  313. $title = apply_filters( 'privacy_on_link_title', '' );
  314. /**
  315. * Filters the link label for the 'Search Engines Discouraged' message
  316. * displayed in the 'At a Glance' dashboard widget.
  317. *
  318. * Prior to 3.8.0, the widget was named 'Right Now'.
  319. *
  320. * @since 3.0.0
  321. *
  322. * @param string $content Default text.
  323. */
  324. $content = apply_filters( 'privacy_on_link_text', __( 'Search Engines Discouraged' ) );
  325. $title_attr = '' === $title ? '' : " title='$title'";
  326. echo "<p><a href='options-reading.php'$title_attr>$content</a></p>";
  327. }
  328. ?>
  329. </div>
  330. <?php
  331. /*
  332. * activity_box_end has a core action, but only prints content when multisite.
  333. * Using an output buffer is the only way to really check if anything's displayed here.
  334. */
  335. ob_start();
  336. /**
  337. * Fires at the end of the 'At a Glance' dashboard widget.
  338. *
  339. * Prior to 3.8.0, the widget was named 'Right Now'.
  340. *
  341. * @since 2.5.0
  342. */
  343. do_action( 'rightnow_end' );
  344. /**
  345. * Fires at the end of the 'At a Glance' dashboard widget.
  346. *
  347. * Prior to 3.8.0, the widget was named 'Right Now'.
  348. *
  349. * @since 2.0.0
  350. */
  351. do_action( 'activity_box_end' );
  352. $actions = ob_get_clean();
  353. if ( ! empty( $actions ) ) :
  354. ?>
  355. <div class="sub">
  356. <?php echo $actions; ?>
  357. </div>
  358. <?php
  359. endif;
  360. }
  361. /**
  362. * @since 3.1.0
  363. */
  364. function wp_network_dashboard_right_now() {
  365. $actions = array();
  366. if ( current_user_can( 'create_sites' ) ) {
  367. $actions['create-site'] = '<a href="' . network_admin_url( 'site-new.php' ) . '">' . __( 'Create a New Site' ) . '</a>';
  368. }
  369. if ( current_user_can( 'create_users' ) ) {
  370. $actions['create-user'] = '<a href="' . network_admin_url( 'user-new.php' ) . '">' . __( 'Create a New User' ) . '</a>';
  371. }
  372. $c_users = get_user_count();
  373. $c_blogs = get_blog_count();
  374. /* translators: %s: Number of users on the network. */
  375. $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
  376. /* translators: %s: Number of sites on the network. */
  377. $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
  378. /* translators: 1: Text indicating the number of sites on the network, 2: Text indicating the number of users on the network. */
  379. $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
  380. if ( $actions ) {
  381. echo '<ul class="subsubsub">';
  382. foreach ( $actions as $class => $action ) {
  383. $actions[ $class ] = "\t<li class='$class'>$action";
  384. }
  385. echo implode( " |</li>\n", $actions ) . "</li>\n";
  386. echo '</ul>';
  387. }
  388. ?>
  389. <br class="clear" />
  390. <p class="youhave"><?php echo $sentence; ?></p>
  391. <?php
  392. /**
  393. * Fires in the Network Admin 'Right Now' dashboard widget
  394. * just before the user and site search form fields.
  395. *
  396. * @since MU (3.0.0)
  397. */
  398. do_action( 'wpmuadminresult' );
  399. ?>
  400. <form action="<?php echo network_admin_url( 'users.php' ); ?>" method="get">
  401. <p>
  402. <label class="screen-reader-text" for="search-users"><?php _e( 'Search Users' ); ?></label>
  403. <input type="search" name="s" value="" size="30" autocomplete="off" id="search-users"/>
  404. <?php submit_button( __( 'Search Users' ), '', false, false, array( 'id' => 'submit_users' ) ); ?>
  405. </p>
  406. </form>
  407. <form action="<?php echo network_admin_url( 'sites.php' ); ?>" method="get">
  408. <p>
  409. <label class="screen-reader-text" for="search-sites"><?php _e( 'Search Sites' ); ?></label>
  410. <input type="search" name="s" value="" size="30" autocomplete="off" id="search-sites"/>
  411. <?php submit_button( __( 'Search Sites' ), '', false, false, array( 'id' => 'submit_sites' ) ); ?>
  412. </p>
  413. </form>
  414. <?php
  415. /**
  416. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  417. *
  418. * @since MU (3.0.0)
  419. */
  420. do_action( 'mu_rightnow_end' );
  421. /**
  422. * Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
  423. *
  424. * @since MU (3.0.0)
  425. */
  426. do_action( 'mu_activity_box_end' );
  427. }
  428. /**
  429. * The Quick Draft widget display and creation of drafts.
  430. *
  431. * @since 3.8.0
  432. *
  433. * @global int $post_ID
  434. *
  435. * @param string $error_msg Optional. Error message. Default false.
  436. */
  437. function wp_dashboard_quick_press( $error_msg = false ) {
  438. global $post_ID;
  439. if ( ! current_user_can( 'edit_posts' ) ) {
  440. return;
  441. }
  442. /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
  443. $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID.
  444. if ( $last_post_id ) {
  445. $post = get_post( $last_post_id );
  446. if ( empty( $post ) || 'auto-draft' !== $post->post_status ) { // auto-draft doesn't exist anymore.
  447. $post = get_default_post_to_edit( 'post', true );
  448. update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
  449. } else {
  450. $post->post_title = ''; // Remove the auto draft title.
  451. }
  452. } else {
  453. $post = get_default_post_to_edit( 'post', true );
  454. $user_id = get_current_user_id();
  455. // Don't create an option if this is a super admin who does not belong to this site.
  456. if ( in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ), true ) ) {
  457. update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID.
  458. }
  459. }
  460. $post_ID = (int) $post->ID;
  461. ?>
  462. <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
  463. <?php if ( $error_msg ) : ?>
  464. <div class="error"><?php echo $error_msg; ?></div>
  465. <?php endif; ?>
  466. <div class="input-text-wrap" id="title-wrap">
  467. <label for="title">
  468. <?php
  469. /** This filter is documented in wp-admin/edit-form-advanced.php */
  470. echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
  471. ?>
  472. </label>
  473. <input type="text" name="post_title" id="title" autocomplete="off" />
  474. </div>
  475. <div class="textarea-wrap" id="description-wrap">
  476. <label for="content"><?php _e( 'Content' ); ?></label>
  477. <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>
  478. </div>
  479. <p class="submit">
  480. <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
  481. <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
  482. <input type="hidden" name="post_type" value="post" />
  483. <?php wp_nonce_field( 'add-post' ); ?>
  484. <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
  485. <br class="clear" />
  486. </p>
  487. </form>
  488. <?php
  489. wp_dashboard_recent_drafts();
  490. }
  491. /**
  492. * Show recent drafts of the user on the dashboard.
  493. *
  494. * @since 2.7.0
  495. *
  496. * @param WP_Post[] $drafts Optional. Array of posts to display. Default false.
  497. */
  498. function wp_dashboard_recent_drafts( $drafts = false ) {
  499. if ( ! $drafts ) {
  500. $query_args = array(
  501. 'post_type' => 'post',
  502. 'post_status' => 'draft',
  503. 'author' => get_current_user_id(),
  504. 'posts_per_page' => 4,
  505. 'orderby' => 'modified',
  506. 'order' => 'DESC',
  507. );
  508. /**
  509. * Filters the post query arguments for the 'Recent Drafts' dashboard widget.
  510. *
  511. * @since 4.4.0
  512. *
  513. * @param array $query_args The query arguments for the 'Recent Drafts' dashboard widget.
  514. */
  515. $query_args = apply_filters( 'dashboard_recent_drafts_query_args', $query_args );
  516. $drafts = get_posts( $query_args );
  517. if ( ! $drafts ) {
  518. return;
  519. }
  520. }
  521. echo '<div class="drafts">';
  522. if ( count( $drafts ) > 3 ) {
  523. printf(
  524. '<p class="view-all"><a href="%s">%s</a></p>' . "\n",
  525. esc_url( admin_url( 'edit.php?post_status=draft' ) ),
  526. __( 'View all drafts' )
  527. );
  528. }
  529. echo '<h2 class="hide-if-no-js">' . __( 'Your Recent Drafts' ) . "</h2>\n<ul>";
  530. /* translators: Maximum number of words used in a preview of a draft on the dashboard. */
  531. $draft_length = intval( _x( '10', 'draft_length' ) );
  532. $drafts = array_slice( $drafts, 0, 3 );
  533. foreach ( $drafts as $draft ) {
  534. $url = get_edit_post_link( $draft->ID );
  535. $title = _draft_or_post_title( $draft->ID );
  536. echo "<li>\n";
  537. printf(
  538. '<div class="draft-title"><a href="%s" aria-label="%s">%s</a><time datetime="%s">%s</time></div>',
  539. esc_url( $url ),
  540. /* translators: %s: Post title. */
  541. esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $title ) ),
  542. esc_html( $title ),
  543. get_the_time( 'c', $draft ),
  544. get_the_time( __( 'F j, Y' ), $draft )
  545. );
  546. $the_content = wp_trim_words( $draft->post_content, $draft_length );
  547. if ( $the_content ) {
  548. echo '<p>' . $the_content . '</p>';
  549. }
  550. echo "</li>\n";
  551. }
  552. echo "</ul>\n</div>";
  553. }
  554. /**
  555. * Outputs a row for the Recent Comments widget.
  556. *
  557. * @access private
  558. * @since 2.7.0
  559. *
  560. * @global WP_Comment $comment Global comment object.
  561. *
  562. * @param WP_Comment $comment The current comment.
  563. * @param bool $show_date Optional. Whether to display the date.
  564. */
  565. function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
  566. $GLOBALS['comment'] = clone $comment;
  567. if ( $comment->comment_post_ID > 0 ) {
  568. $comment_post_title = _draft_or_post_title( $comment->comment_post_ID );
  569. $comment_post_url = get_the_permalink( $comment->comment_post_ID );
  570. $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
  571. } else {
  572. $comment_post_link = '';
  573. }
  574. $actions_string = '';
  575. if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
  576. // Pre-order it: Approve | Reply | Edit | Spam | Trash.
  577. $actions = array(
  578. 'approve' => '',
  579. 'unapprove' => '',
  580. 'reply' => '',
  581. 'edit' => '',
  582. 'spam' => '',
  583. 'trash' => '',
  584. 'delete' => '',
  585. 'view' => '',
  586. );
  587. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  588. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  589. $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  590. $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
  591. $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  592. $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  593. $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
  594. $actions['approve'] = sprintf(
  595. '<a href="%s" data-wp-lists="%s" class="vim-a aria-button-if-js" aria-label="%s">%s</a>',
  596. $approve_url,
  597. "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=approved",
  598. esc_attr__( 'Approve this comment' ),
  599. __( 'Approve' )
  600. );
  601. $actions['unapprove'] = sprintf(
  602. '<a href="%s" data-wp-lists="%s" class="vim-u aria-button-if-js" aria-label="%s">%s</a>',
  603. $unapprove_url,
  604. "dim:the-comment-list:comment-{$comment->comment_ID}:unapproved:e7e7d3:e7e7d3:new=unapproved",
  605. esc_attr__( 'Unapprove this comment' ),
  606. __( 'Unapprove' )
  607. );
  608. $actions['edit'] = sprintf(
  609. '<a href="%s" aria-label="%s">%s</a>',
  610. "comment.php?action=editcomment&amp;c={$comment->comment_ID}",
  611. esc_attr__( 'Edit this comment' ),
  612. __( 'Edit' )
  613. );
  614. $actions['reply'] = sprintf(
  615. '<button type="button" onclick="window.commentReply && commentReply.open(\'%s\',\'%s\');" class="vim-r button-link hide-if-no-js" aria-label="%s">%s</button>',
  616. $comment->comment_ID,
  617. $comment->comment_post_ID,
  618. esc_attr__( 'Reply to this comment' ),
  619. __( 'Reply' )
  620. );
  621. $actions['spam'] = sprintf(
  622. '<a href="%s" data-wp-lists="%s" class="vim-s vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  623. $spam_url,
  624. "delete:the-comment-list:comment-{$comment->comment_ID}::spam=1",
  625. esc_attr__( 'Mark this comment as spam' ),
  626. /* translators: "Mark as spam" link. */
  627. _x( 'Spam', 'verb' )
  628. );
  629. if ( ! EMPTY_TRASH_DAYS ) {
  630. $actions['delete'] = sprintf(
  631. '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  632. $delete_url,
  633. "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
  634. esc_attr__( 'Delete this comment permanently' ),
  635. __( 'Delete Permanently' )
  636. );
  637. } else {
  638. $actions['trash'] = sprintf(
  639. '<a href="%s" data-wp-lists="%s" class="delete vim-d vim-destructive aria-button-if-js" aria-label="%s">%s</a>',
  640. $trash_url,
  641. "delete:the-comment-list:comment-{$comment->comment_ID}::trash=1",
  642. esc_attr__( 'Move this comment to the Trash' ),
  643. _x( 'Trash', 'verb' )
  644. );
  645. }
  646. $actions['view'] = sprintf(
  647. '<a class="comment-link" href="%s" aria-label="%s">%s</a>',
  648. esc_url( get_comment_link( $comment ) ),
  649. esc_attr__( 'View this comment' ),
  650. __( 'View' )
  651. );
  652. /**
  653. * Filters the action links displayed for each comment in the 'Recent Comments'
  654. * dashboard widget.
  655. *
  656. * @since 2.6.0
  657. *
  658. * @param string[] $actions An array of comment actions. Default actions include:
  659. * 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
  660. * 'Delete', and 'Trash'.
  661. * @param WP_Comment $comment The comment object.
  662. */
  663. $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
  664. $i = 0;
  665. foreach ( $actions as $action => $link ) {
  666. ++$i;
  667. ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  668. // Reply and quickedit need a hide-if-no-js span.
  669. if ( 'reply' == $action || 'quickedit' == $action ) {
  670. $action .= ' hide-if-no-js';
  671. }
  672. if ( 'view' === $action && '1' !== $comment->comment_approved ) {
  673. $action .= ' hidden';
  674. }
  675. $actions_string .= "<span class='$action'>$sep$link</span>";
  676. }
  677. }
  678. ?>
  679. <li id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status( $comment ) ), $comment ); ?>>
  680. <?php
  681. $comment_row_class = '';
  682. if ( get_option( 'show_avatars' ) ) {
  683. echo get_avatar( $comment, 50, 'mystery' );
  684. $comment_row_class .= ' has-avatar';
  685. }
  686. ?>
  687. <?php if ( ! $comment->comment_type || 'comment' == $comment->comment_type ) : ?>
  688. <div class="dashboard-comment-wrap has-row-actions <?php echo $comment_row_class; ?>">
  689. <p class="comment-meta">
  690. <?php
  691. // Comments might not have a post they relate to, e.g. programmatically created ones.
  692. if ( $comment_post_link ) {
  693. printf(
  694. /* translators: 1: Comment author, 2: Post link, 3: Notification if the comment is pending. */
  695. __( 'From %1$s on %2$s %3$s' ),
  696. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
  697. $comment_post_link,
  698. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  699. );
  700. } else {
  701. printf(
  702. /* translators: 1: Comment author, 2: Notification if the comment is pending. */
  703. __( 'From %1$s %2$s' ),
  704. '<cite class="comment-author">' . get_comment_author_link( $comment ) . '</cite>',
  705. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  706. );
  707. }
  708. ?>
  709. </p>
  710. <?php
  711. else :
  712. switch ( $comment->comment_type ) {
  713. case 'pingback':
  714. $type = __( 'Pingback' );
  715. break;
  716. case 'trackback':
  717. $type = __( 'Trackback' );
  718. break;
  719. default:
  720. $type = ucwords( $comment->comment_type );
  721. }
  722. $type = esc_html( $type );
  723. ?>
  724. <div class="dashboard-comment-wrap has-row-actions">
  725. <p class="comment-meta">
  726. <?php
  727. // Pingbacks, Trackbacks or custom comment types might not have a post they relate to, e.g. programmatically created ones.
  728. if ( $comment_post_link ) {
  729. printf(
  730. /* translators: 1: Type of comment, 2: Post link, 3: Notification if the comment is pending. */
  731. _x( '%1$s on %2$s %3$s', 'dashboard' ),
  732. "<strong>$type</strong>",
  733. $comment_post_link,
  734. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  735. );
  736. } else {
  737. printf(
  738. /* translators: 1: Type of comment, 2: Notification if the comment is pending. */
  739. _x( '%1$s %2$s', 'dashboard' ),
  740. "<strong>$type</strong>",
  741. '<span class="approve">' . __( '[Pending]' ) . '</span>'
  742. );
  743. }
  744. ?>
  745. </p>
  746. <p class="comment-author"><?php comment_author_link( $comment ); ?></p>
  747. <?php endif; // comment_type ?>
  748. <blockquote><p><?php comment_excerpt( $comment ); ?></p></blockquote>
  749. <?php if ( $actions_string ) : ?>
  750. <p class="row-actions"><?php echo $actions_string; ?></p>
  751. <?php endif; ?>
  752. </div>
  753. </li>
  754. <?php
  755. $GLOBALS['comment'] = null;
  756. }
  757. /**
  758. * Callback function for Activity widget.
  759. *
  760. * @since 3.8.0
  761. */
  762. function wp_dashboard_site_activity() {
  763. echo '<div id="activity-widget">';
  764. $future_posts = wp_dashboard_recent_posts(
  765. array(
  766. 'max' => 5,
  767. 'status' => 'future',
  768. 'order' => 'ASC',
  769. 'title' => __( 'Publishing Soon' ),
  770. 'id' => 'future-posts',
  771. )
  772. );
  773. $recent_posts = wp_dashboard_recent_posts(
  774. array(
  775. 'max' => 5,
  776. 'status' => 'publish',
  777. 'order' => 'DESC',
  778. 'title' => __( 'Recently Published' ),
  779. 'id' => 'published-posts',
  780. )
  781. );
  782. $recent_comments = wp_dashboard_recent_comments();
  783. if ( ! $future_posts && ! $recent_posts && ! $recent_comments ) {
  784. echo '<div class="no-activity">';
  785. echo '<p>' . __( 'No activity yet!' ) . '</p>';
  786. echo '</div>';
  787. }
  788. echo '</div>';
  789. }
  790. /**
  791. * Generates Publishing Soon and Recently Published sections.
  792. *
  793. * @since 3.8.0
  794. *
  795. * @param array $args {
  796. * An array of query and display arguments.
  797. *
  798. * @type int $max Number of posts to display.
  799. * @type string $status Post status.
  800. * @type string $order Designates ascending ('ASC') or descending ('DESC') order.
  801. * @type string $title Section title.
  802. * @type string $id The container id.
  803. * }
  804. * @return bool False if no posts were found. True otherwise.
  805. */
  806. function wp_dashboard_recent_posts( $args ) {
  807. $query_args = array(
  808. 'post_type' => 'post',
  809. 'post_status' => $args['status'],
  810. 'orderby' => 'date',
  811. 'order' => $args['order'],
  812. 'posts_per_page' => intval( $args['max'] ),
  813. 'no_found_rows' => true,
  814. 'cache_results' => false,
  815. 'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
  816. );
  817. /**
  818. * Filters the query arguments used for the Recent Posts widget.
  819. *
  820. * @since 4.2.0
  821. *
  822. * @param array $query_args The arguments passed to WP_Query to produce the list of posts.
  823. */
  824. $query_args = apply_filters( 'dashboard_recent_posts_query_args', $query_args );
  825. $posts = new WP_Query( $query_args );
  826. if ( $posts->have_posts() ) {
  827. echo '<div id="' . $args['id'] . '" class="activity-block">';
  828. echo '<h3>' . $args['title'] . '</h3>';
  829. echo '<ul>';
  830. $today = current_time( 'Y-m-d' );
  831. $tomorrow = current_datetime()->modify( '+1 day' )->format( 'Y-m-d' );
  832. $year = current_time( 'Y' );
  833. while ( $posts->have_posts() ) {
  834. $posts->the_post();
  835. $time = get_the_time( 'U' );
  836. if ( gmdate( 'Y-m-d', $time ) == $today ) {
  837. $relative = __( 'Today' );
  838. } elseif ( gmdate( 'Y-m-d', $time ) == $tomorrow ) {
  839. $relative = __( 'Tomorrow' );
  840. } elseif ( gmdate( 'Y', $time ) !== $year ) {
  841. /* translators: Date and time format for recent posts on the dashboard, from a different calendar year, see https://www.php.net/date */
  842. $relative = date_i18n( __( 'M jS Y' ), $time );
  843. } else {
  844. /* translators: Date and time format for recent posts on the dashboard, see https://www.php.net/date */
  845. $relative = date_i18n( __( 'M jS' ), $time );
  846. }
  847. // Use the post edit link for those who can edit, the permalink otherwise.
  848. $recent_post_link = current_user_can( 'edit_post', get_the_ID() ) ? get_edit_post_link() : get_permalink();
  849. $draft_or_post_title = _draft_or_post_title();
  850. printf(
  851. '<li><span>%1$s</span> <a href="%2$s" aria-label="%3$s">%4$s</a></li>',
  852. /* translators: 1: Relative date, 2: Time. */
  853. sprintf( _x( '%1$s, %2$s', 'dashboard' ), $relative, get_the_time() ),
  854. $recent_post_link,
  855. /* translators: %s: Post title. */
  856. esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $draft_or_post_title ) ),
  857. $draft_or_post_title
  858. );
  859. }
  860. echo '</ul>';
  861. echo '</div>';
  862. } else {
  863. return false;
  864. }
  865. wp_reset_postdata();
  866. return true;
  867. }
  868. /**
  869. * Show Comments section.
  870. *
  871. * @since 3.8.0
  872. *
  873. * @param int $total_items Optional. Number of comments to query. Default 5.
  874. * @return bool False if no comments were found. True otherwise.
  875. */
  876. function wp_dashboard_recent_comments( $total_items = 5 ) {
  877. // Select all comment types and filter out spam later for better query performance.
  878. $comments = array();
  879. $comments_query = array(
  880. 'number' => $total_items * 5,
  881. 'offset' => 0,
  882. );
  883. if ( ! current_user_can( 'edit_posts' ) ) {
  884. $comments_query['status'] = 'approve';
  885. }
  886. while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
  887. if ( ! is_array( $possible ) ) {
  888. break;
  889. }
  890. foreach ( $possible as $comment ) {
  891. if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) ) {
  892. continue;
  893. }
  894. $comments[] = $comment;
  895. if ( count( $comments ) == $total_items ) {
  896. break 2;
  897. }
  898. }
  899. $comments_query['offset'] += $comments_query['number'];
  900. $comments_query['number'] = $total_items * 10;
  901. }
  902. if ( $comments ) {
  903. echo '<div id="latest-comments" class="activity-block">';
  904. echo '<h3>' . __( 'Recent Comments' ) . '</h3>';
  905. echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
  906. foreach ( $comments as $comment ) {
  907. _wp_dashboard_recent_comments_row( $comment );
  908. }
  909. echo '</ul>';
  910. if ( current_user_can( 'edit_posts' ) ) {
  911. echo '<h3 class="screen-reader-text">' . __( 'View more comments' ) . '</h3>';
  912. _get_list_table( 'WP_Comments_List_Table' )->views();
  913. }
  914. wp_comment_reply( -1, false, 'dashboard', false );
  915. wp_comment_trashnotice();
  916. echo '</div>';
  917. } else {
  918. return false;
  919. }
  920. return true;
  921. }
  922. /**
  923. * Display generic dashboard RSS widget feed.
  924. *
  925. * @since 2.5.0
  926. *
  927. * @param string $widget_id
  928. */
  929. function wp_dashboard_rss_output( $widget_id ) {
  930. $widgets = get_option( 'dashboard_widget_options' );
  931. echo '<div class="rss-widget">';
  932. wp_widget_rss_output( $widgets[ $widget_id ] );
  933. echo '</div>';
  934. }
  935. /**
  936. * Checks to see if all of the feed url in $check_urls are cached.
  937. *
  938. * If $check_urls is empty, look for the rss feed url found in the dashboard
  939. * widget options of $widget_id. If cached, call $callback, a function that
  940. * echoes out output for this widget. If not cache, echo a "Loading..." stub
  941. * which is later replaced by Ajax call (see top of /wp-admin/index.php)
  942. *
  943. * @since 2.5.0
  944. * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
  945. * by adding it to the function signature.
  946. *
  947. * @param string $widget_id The widget ID.
  948. * @param callable $callback The callback function used to display each feed.
  949. * @param array $check_urls RSS feeds.
  950. * @param mixed ...$args Optional additional parameters to pass to the callback function.
  951. * @return bool True on success, false on failure.
  952. */
  953. function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array(), ...$args ) {
  954. $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>';
  955. $doing_ajax = wp_doing_ajax();
  956. if ( empty( $check_urls ) ) {
  957. $widgets = get_option( 'dashboard_widget_options' );
  958. if ( empty( $widgets[ $widget_id ]['url'] ) && ! $doing_ajax ) {
  959. echo $loading;
  960. return false;
  961. }
  962. $check_urls = array( $widgets[ $widget_id ]['url'] );
  963. }
  964. $locale = get_user_locale();
  965. $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
  966. $output = get_transient( $cache_key );
  967. if ( false !== $output ) {
  968. echo $output;
  969. return true;
  970. }
  971. if ( ! $doing_ajax ) {
  972. echo $loading;
  973. return false;
  974. }
  975. if ( $callback && is_callable( $callback ) ) {
  976. array_unshift( $args, $widget_id, $check_urls );
  977. ob_start();
  978. call_user_func_array( $callback, $args );
  979. // Default lifetime in cache of 12 hours (same as the feeds).
  980. set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS );
  981. }
  982. return true;
  983. }
  984. //
  985. // Dashboard Widgets Controls.
  986. //
  987. /**
  988. * Calls widget control callback.
  989. *
  990. * @since 2.5.0
  991. *
  992. * @global array $wp_dashboard_control_callbacks
  993. *
  994. * @param int $widget_control_id Registered Widget ID.
  995. */
  996. function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
  997. global $wp_dashboard_control_callbacks;
  998. if ( is_scalar( $widget_control_id ) && $widget_control_id && isset( $wp_dashboard_control_callbacks[ $widget_control_id ] ) && is_callable( $wp_dashboard_control_callbacks[ $widget_control_id ] ) ) {
  999. call_user_func(
  1000. $wp_dashboard_control_callbacks[ $widget_control_id ],
  1001. '',
  1002. array(
  1003. 'id' => $widget_control_id,
  1004. 'callback' => $wp_dashboard_control_callbacks[ $widget_control_id ],
  1005. )
  1006. );
  1007. }
  1008. }
  1009. /**
  1010. * The RSS dashboard widget control.
  1011. *
  1012. * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
  1013. * from RSS-type widgets.
  1014. *
  1015. * @since 2.5.0
  1016. *
  1017. * @param string $widget_id
  1018. * @param array $form_inputs
  1019. */
  1020. function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
  1021. $widget_options = get_option( 'dashboard_widget_options' );
  1022. if ( ! $widget_options ) {
  1023. $widget_options = array();
  1024. }
  1025. if ( ! isset( $widget_options[ $widget_id ] ) ) {
  1026. $widget_options[ $widget_id ] = array();
  1027. }
  1028. $number = 1; // Hack to use wp_widget_rss_form().
  1029. $widget_options[ $widget_id ]['number'] = $number;
  1030. if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset( $_POST['widget-rss'][ $number ] ) ) {
  1031. $_POST['widget-rss'][ $number ] = wp_unslash( $_POST['widget-rss'][ $number ] );
  1032. $widget_options[ $widget_id ] = wp_widget_rss_process( $_POST['widget-rss'][ $number ] );
  1033. $widget_options[ $widget_id ]['number'] = $number;
  1034. // Title is optional. If black, fill it if possible.
  1035. if ( ! $widget_options[ $widget_id ]['title'] && isset( $_POST['widget-rss'][ $number ]['title'] ) ) {
  1036. $rss = fetch_feed( $widget_options[ $widget_id ]['url'] );
  1037. if ( is_wp_error( $rss ) ) {
  1038. $widget_options[ $widget_id ]['title'] = htmlentities( __( 'Unknown Feed' ) );
  1039. } else {
  1040. $widget_options[ $widget_id ]['title'] = htmlentities( strip_tags( $rss->get_title() ) );
  1041. $rss->__destruct();
  1042. unset( $rss );
  1043. }
  1044. }
  1045. update_option( 'dashboard_widget_options', $widget_options );
  1046. $locale = get_user_locale();
  1047. $cache_key = 'dash_v2_' . md5( $widget_id . '_' . $locale );
  1048. delete_transient( $cache_key );
  1049. }
  1050. wp_widget_rss_form( $widget_options[ $widget_id ], $form_inputs );
  1051. }
  1052. /**
  1053. * Renders the Events and News dashboard widget.
  1054. *
  1055. * @since 4.8.0
  1056. */
  1057. function wp_dashboard_events_news() {
  1058. wp_print_community_events_markup();
  1059. ?>
  1060. <div class="wordpress-news hide-if-no-js">
  1061. <?php wp_dashboard_primary(); ?>
  1062. </div>
  1063. <p class="community-events-footer">
  1064. <?php
  1065. printf(
  1066. '<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>',
  1067. 'https://make.wordpress.org/community/meetups-landing-page',
  1068. __( 'Meetups' ),
  1069. /* translators: Accessibility text. */
  1070. __( '(opens in a new tab)' )
  1071. );
  1072. ?>
  1073. |
  1074. <?php
  1075. printf(
  1076. '<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>',
  1077. 'https://central.wordcamp.org/schedule/',
  1078. __( 'WordCamps' ),
  1079. /* translators: Accessibility text. */
  1080. __( '(opens in a new tab)' )
  1081. );
  1082. ?>
  1083. |
  1084. <?php
  1085. printf(
  1086. '<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>',
  1087. /* translators: If a Rosetta site exists (e.g. https://es.wordpress.org/news/), then use that. Otherwise, leave untranslated. */
  1088. esc_url( _x( 'https://wordpress.org/news/', 'Events and News dashboard widget' ) ),
  1089. __( 'News' ),
  1090. /* translators: Accessibility text. */
  1091. __( '(opens in a new tab)' )
  1092. );
  1093. ?>
  1094. </p>
  1095. <?php
  1096. }
  1097. /**
  1098. * Prints the markup for the Community Events section of the Events and News Dashboard widget.
  1099. *
  1100. * @since 4.8.0
  1101. */
  1102. function wp_print_community_events_markup() {
  1103. ?>
  1104. <div class="community-events-errors notice notice-error inline hide-if-js">
  1105. <p class="hide-if-js">
  1106. <?php _e( 'This widget requires JavaScript.' ); ?>
  1107. </p>
  1108. <p class="community-events-error-occurred" aria-hidden="true">
  1109. <?php _e( 'An error occurred. Please try again.' ); ?>
  1110. </p>
  1111. <p class="community-events-could-not-locate" aria-hidden="true"></p>
  1112. </div>
  1113. <div class="community-events-loading hide-if-no-js">
  1114. <?php _e( 'Loading&hellip;' ); ?>
  1115. </div>
  1116. <?php
  1117. /*
  1118. * Hide the main element when the page first loads, because the content
  1119. * won't be ready until wp.communityEvents.renderEventsTemplate() has run.
  1120. */
  1121. ?>
  1122. <div id="community-events" class="community-events" aria-hidden="true">
  1123. <div class="activity-block">
  1124. <p>
  1125. <span id="community-events-location-message"></span>
  1126. <button class="button-link community-events-toggle-location" aria-label="<?php esc_attr_e( 'Edit city' ); ?>" aria-expanded="false">
  1127. <span class="dashicons dashicons-edit"></span>
  1128. </button>
  1129. </p>
  1130. <form class="community-events-form" aria-hidden="true" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" method="post">
  1131. <label for="community-events-location">
  1132. <?php _e( 'City:' ); ?>
  1133. </label>
  1134. <?php
  1135. /* translators: Replace with a city related to your locale.
  1136. * Test that it matches the expected location and has upcoming
  1137. * events before including it. If no cities related to your
  1138. * locale have events, then use a city related to your locale
  1139. * that would be recognizable to most users. Use only the city
  1140. * name itself, without any region or country. Use the endonym
  1141. * (native locale name) instead of the English name if possible.
  1142. */
  1143. ?>
  1144. <input id="community-events-location" class="regular-text" type="text" name="community-events-location" placeholder="<?php esc_attr_e( 'Cincinnati' ); ?>" />
  1145. <?php submit_button( __( 'Submit' ), 'secondary', 'community-events-submit', false ); ?>
  1146. <button class="community-events-cancel button-link" type="button" aria-expanded="false">
  1147. <?php _e( 'Cancel' ); ?>
  1148. </button>
  1149. <span class="spinner"></span>
  1150. </form>
  1151. </div>
  1152. <ul class="community-events-results activity-block last"></ul>
  1153. </div>
  1154. <?php
  1155. }
  1156. /**
  1157. * Renders the events templates for the Event and News widget.
  1158. *
  1159. * @since 4.8.0
  1160. */
  1161. function wp_print_community_events_templates() {
  1162. ?>
  1163. <script id="tmpl-community-events-attend-event-near" type="text/template">
  1164. <?php
  1165. printf(
  1166. /* translators: %s: The name of a city. */
  1167. __( 'Attend an upcoming event near %s.' ),
  1168. '<strong>{{ data.location.description }}</strong>'
  1169. );
  1170. ?>
  1171. </script>
  1172. <script id="tmpl-community-events-could-not-locate" type="text/template">
  1173. <?php
  1174. printf(
  1175. /* translators: %s is the name of the city we couldn't locate.
  1176. * Replace the examples with cities in your locale, but test
  1177. * that they match the expected location before including them.
  1178. * Use endonyms (native locale names) whenever possible.
  1179. */
  1180. __( 'We couldn&#8217;t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
  1181. '<em>{{data.unknownCity}}</em>'
  1182. );
  1183. ?>
  1184. </script>
  1185. <script id="tmpl-community-events-event-list" type="text/template">
  1186. <# _.each( data.events, function( event ) { #>
  1187. <li class="event event-{{ event.type }} wp-clearfix">
  1188. <div class="event-info">
  1189. <div class="dashicons event-icon" aria-hidden="true"></div>
  1190. <div class="event-info-inner">
  1191. <a class="event-title" href="{{ event.url }}">{{ event.title }}</a>
  1192. <span class="event-city">{{ event.location.location }}</span>
  1193. </div>
  1194. </div>
  1195. <div class="event-date-time">
  1196. <span class="event-date">{{ event.formatted_date }}</span>
  1197. <# if ( 'meetup' === event.type ) { #>
  1198. <span class="event-time">{{ event.formatted_time }}</span>
  1199. <# } #>
  1200. </div>
  1201. </li>
  1202. <# } ) #>
  1203. </script>
  1204. <script id="tmpl-community-events-no-upcoming-events" type="text/template">
  1205. <li class="event-none">
  1206. <# if ( data.location.description ) { #>
  1207. <?php
  1208. printf(
  1209. /* translators: 1: The city the user searched for, 2: Meetup organization documentation URL. */
  1210. __( 'There aren&#8217;t any events scheduled near %1$s at the moment. Would you like to <a href="%2$s">organize one</a>?' ),
  1211. '{{ data.location.description }}',
  1212. __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
  1213. );
  1214. ?>
  1215. <# } else { #>
  1216. <?php
  1217. printf(
  1218. /* translators: %s: Meetup organization documentation URL. */
  1219. __( 'There aren&#8217;t any events scheduled near you at the moment. Would you like to <a href="%s">organize one</a>?' ),
  1220. __( 'https://make.wordpress.org/community/handbook/meetup-organizer/welcome/' )
  1221. );
  1222. ?>
  1223. <# } #>
  1224. </li>
  1225. </script>
  1226. <?php
  1227. }
  1228. /**
  1229. * 'WordPress Events and News' dashboard widget.
  1230. *
  1231. * @since 2.7.0
  1232. * @since 4.8.0 Removed popular plugins feed.
  1233. */
  1234. function wp_dashboard_primary() {
  1235. $feeds = array(
  1236. 'news' => array(
  1237. /**
  1238. * Filters the primary link URL for the 'WordPress Events and News' dashboard widget.
  1239. *
  1240. * @since 2.5.0
  1241. *
  1242. * @param string $link The widget's primary link URL.
  1243. */
  1244. 'link' => apply_filters( 'dashboard_primary_link', __( 'https://wordpress.org/news/' ) ),
  1245. /**
  1246. * Filters the primary feed URL for the 'WordPress Events and News' dashboard widget.
  1247. *
  1248. * @since 2.3.0
  1249. *
  1250. * @param string $url The widget's primary feed URL.
  1251. */
  1252. 'url' => apply_filters( 'dashboard_primary_feed', __( 'https://wordpress.org/news/feed/' ) ),
  1253. /**
  1254. * Filters the primary link title for the 'WordPress Events and News' dashboard widget.
  1255. *
  1256. * @since 2.3.0
  1257. *
  1258. * @param string $title Title attribute for the widget's primary link.
  1259. */
  1260. 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
  1261. 'items' => 1,
  1262. 'show_summary' => 0,
  1263. 'show_author' => 0,
  1264. 'show_date' => 0,
  1265. ),
  1266. 'planet' => array(
  1267. /**
  1268. * Filters the secondary link URL for the 'WordPress Events and News' dashboard widget.
  1269. *
  1270. * @since 2.3.0
  1271. *
  1272. * @param string $link The widget's secondary link URL.
  1273. */
  1274. 'link' => apply_filters( 'dashboard_secondary_link', __( 'https://planet.wordpress.org/' ) ),
  1275. /**
  1276. * Filters the secondary feed URL for the 'WordPress Events and News' dashboard widget.
  1277. *
  1278. * @since 2.3.0
  1279. *
  1280. * @param string $url The widget's secondary feed URL.
  1281. */
  1282. 'url' => apply_filters( 'dashboard_secondary_feed', __( 'https://planet.wordpress.org/feed/' ) ),
  1283. /**
  1284. * Filters the secondary link title for the 'WordPress Events and News' dashboard widget.
  1285. *
  1286. * @since 2.3.0
  1287. *
  1288. * @param string $title Title attribute for the widget's secondary link.
  1289. */
  1290. 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
  1291. /**
  1292. * Filters the number of secondary link items for the 'WordPress Events and News' dashboard widget.
  1293. *
  1294. * @since 4.4.0
  1295. *
  1296. * @param string $items How many items to show in the secondary feed.
  1297. */
  1298. 'items' => apply_filters( 'dashboard_secondary_items', 3 ),
  1299. 'show_summary' => 0,
  1300. 'show_author' => 0,
  1301. 'show_date' => 0,
  1302. ),
  1303. );
  1304. wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
  1305. }
  1306. /**
  1307. * Displays the WordPress events and news feeds.
  1308. *
  1309. * @since 3.8.0
  1310. * @since 4.8.0 Removed popular plugins feed.
  1311. *
  1312. * @param string $widget_id Widget ID.
  1313. * @param array $feeds Array of RSS feeds.
  1314. */
  1315. function wp_dashboard_primary_output( $widget_id, $feeds ) {
  1316. foreach ( $feeds as $type => $args ) {
  1317. $args['type'] = $type;
  1318. echo '<div class="rss-widget">';
  1319. wp_widget_rss_output( $args['url'], $args );
  1320. echo '</div>';
  1321. }
  1322. }
  1323. /**
  1324. * Displays file upload quota on dashboard.
  1325. *
  1326. * Runs on the {@see 'activity_box_end'} hook in wp_dashboard_right_now().
  1327. *
  1328. * @since 3.0.0
  1329. *
  1330. * @return bool|null True if not multisite, user can't upload files, or the space check option is disabled.
  1331. */
  1332. function wp_dashboard_quota() {
  1333. if ( ! is_multisite() || ! current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) ) {
  1334. return true;
  1335. }
  1336. $quota = get_space_allowed();
  1337. $used = get_space_used();
  1338. if ( $used > $quota ) {
  1339. $percentused = '100';
  1340. } else {
  1341. $percentused = ( $used / $quota ) * 100;
  1342. }
  1343. $used_class = ( $percentused >= 70 ) ? ' warning' : '';
  1344. $used = round( $used, 2 );
  1345. $percentused = number_format( $percentused );
  1346. ?>
  1347. <h3 class="mu-storage"><?php _e( 'Storage Space' ); ?></h3>
  1348. <div class="mu-storage">
  1349. <ul>
  1350. <li class="storage-count">
  1351. <?php
  1352. $text = sprintf(
  1353. /* translators: %s: Number of megabytes. */
  1354. __( '%s MB Space Allowed' ),
  1355. number_format_i18n( $quota )
  1356. );
  1357. pr

Large files files are truncated, but you can click here to view the full file