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