/wp-admin/includes/dashboard.php

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