25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

1508 satır
52 KiB

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