3 * WordPress Dashboard Widget Administration Screen API
6 * @subpackage Administration
10 * Registers dashboard widgets.
12 * Handles POST data, sets up filters.
16 function wp_dashboard_setup() {
17 global $wp_registered_widgets, $wp_registered_widget_controls, $wp_dashboard_control_callbacks;
18 $wp_dashboard_control_callbacks = array();
19 $screen = get_current_screen();
22 $widget_options = get_option( 'dashboard_widget_options' );
23 if ( !$widget_options || !is_array($widget_options) )
24 $widget_options = array();
26 /* Register Widgets and Controls */
28 $response = wp_check_browser_version();
30 if ( $response && $response['upgrade'] ) {
31 add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
32 if ( $response['insecure'] )
33 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
35 wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
39 if ( is_blog_admin() && current_user_can('edit_posts') )
40 wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
42 if ( is_network_admin() )
43 wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
46 if ( is_blog_admin() ) {
47 wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
51 if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
52 $quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) );
53 wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
57 wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' );
59 // Hook to register new widgets
60 // Filter widget order
61 if ( is_network_admin() ) {
62 do_action( 'wp_network_dashboard_setup' );
63 $dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
64 } elseif ( is_user_admin() ) {
65 do_action( 'wp_user_dashboard_setup' );
66 $dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
68 do_action( 'wp_dashboard_setup' );
69 $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
72 foreach ( $dashboard_widgets as $widget_id ) {
73 $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>';
74 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
77 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
78 check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
79 ob_start(); // hack - but the same hack wp-admin/widgets.php uses
80 wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
82 wp_redirect( remove_query_arg( 'edit' ) );
87 update_option( 'dashboard_widget_options', $widget_options );
89 /** This action is documented in wp-admin/edit-form-advanced.php */
90 do_action('do_meta_boxes', $screen->id, 'normal', '');
91 /** This action is documented in wp-admin/edit-form-advanced.php */
92 do_action('do_meta_boxes', $screen->id, 'side', '');
95 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
96 $screen = get_current_screen();
97 global $wp_dashboard_control_callbacks;
99 if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
100 $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
101 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
102 list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
103 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
104 $callback = '_wp_dashboard_control_callback';
106 list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
107 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
111 $side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
113 $location = 'normal';
114 if ( in_array($widget_id, $side_widgets) )
118 if ( 'dashboard_browser_nag' === $widget_id )
121 add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
124 function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
125 echo '<form action="" method="post" class="dashboard-widget-control-form">';
126 wp_dashboard_trigger_widget_control( $meta_box['id'] );
127 wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
128 echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
129 submit_button( __('Submit') );
134 * Displays the dashboard.
138 function wp_dashboard() {
139 $screen = get_current_screen();
140 $columns = absint( $screen->get_columns() );
143 $columns_css = " columns-$columns";
147 <div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
148 <div id='postbox-container-1' class='postbox-container'>
149 <?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
151 <div id='postbox-container-2' class='postbox-container'>
152 <?php do_meta_boxes( $screen->id, 'side', '' ); ?>
154 <div id='postbox-container-3' class='postbox-container'>
155 <?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
157 <div id='postbox-container-4' class='postbox-container'>
158 <?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
163 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
164 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
168 /* Dashboard Widgets */
171 * Dashboard widget that displays some basic stats about the site.
173 * Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
177 function wp_dashboard_right_now() {
178 $theme = wp_get_theme();
179 if ( current_user_can( 'switch_themes' ) )
180 $theme_name = sprintf( '<a href="themes.php">%1$s</a>', $theme->display('Name') );
182 $theme_name = $theme->display('Name');
188 foreach ( array( 'post', 'page' ) as $post_type ) {
189 $num_posts = wp_count_posts( $post_type );
190 if ( $num_posts && $num_posts->publish ) {
191 if ( 'post' == $post_type ) {
192 $text = _n( '%s Post', '%s Posts', $num_posts->publish );
194 $text = _n( '%s Page', '%s Pages', $num_posts->publish );
196 $text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
197 $post_type_object = get_post_type_object( $post_type );
198 if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
199 printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
201 printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
207 $num_comm = wp_count_comments();
208 if ( $num_comm && $num_comm->total_comments ) {
209 $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) );
211 <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
213 if ( $num_comm->moderated ) {
214 /* translators: Number of comments in moderation */
215 $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
217 <li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
223 * Include additional elements in the 'At a Glance' dashboard widget.
224 * This widget was previously 'Right Now'.
227 * @param array $items Array of items.
229 $elements = apply_filters( 'dashboard_glance_items', array() );
231 echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
236 <p><?php printf( __( 'WordPress %1$s running %2$s theme.' ), get_bloginfo( 'version', 'display' ), $theme_name ); ?></p>
239 // Check if search engines are asked not to index this site.
240 if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) {
243 * Filter the title attribute for the link displayed in Site Content metabox when search engines are discouraged from indexing the site.
247 * @param string Default attribute text.
249 $title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) );
252 * Filter the text for the link displayed in Site Content metabox when search engines are discouraged from indexing the site.
256 * @param string Default text.
258 $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
260 echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
265 // activity_box_end has a core action, but only prints content when multisite.
266 // Using an output buffer is the only way to really check if anything's displayed here.
268 do_action( 'rightnow_end' );
269 do_action( 'activity_box_end' );
270 $actions = ob_get_clean();
272 if ( !empty( $actions ) ) : ?>
274 <?php echo $actions; ?>
279 function wp_network_dashboard_right_now() {
281 if ( current_user_can('create_sites') )
282 $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
283 if ( current_user_can('create_users') )
284 $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
286 $c_users = get_user_count();
287 $c_blogs = get_blog_count();
289 $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
290 $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
292 $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
295 echo '<ul class="subsubsub">';
296 foreach ( $actions as $class => $action ) {
297 $actions[ $class ] = "\t<li class='$class'>$action";
299 echo implode( " |</li>\n", $actions ) . "</li>\n";
305 <p class="youhave"><?php echo $sentence; ?></p>
306 <?php do_action( 'wpmuadminresult', '' ); ?>
308 <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
310 <input type="search" name="s" value="" size="30" autocomplete="off" />
311 <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
315 <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
317 <input type="search" name="s" value="" size="30" autocomplete="off" />
318 <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
322 do_action( 'mu_rightnow_end' );
323 do_action( 'mu_activity_box_end' );
327 * The Quick Draft widget display and creation of drafts.
331 * @param string $error_msg Optional. Error message. Default false.
333 function wp_dashboard_quick_press( $error_msg = false ) {
336 /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
337 $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
338 if ( $last_post_id ) {
339 $post = get_post( $last_post_id );
340 if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
341 $post = get_default_post_to_edit( 'post', true );
342 update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
344 $post->post_title = ''; // Remove the auto draft title
347 $post = get_default_post_to_edit( 'post' , true);
348 $user_id = get_current_user_id();
349 // Don't create an option if this is a super admin who does not belong to this site.
350 if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
351 update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
354 $post_ID = (int) $post->ID;
357 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
359 <?php if ( $error_msg ) : ?>
360 <div class="error"><?php echo $error_msg; ?></div>
363 <div class="input-text-wrap" id="title-wrap">
364 <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); ?></label>
365 <input type="text" name="post_title" id="title" autocomplete="off" />
368 <div class="textarea-wrap" id="description-wrap">
369 <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label>
370 <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
374 <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
375 <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
376 <input type="hidden" name="post_type" value="post" />
377 <?php wp_nonce_field( 'add-post' ); ?>
378 <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
384 wp_dashboard_recent_drafts();
388 * Show recent drafts of the user on the dashboard.
392 function wp_dashboard_recent_drafts( $drafts = false ) {
395 'post_type' => 'post',
396 'post_status' => 'draft',
397 'author' => get_current_user_id(),
398 'posts_per_page' => 4,
399 'orderby' => 'modified',
402 $drafts = get_posts( $query_args );
408 echo '<div class="drafts">';
409 if ( count( $drafts ) > 3 ) {
410 echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n";
412 echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>";
414 $drafts = array_slice( $drafts, 0, 3 );
415 foreach ( $drafts as $draft ) {
416 $url = get_edit_post_link( $draft->ID );
417 $title = _draft_or_post_title( $draft->ID );
419 echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
420 echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
421 if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
422 echo '<p>' . $the_content . '</p>';
426 echo "</ul>\n</div>";
429 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
430 $GLOBALS['comment'] =& $comment;
432 $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
433 $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
434 $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
435 $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
437 $actions_string = '';
438 if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
439 // preorder it: Approve | Reply | Edit | Spam | Trash
441 'approve' => '', 'unapprove' => '',
445 'trash' => '', 'delete' => ''
448 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
449 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
451 $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
452 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
453 $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
454 $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
455 $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
457 $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>';
458 $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>';
459 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
460 $actions['reply'] = '<a onclick="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>';
461 $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>';
462 if ( !EMPTY_TRASH_DAYS )
463 $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>';
465 $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>';
467 $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
470 foreach ( $actions as $action => $link ) {
472 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
474 // Reply and quickedit need a hide-if-no-js span
475 if ( 'reply' == $action || 'quickedit' == $action )
476 $action .= ' hide-if-no-js';
478 $actions_string .= "<span class='$action'>$sep$link</span>";
484 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
485 <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
487 <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
489 <div class="dashboard-comment-wrap">
490 <h4 class="comment-meta">
491 <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
492 '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
497 switch ( $comment->comment_type ) :
499 $type = __( 'Pingback' );
502 $type = __( 'Trackback' );
505 $type = ucwords( $comment->comment_type );
507 $type = esc_html( $type );
509 <div class="dashboard-comment-wrap">
510 <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
511 <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
512 <p class="comment-author"><?php comment_author_link(); ?></p>
514 <?php endif; // comment_type ?>
515 <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
516 <p class="row-actions"><?php echo $actions_string; ?></p>
523 * Callback function for Activity widget.
527 function wp_dashboard_site_activity() {
529 echo '<div id="activity-widget">';
531 $future_posts = wp_dashboard_recent_posts( array(
534 'status' => 'future',
536 'title' => __( 'Publishing Soon' ),
537 'id' => 'future-posts',
539 $recent_posts = wp_dashboard_recent_posts( array(
542 'status' => 'publish',
544 'title' => __( 'Recently Published' ),
545 'id' => 'published-posts',
548 $recent_comments = wp_dashboard_recent_comments();
550 if ( !$future_posts && !$recent_posts && !$recent_comments ) {
551 echo '<div class="no-activity">';
552 echo '<p class="smiley"></p>';
553 echo '<p>' . __( 'No activity yet!' ) . '</p>';
561 * Generates Publishing Soon and Recently Published sections.
565 * @param array $args {
566 * An array of query and display arguments.
568 * @type int $display Number of posts to display.
569 * @type int $max Maximum number of posts to query.
570 * @type string $status Post status.
571 * @type string $order Designates ascending ('ASC') or descending ('DESC') order.
572 * @type string $title Section title.
573 * @type string $id The container id.
575 * @return bool False if no posts were found. True otherwise.
577 function wp_dashboard_recent_posts( $args ) {
579 'post_type' => 'post',
580 'post_status' => $args['status'],
582 'order' => $args['order'],
583 'posts_per_page' => intval( $args['max'] ),
584 'no_found_rows' => true,
585 'cache_results' => false
587 $posts = new WP_Query( $query_args );
589 if ( $posts->have_posts() ) {
591 echo '<div id="' . $args['id'] . '" class="activity-block">';
593 if ( $posts->post_count > $args['display'] ) {
594 echo '<small class="show-more hide-if-no-js"><a href="#">' . sprintf( __( 'See %s more…'), $posts->post_count - intval( $args['display'] ) ) . '</a></small>';
597 echo '<h4>' . $args['title'] . '</h4>';
602 $today = date( 'Y-m-d', current_time( 'timestamp' ) );
603 $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
605 while ( $posts->have_posts() ) {
608 $time = get_the_time( 'U' );
609 if ( date( 'Y-m-d', $time ) == $today ) {
610 $relative = __( 'Today' );
611 } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
612 $relative = __( 'Tomorrow' );
614 /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
615 $relative = date_i18n( __( 'M jS' ), $time );
619 /* translators: 1: relative date, 2: time, 4: post title */
620 __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' ),
623 get_edit_post_link(),
624 _draft_or_post_title()
627 $hidden = $i >= $args['display'] ? ' class="hidden"' : '';
628 echo "<li{$hidden}>$text</li>";
645 * Show Comments section.
649 * @param int $total_items Optional. Number of comments to query. Default 5.
650 * @return bool False if no comments were found. True otherwise.
652 function wp_dashboard_recent_comments( $total_items = 5 ) {
655 // Select all comment types and filter out spam later for better query performance.
659 $comments_query = array(
660 'number' => $total_items * 5,
663 if ( ! current_user_can( 'edit_posts' ) )
664 $comments_query['status'] = 'approve';
666 while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
667 foreach ( $possible as $comment ) {
668 if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
670 $comments[] = $comment;
671 if ( count( $comments ) == $total_items )
674 $comments_query['offset'] += $comments_query['number'];
675 $comments_query['number'] = $total_items * 10;
681 echo '<div id="latest-comments" class="activity-block">';
682 echo '<h4>' . __( 'Comments' ) . '</h4>';
684 echo '<div id="the-comment-list" data-wp-lists="list:comment">';
685 foreach ( $comments as $comment )
686 _wp_dashboard_recent_comments_row( $comment );
689 if ( current_user_can('edit_posts') )
690 _get_list_table('WP_Comments_List_Table')->views();
692 wp_comment_reply( -1, false, 'dashboard', false );
693 wp_comment_trashnotice();
703 * Display generic dashboard RSS widget feed.
707 * @param string $widget_id
709 function wp_dashboard_rss_output( $widget_id ) {
710 $widgets = get_option( 'dashboard_widget_options' );
711 echo '<div class="rss-widget">';
712 wp_widget_rss_output( $widgets[ $widget_id ] );
717 * Checks to see if all of the feed url in $check_urls are cached.
719 * If $check_urls is empty, look for the rss feed url found in the dashboard
720 * widget options of $widget_id. If cached, call $callback, a function that
721 * echoes out output for this widget. If not cache, echo a "Loading..." stub
722 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
726 * @param string $widget_id
727 * @param callback $callback
728 * @param array $check_urls RSS feeds
729 * @return bool False on failure. True on success.
731 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
732 $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
733 $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
735 if ( empty($check_urls) ) {
736 $widgets = get_option( 'dashboard_widget_options' );
737 if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
741 $check_urls = array( $widgets[$widget_id]['url'] );
744 $cache_key = 'dash_' . md5( $widget_id );
745 if ( false !== ( $output = get_transient( $cache_key ) ) ) {
750 if ( ! $doing_ajax ) {
755 if ( $callback && is_callable( $callback ) ) {
756 $args = array_slice( func_get_args(), 2 );
757 array_unshift( $args, $widget_id );
759 call_user_func_array( $callback, $args );
760 set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
766 /* Dashboard Widgets Controls */
768 // Calls widget_control callback
770 * Calls widget control callback.
774 * @param int $widget_control_id Registered Widget ID.
776 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
777 global $wp_dashboard_control_callbacks;
779 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]) ) {
780 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
785 * The RSS dashboard widget control.
787 * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
788 * from RSS-type widgets.
792 * @param string $widget_id
793 * @param array $form_inputs
795 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
796 if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
797 $widget_options = array();
799 if ( !isset($widget_options[$widget_id]) )
800 $widget_options[$widget_id] = array();
802 $number = 1; // Hack to use wp_widget_rss_form()
803 $widget_options[$widget_id]['number'] = $number;
805 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
806 $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
807 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
808 $widget_options[$widget_id]['number'] = $number;
809 // title is optional. If black, fill it if possible
810 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
811 $rss = fetch_feed($widget_options[$widget_id]['url']);
812 if ( is_wp_error($rss) ) {
813 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
815 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
820 update_option( 'dashboard_widget_options', $widget_options );
821 $cache_key = 'dash_' . md5( $widget_id );
822 delete_transient( $cache_key );
825 wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
829 * WordPress News dashboard widget.
833 function wp_dashboard_primary() {
836 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
837 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
838 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
845 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
846 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
847 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
855 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' ) ) ) {
856 $feeds['plugins'] = array(
859 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
869 wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
873 * Display the WordPress news feeds.
877 * @param string $widget_id Widget ID.
878 * @param array $feeds Array of RSS feeds.
880 function wp_dashboard_primary_output( $widget_id, $feeds ) {
881 foreach( $feeds as $type => $args ) {
882 $args['type'] = $type;
883 echo '<div class="rss-widget">';
884 if ( $type === 'plugins' ) {
885 wp_dashboard_plugins_output( $args['url'], $args );
887 wp_widget_rss_output( $args['url'], $args );
894 * Display plugins text for the WordPress news widget.
898 function wp_dashboard_plugins_output( $rss, $args = array() ) {
899 // Plugin feeds plus link to install them
900 $popular = fetch_feed( $args['url']['popular'] );
902 if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
903 $plugin_slugs = array_keys( get_plugins() );
904 set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
910 'popular' => __( 'Popular Plugin' )
911 ) as $feed => $label ) {
912 if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
915 $items = $$feed->get_items(0, 5);
917 // Pick a random, non-installed plugin
919 // Abort this foreach loop iteration if there's no plugins left of this type
920 if ( 0 == count($items) )
923 $item_key = array_rand($items);
924 $item = $items[$item_key];
926 list($link, $frag) = explode( '#', $item->get_link() );
928 $link = esc_url($link);
929 if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
932 unset( $items[$item_key] );
936 // Is this random plugin's slug already installed? If so, try again.
937 reset( $plugin_slugs );
938 foreach ( $plugin_slugs as $plugin_slug ) {
939 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
940 unset( $items[$item_key] );
945 // If we get to this point, then the random plugin isn't installed and we can stop the while().
949 // Eliminate some common badly formed plugin descriptions
950 while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
951 unset($items[$item_key]);
953 if ( !isset($items[$item_key]) )
956 $title = esc_html( $item->get_title() );
958 $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
960 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800';
962 echo "<li class='dashboard-news-plugin'><span>$label:</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
964 $$feed->__destruct();
972 * Display file upload quota on dashboard.
974 * Runs on the activity_box_end hook in wp_dashboard_right_now().
978 * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
980 function wp_dashboard_quota() {
981 if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
984 $quota = get_space_allowed();
985 $used = get_space_used();
987 if ( $used > $quota )
988 $percentused = '100';
990 $percentused = ( $used / $quota ) * 100;
991 $used_class = ( $percentused >= 70 ) ? ' warning' : '';
992 $used = round( $used, 2 );
993 $percentused = number_format( $percentused );
996 <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
997 <div class="mu-storage">
999 <li class="storage-count">
1000 <?php $text = sprintf(
1001 /* translators: number of megabytes */
1002 __( '%s MB Space Allowed' ),
1003 number_format_i18n( $quota )
1006 '<a href="%1$s" title="%2$s">%3$s</a>',
1007 esc_url( admin_url( 'upload.php' ) ),
1008 __( 'Manage Uploads' ),
1011 </li><li class="storage-count <?php echo $used_class; ?>">
1012 <?php $text = sprintf(
1013 /* translators: 1: number of megabytes, 2: percentage */
1014 __( '%1$s MB (%2$s%%) Space Used' ),
1015 number_format_i18n( $used, 2 ),
1019 '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
1020 esc_url( admin_url( 'upload.php' ) ),
1021 __( 'Manage Uploads' ),
1029 add_action( 'activity_box_end', 'wp_dashboard_quota' );
1031 // Display Browser Nag Meta Box
1032 function wp_dashboard_browser_nag() {
1034 $response = wp_check_browser_version();
1037 if ( $response['insecure'] ) {
1038 $msg = sprintf( __( "It looks like you're using an insecure version of <a href='%s'>%s</a>. Using an outdated browser makes your computer unsafe. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
1040 $msg = sprintf( __( "It looks like you're using an old version of <a href='%s'>%s</a>. For the best WordPress experience, please update your browser." ), esc_attr( $response['update_url'] ), esc_html( $response['name'] ) );
1043 $browser_nag_class = '';
1044 if ( !empty( $response['img_src'] ) ) {
1045 $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
1047 $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
1048 $browser_nag_class = ' has-browser-icon';
1050 $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1052 $browsehappy = 'http://browsehappy.com/';
1053 $locale = get_locale();
1054 if ( 'en_US' !== $locale )
1055 $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1057 $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>';
1058 $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
1059 $notice .= '<div class="clear"></div>';
1062 echo apply_filters( 'browse-happy-notice', $notice, $response );
1065 function dashboard_browser_nag_class( $classes ) {
1066 $response = wp_check_browser_version();
1068 if ( $response && $response['insecure'] )
1069 $classes[] = 'browser-insecure';
1075 * Check if the user needs a browser update
1079 * @return array|bool False on failure, array of browser data on success.
1081 function wp_check_browser_version() {
1082 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1085 $key = md5( $_SERVER['HTTP_USER_AGENT'] );
1087 if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
1091 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1092 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
1095 $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
1097 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
1101 * Response should be an array with:
1102 * 'name' - string - A user friendly browser name
1103 * 'version' - string - The most recent version of the browser
1104 * 'current_version' - string - The version of the browser the user is using
1105 * 'upgrade' - boolean - Whether the browser needs an upgrade
1106 * 'insecure' - boolean - Whether the browser is deemed insecure
1107 * 'upgrade_url' - string - The url to visit to upgrade
1108 * 'img_src' - string - An image representing the browser
1109 * 'img_src_ssl' - string - An image (over SSL) representing the browser
1111 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1113 if ( ! is_array( $response ) )
1116 set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1123 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1125 function wp_dashboard_empty() {}
1128 * Displays a welcome panel to introduce users to WordPress.
1132 function wp_welcome_panel() {
1134 <div class="welcome-panel-content">
1135 <h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
1136 <p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
1137 <div class="welcome-panel-column-container">
1138 <div class="welcome-panel-column">
1139 <h4><?php _e( 'Get Started' ); ?></h4>
1140 <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>
1141 <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
1142 <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
1143 <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
1146 <div class="welcome-panel-column">
1147 <h4><?php _e( 'Next Steps' ); ?></h4>
1149 <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
1150 <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>
1151 <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>
1152 <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
1153 <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>
1154 <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>
1155 <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1157 <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1158 <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>
1160 <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
1163 <div class="welcome-panel-column welcome-panel-last">
1164 <h4><?php _e( 'More Actions' ); ?></h4>
1166 <li><?php printf( '<div class="welcome-icon welcome-widgets-menus">' . __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ) . '</div>', admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) ); ?></li>
1167 <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
1168 <li><?php printf( '<a href="%s" class="welcome-icon welcome-learn-more">' . __( 'Learn more about getting started' ) . '</a>', __( 'http://codex.wordpress.org/First_Steps_With_WordPress' ) ); ?></li>