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