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 printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
201 $num_comm = wp_count_comments();
202 if ( $num_comm && $num_comm->total_comments ) {
203 $text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) );
205 <li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
207 if ( $num_comm->moderated ) {
208 /* translators: Number of comments in moderation */
209 $text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
211 <li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
217 * Include additional elements in the 'At a Glance' dashboard widget.
218 * This widget was previously 'Right Now'.
221 * @param array $items Array of items.
223 $elements = apply_filters( 'dashboard_glance_items', array() );
225 echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
230 <p><?php printf( __( 'WordPress %1$s running %2$s theme.' ), get_bloginfo( 'version', 'display' ), $theme_name ); ?></p>
233 // Check if search engines are asked not to index this site.
234 if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) {
237 * Filter the title attribute for the link displayed in Site Content metabox when search engines are discouraged from indexing the site.
241 * @param string Default attribute text.
243 $title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) );
246 * Filter the text for the link displayed in Site Content metabox when search engines are discouraged from indexing the site.
250 * @param string Default text.
252 $content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
254 echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
259 // activity_box_end has a core action, but only prints content when multisite.
260 // Using an output buffer is the only way to really check if anything's displayed here.
262 do_action( 'rightnow_end' );
263 do_action( 'activity_box_end' );
264 $actions = ob_get_clean();
266 if ( !empty( $actions ) ) : ?>
268 <?php echo $actions; ?>
273 function wp_network_dashboard_right_now() {
275 if ( current_user_can('create_sites') )
276 $actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
277 if ( current_user_can('create_users') )
278 $actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
280 $c_users = get_user_count();
281 $c_blogs = get_blog_count();
283 $user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
284 $blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
286 $sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
289 echo '<ul class="subsubsub">';
290 foreach ( $actions as $class => $action ) {
291 $actions[ $class ] = "\t<li class='$class'>$action";
293 echo implode( " |</li>\n", $actions ) . "</li>\n";
299 <p class="youhave"><?php echo $sentence; ?></p>
300 <?php do_action( 'wpmuadminresult', '' ); ?>
302 <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
304 <input type="search" name="s" value="" size="30" autocomplete="off" />
305 <?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
309 <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
311 <input type="search" name="s" value="" size="30" autocomplete="off" />
312 <?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
316 do_action( 'mu_rightnow_end' );
317 do_action( 'mu_activity_box_end' );
321 * The Quick Draft widget display and creation of drafts.
325 * @param string $error_msg Optional. Error message. Default false.
327 function wp_dashboard_quick_press( $error_msg = false ) {
330 /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
331 $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
332 if ( $last_post_id ) {
333 $post = get_post( $last_post_id );
334 if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
335 $post = get_default_post_to_edit( 'post', true );
336 update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
338 $post->post_title = ''; // Remove the auto draft title
341 $post = get_default_post_to_edit( 'post' , true);
342 $user_id = get_current_user_id();
343 // Don't create an option if this is a super admin who does not belong to this site.
344 if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
345 update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
348 $post_ID = (int) $post->ID;
351 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
353 <?php if ( $error_msg ) : ?>
354 <div class="error"><?php echo $error_msg; ?></div>
357 <div class="input-text-wrap" id="title-wrap">
358 <label class="screen-reader-text prompt" for="title" id="title-prompt-text"><?php echo apply_filters( 'enter_title_here', __( 'Title' ), $post ); ?></label>
359 <input type="text" name="post_title" id="title" autocomplete="off" />
362 <div class="textarea-wrap" id="description-wrap">
363 <label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label>
364 <textarea name="content" id="content" class="mceEditor" rows="3" cols="15"></textarea>
368 <input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
369 <input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
370 <input type="hidden" name="post_type" value="post" />
371 <?php wp_nonce_field( 'add-post' ); ?>
372 <?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
378 wp_dashboard_recent_drafts();
382 * Show recent drafts of the user on the dashboard.
386 function wp_dashboard_recent_drafts( $drafts = false ) {
389 'post_type' => 'post',
390 'post_status' => 'draft',
391 'author' => get_current_user_id(),
392 'posts_per_page' => 4,
393 'orderby' => 'modified',
396 $drafts = get_posts( $query_args );
402 echo '<div class="drafts">';
403 if ( count( $drafts ) > 3 ) {
404 echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n";
406 echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>";
408 $drafts = array_slice( $drafts, 0, 3 );
409 foreach ( $drafts as $draft ) {
410 $url = get_edit_post_link( $draft->ID );
411 $title = _draft_or_post_title( $draft->ID );
413 echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
414 echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
415 if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
416 echo '<p>' . $the_content . '</p>';
420 echo "</ul>\n</div>";
423 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
424 $GLOBALS['comment'] =& $comment;
426 $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
427 $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
428 $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
429 $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
431 $actions_string = '';
432 if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
433 // preorder it: Approve | Reply | Edit | Spam | Trash
435 'approve' => '', 'unapprove' => '',
439 'trash' => '', 'delete' => ''
442 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
443 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
445 $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
446 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
447 $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
448 $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
449 $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
451 $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>';
452 $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>';
453 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
454 $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>';
455 $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>';
456 if ( !EMPTY_TRASH_DAYS )
457 $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>';
459 $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>';
461 $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
464 foreach ( $actions as $action => $link ) {
466 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
468 // Reply and quickedit need a hide-if-no-js span
469 if ( 'reply' == $action || 'quickedit' == $action )
470 $action .= ' hide-if-no-js';
472 $actions_string .= "<span class='$action'>$sep$link</span>";
478 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
479 <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
481 <?php echo get_avatar( $comment, 50, 'mystery' ); ?>
483 <div class="dashboard-comment-wrap">
484 <h4 class="comment-meta">
485 <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
486 '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
491 switch ( $comment->comment_type ) :
493 $type = __( 'Pingback' );
496 $type = __( 'Trackback' );
499 $type = ucwords( $comment->comment_type );
501 $type = esc_html( $type );
503 <div class="dashboard-comment-wrap">
504 <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
505 <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
506 <p class="comment-author"><?php comment_author_link(); ?></p>
508 <?php endif; // comment_type ?>
509 <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
510 <p class="row-actions"><?php echo $actions_string; ?></p>
517 * Callback function for Activity widget.
521 function wp_dashboard_site_activity() {
523 echo '<div id="activity-widget">';
525 $future_posts = wp_dashboard_recent_posts( array(
528 'status' => 'future',
530 'title' => __( 'Publishing Soon' ),
531 'id' => 'future-posts',
533 $recent_posts = wp_dashboard_recent_posts( array(
536 'status' => 'publish',
538 'title' => __( 'Recently Published' ),
539 'id' => 'published-posts',
542 $recent_comments = wp_dashboard_recent_comments();
544 if ( !$future_posts && !$recent_posts && !$recent_comments ) {
545 echo '<div class="no-activity">';
546 echo '<p class="smiley"></p>';
547 echo '<p>' . __( 'No activity yet!' ) . '</p>';
555 * Generates Publishing Soon and Recently Published sections.
559 * @param array $args {
560 * An array of query and display arguments.
562 * @type int $display Number of posts to display.
563 * @type int $max Maximum number of posts to query.
564 * @type string $status Post status.
565 * @type string $order Designates ascending ('ASC') or descending ('DESC') order.
566 * @type string $title Section title.
567 * @type string $id The container id.
569 * @return bool False if no posts were found. True otherwise.
571 function wp_dashboard_recent_posts( $args ) {
573 'post_type' => 'post',
574 'post_status' => $args['status'],
576 'order' => $args['order'],
577 'posts_per_page' => intval( $args['max'] ),
578 'no_found_rows' => true,
579 'cache_results' => false
581 $posts = new WP_Query( $query_args );
583 if ( $posts->have_posts() ) {
585 echo '<div id="' . $args['id'] . '" class="activity-block">';
587 if ( $posts->post_count > $args['display'] ) {
588 echo '<small class="show-more hide-if-no-js"><a href="#">' . sprintf( __( 'See %s more…'), $posts->post_count - intval( $args['display'] ) ) . '</a></small>';
591 echo '<h4>' . $args['title'] . '</h4>';
596 $today = date( 'Y-m-d', current_time( 'timestamp' ) );
597 $tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
599 while ( $posts->have_posts() ) {
602 $time = get_the_time( 'U' );
603 if ( date( 'Y-m-d', $time ) == $today ) {
604 $relative = __( 'Today' );
605 } elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
606 $relative = __( 'Tomorrow' );
608 /* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
609 $relative = date_i18n( __( 'M jS' ), $time );
613 /* translators: 1: relative date, 2: time, 4: post title */
614 __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' ),
617 get_edit_post_link(),
618 _draft_or_post_title()
621 $hidden = $i >= $args['display'] ? ' class="hidden"' : '';
622 echo "<li{$hidden}>$text</li>";
639 * Show Comments section.
643 * @param int $total_items Optional. Number of comments to query. Default 5.
644 * @return bool False if no comments were found. True otherwise.
646 function wp_dashboard_recent_comments( $total_items = 5 ) {
649 // Select all comment types and filter out spam later for better query performance.
653 $comments_query = array(
654 'number' => $total_items * 5,
657 if ( ! current_user_can( 'edit_posts' ) )
658 $comments_query['status'] = 'approve';
660 while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
661 foreach ( $possible as $comment ) {
662 if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
664 $comments[] = $comment;
665 if ( count( $comments ) == $total_items )
668 $comments_query['offset'] += $comments_query['number'];
669 $comments_query['number'] = $total_items * 10;
675 echo '<div id="latest-comments" class="activity-block">';
676 echo '<h4>' . __( 'Comments' ) . '</h4>';
678 echo '<div id="the-comment-list" data-wp-lists="list:comment">';
679 foreach ( $comments as $comment )
680 _wp_dashboard_recent_comments_row( $comment );
683 if ( current_user_can('edit_posts') )
684 _get_list_table('WP_Comments_List_Table')->views();
686 wp_comment_reply( -1, false, 'dashboard', false );
687 wp_comment_trashnotice();
697 * Display generic dashboard RSS widget feed.
701 * @param string $widget_id
703 function wp_dashboard_rss_output( $widget_id ) {
704 $widgets = get_option( 'dashboard_widget_options' );
705 echo '<div class="rss-widget">';
706 wp_widget_rss_output( $widgets[ $widget_id ] );
711 * Checks to see if all of the feed url in $check_urls are cached.
713 * If $check_urls is empty, look for the rss feed url found in the dashboard
714 * widget options of $widget_id. If cached, call $callback, a function that
715 * echoes out output for this widget. If not cache, echo a "Loading..." stub
716 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
720 * @param string $widget_id
721 * @param callback $callback
722 * @param array $check_urls RSS feeds
723 * @return bool False on failure. True on success.
725 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
726 $loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
727 $doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
729 if ( empty($check_urls) ) {
730 $widgets = get_option( 'dashboard_widget_options' );
731 if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
735 $check_urls = array( $widgets[$widget_id]['url'] );
738 $cache_key = 'dash_' . md5( $widget_id );
739 if ( false !== ( $output = get_transient( $cache_key ) ) ) {
744 if ( ! $doing_ajax ) {
749 if ( $callback && is_callable( $callback ) ) {
750 $args = array_slice( func_get_args(), 2 );
751 array_unshift( $args, $widget_id );
753 call_user_func_array( $callback, $args );
754 set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
760 /* Dashboard Widgets Controls */
762 // Calls widget_control callback
764 * Calls widget control callback.
768 * @param int $widget_control_id Registered Widget ID.
770 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
771 global $wp_dashboard_control_callbacks;
773 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]) ) {
774 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
779 * The RSS dashboard widget control.
781 * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
782 * from RSS-type widgets.
786 * @param string $widget_id
787 * @param array $form_inputs
789 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
790 if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
791 $widget_options = array();
793 if ( !isset($widget_options[$widget_id]) )
794 $widget_options[$widget_id] = array();
796 $number = 1; // Hack to use wp_widget_rss_form()
797 $widget_options[$widget_id]['number'] = $number;
799 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
800 $_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
801 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
802 $widget_options[$widget_id]['number'] = $number;
803 // title is optional. If black, fill it if possible
804 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
805 $rss = fetch_feed($widget_options[$widget_id]['url']);
806 if ( is_wp_error($rss) ) {
807 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
809 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
814 update_option( 'dashboard_widget_options', $widget_options );
815 $cache_key = 'dash_' . md5( $widget_id );
816 delete_transient( $cache_key );
819 wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
823 * WordPress News dashboard widget.
827 function wp_dashboard_primary() {
830 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
831 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
832 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
839 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
840 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
841 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
849 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' ) ) ) {
850 $feeds['plugins'] = array(
853 'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
863 wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
867 * Display the WordPress news feeds.
871 * @param string $widget_id Widget ID.
872 * @param array $feeds Array of RSS feeds.
874 function wp_dashboard_primary_output( $widget_id, $feeds ) {
875 foreach( $feeds as $type => $args ) {
876 $args['type'] = $type;
877 echo '<div class="rss-widget">';
878 if ( $type === 'plugins' ) {
879 wp_dashboard_plugins_output( $args['url'], $args );
881 wp_widget_rss_output( $args['url'], $args );
888 * Display plugins text for the WordPress news widget.
892 function wp_dashboard_plugins_output( $rss, $args = array() ) {
893 // Plugin feeds plus link to install them
894 $popular = fetch_feed( $args['url']['popular'] );
896 if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
897 $plugin_slugs = array_keys( get_plugins() );
898 set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
904 'popular' => __( 'Popular Plugin' )
905 ) as $feed => $label ) {
906 if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
909 $items = $$feed->get_items(0, 5);
911 // Pick a random, non-installed plugin
913 // Abort this foreach loop iteration if there's no plugins left of this type
914 if ( 0 == count($items) )
917 $item_key = array_rand($items);
918 $item = $items[$item_key];
920 list($link, $frag) = explode( '#', $item->get_link() );
922 $link = esc_url($link);
923 if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
926 unset( $items[$item_key] );
930 // Is this random plugin's slug already installed? If so, try again.
931 reset( $plugin_slugs );
932 foreach ( $plugin_slugs as $plugin_slug ) {
933 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
934 unset( $items[$item_key] );
939 // If we get to this point, then the random plugin isn't installed and we can stop the while().
943 // Eliminate some common badly formed plugin descriptions
944 while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
945 unset($items[$item_key]);
947 if ( !isset($items[$item_key]) )
950 $title = esc_html( $item->get_title() );
952 $description = esc_html( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ) ) );
954 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800';
956 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>";
958 $$feed->__destruct();
966 * Display file upload quota on dashboard.
968 * Runs on the activity_box_end hook in wp_dashboard_right_now().
972 * @return bool True if not multisite, user can't upload files, or the space check option is disabled.
974 function wp_dashboard_quota() {
975 if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
978 $quota = get_space_allowed();
979 $used = get_space_used();
981 if ( $used > $quota )
982 $percentused = '100';
984 $percentused = ( $used / $quota ) * 100;
985 $used_class = ( $percentused >= 70 ) ? ' warning' : '';
986 $used = round( $used, 2 );
987 $percentused = number_format( $percentused );
990 <h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
991 <div class="mu-storage">
993 <li class="storage-count">
994 <?php $text = sprintf(
995 /* translators: number of megabytes */
996 __( '%s MB Space Allowed' ),
997 number_format_i18n( $quota )
1000 '<a href="%1$s" title="%2$s">%3$s</a>',
1001 esc_url( admin_url( 'upload.php' ) ),
1002 __( 'Manage Uploads' ),
1005 </li><li class="storage-count <?php echo $used_class; ?>">
1006 <?php $text = sprintf(
1007 /* translators: 1: number of megabytes, 2: percentage */
1008 __( '%1$s MB (%2$s%%) Space Used' ),
1009 number_format_i18n( $used, 2 ),
1013 '<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
1014 esc_url( admin_url( 'upload.php' ) ),
1015 __( 'Manage Uploads' ),
1023 add_action( 'activity_box_end', 'wp_dashboard_quota' );
1025 // Display Browser Nag Meta Box
1026 function wp_dashboard_browser_nag() {
1028 $response = wp_check_browser_version();
1031 if ( $response['insecure'] ) {
1032 $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'] ) );
1034 $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'] ) );
1037 $browser_nag_class = '';
1038 if ( !empty( $response['img_src'] ) ) {
1039 $img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
1041 $notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
1042 $browser_nag_class = ' has-browser-icon';
1044 $notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1046 $browsehappy = 'http://browsehappy.com/';
1047 $locale = get_locale();
1048 if ( 'en_US' !== $locale )
1049 $browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1051 $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>';
1052 $notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
1053 $notice .= '<div class="clear"></div>';
1056 echo apply_filters( 'browse-happy-notice', $notice, $response );
1059 function dashboard_browser_nag_class( $classes ) {
1060 $response = wp_check_browser_version();
1062 if ( $response && $response['insecure'] )
1063 $classes[] = 'browser-insecure';
1069 * Check if the user needs a browser update
1073 * @return array|bool False on failure, array of browser data on success.
1075 function wp_check_browser_version() {
1076 if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1079 $key = md5( $_SERVER['HTTP_USER_AGENT'] );
1081 if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
1085 'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1086 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
1089 $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
1091 if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
1095 * Response should be an array with:
1096 * 'name' - string - A user friendly browser name
1097 * 'version' - string - The most recent version of the browser
1098 * 'current_version' - string - The version of the browser the user is using
1099 * 'upgrade' - boolean - Whether the browser needs an upgrade
1100 * 'insecure' - boolean - Whether the browser is deemed insecure
1101 * 'upgrade_url' - string - The url to visit to upgrade
1102 * 'img_src' - string - An image representing the browser
1103 * 'img_src_ssl' - string - An image (over SSL) representing the browser
1105 $response = json_decode( wp_remote_retrieve_body( $response ), true );
1107 if ( ! is_array( $response ) )
1110 set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1117 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1119 function wp_dashboard_empty() {}
1122 * Displays a welcome panel to introduce users to WordPress.
1126 function wp_welcome_panel() {
1128 <div class="welcome-panel-content">
1129 <h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
1130 <p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
1131 <div class="welcome-panel-column-container">
1132 <div class="welcome-panel-column">
1133 <h4><?php _e( 'Get Started' ); ?></h4>
1134 <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>
1135 <a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
1136 <?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
1137 <p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
1140 <div class="welcome-panel-column">
1141 <h4><?php _e( 'Next Steps' ); ?></h4>
1143 <?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
1144 <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>
1145 <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>
1146 <?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
1147 <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>
1148 <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>
1149 <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1151 <li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1152 <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>
1154 <li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
1157 <div class="welcome-panel-column welcome-panel-last">
1158 <h4><?php _e( 'More Actions' ); ?></h4>
1160 <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>
1161 <li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
1162 <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>