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();
21
/* Register Widgets and Controls */
23
$response = wp_check_browser_version();
25
if ( $response && $response['upgrade'] ) {
26
add_filter( 'postbox_classes_dashboard_dashboard_browser_nag', 'dashboard_browser_nag_class' );
27
if ( $response['insecure'] )
28
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'You are using an insecure browser!' ), 'wp_dashboard_browser_nag' );
30
wp_add_dashboard_widget( 'dashboard_browser_nag', __( 'Your browser is out of date!' ), 'wp_dashboard_browser_nag' );
34
if ( is_blog_admin() && current_user_can('edit_posts') )
35
wp_add_dashboard_widget( 'dashboard_right_now', __( 'At a Glance' ), 'wp_dashboard_right_now' );
37
if ( is_network_admin() )
38
wp_add_dashboard_widget( 'network_dashboard_right_now', __( 'Right Now' ), 'wp_network_dashboard_right_now' );
41
if ( is_blog_admin() ) {
42
wp_add_dashboard_widget( 'dashboard_activity', __( 'Activity' ), 'wp_dashboard_site_activity' );
46
if ( is_blog_admin() && current_user_can( 'edit_posts' ) ) {
47
$quick_draft_title = sprintf( '<span class="hide-if-no-js">%1$s</span> <span class="hide-if-js">%2$s</span>', __( 'Quick Draft' ), __( 'Drafts' ) );
48
wp_add_dashboard_widget( 'dashboard_quick_press', $quick_draft_title, 'wp_dashboard_quick_press' );
52
wp_add_dashboard_widget( 'dashboard_primary', __( 'WordPress News' ), 'wp_dashboard_primary' );
54
if ( is_network_admin() ) {
57
* Fires after core widgets for the Network Admin dashboard have been registered.
61
do_action( 'wp_network_dashboard_setup' );
64
* Filter the list of widgets to load for the Network Admin dashboard.
68
* @param array $dashboard_widgets An array of dashboard widgets.
70
$dashboard_widgets = apply_filters( 'wp_network_dashboard_widgets', array() );
71
} elseif ( is_user_admin() ) {
74
* Fires after core widgets for the User Admin dashboard have been registered.
78
do_action( 'wp_user_dashboard_setup' );
81
* Filter the list of widgets to load for the User Admin dashboard.
85
* @param array $dashboard_widgets An array of dashboard widgets.
87
$dashboard_widgets = apply_filters( 'wp_user_dashboard_widgets', array() );
91
* Fires after core widgets for the admin dashboard have been registered.
95
do_action( 'wp_dashboard_setup' );
98
* Filter the list of widgets to load for the admin dashboard.
102
* @param array $dashboard_widgets An array of dashboard widgets.
104
$dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
107
foreach ( $dashboard_widgets as $widget_id ) {
108
$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>';
109
wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
112
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
113
check_admin_referer( 'edit-dashboard-widget_' . $_POST['widget_id'], 'dashboard-widget-nonce' );
114
ob_start(); // hack - but the same hack wp-admin/widgets.php uses
115
wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
117
wp_redirect( remove_query_arg( 'edit' ) );
121
/** This action is documented in wp-admin/edit-form-advanced.php */
122
do_action( 'do_meta_boxes', $screen->id, 'normal', '' );
124
/** This action is documented in wp-admin/edit-form-advanced.php */
125
do_action( 'do_meta_boxes', $screen->id, 'side', '' );
128
function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null, $callback_args = null ) {
129
$screen = get_current_screen();
130
global $wp_dashboard_control_callbacks;
132
if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
133
$wp_dashboard_control_callbacks[$widget_id] = $control_callback;
134
if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
135
list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
136
$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
137
$callback = '_wp_dashboard_control_callback';
139
list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
140
$widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
144
$side_widgets = array( 'dashboard_quick_press', 'dashboard_primary' );
146
$location = 'normal';
147
if ( in_array($widget_id, $side_widgets) )
151
if ( 'dashboard_browser_nag' === $widget_id )
154
add_meta_box( $widget_id, $widget_name, $callback, $screen, $location, $priority, $callback_args );
157
function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
158
echo '<form action="" method="post" class="dashboard-widget-control-form">';
159
wp_dashboard_trigger_widget_control( $meta_box['id'] );
160
wp_nonce_field( 'edit-dashboard-widget_' . $meta_box['id'], 'dashboard-widget-nonce' );
161
echo '<input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" />';
162
submit_button( __('Submit') );
167
* Displays the dashboard.
171
function wp_dashboard() {
172
$screen = get_current_screen();
173
$columns = absint( $screen->get_columns() );
176
$columns_css = " columns-$columns";
180
<div id="dashboard-widgets" class="metabox-holder<?php echo $columns_css; ?>">
181
<div id="postbox-container-1" class="postbox-container">
182
<?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
184
<div id="postbox-container-2" class="postbox-container">
185
<?php do_meta_boxes( $screen->id, 'side', '' ); ?>
187
<div id="postbox-container-3" class="postbox-container">
188
<?php do_meta_boxes( $screen->id, 'column3', '' ); ?>
190
<div id="postbox-container-4" class="postbox-container">
191
<?php do_meta_boxes( $screen->id, 'column4', '' ); ?>
196
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
197
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
206
* Dashboard widget that displays some basic stats about the site.
208
* Formerly 'Right Now'. A streamlined 'At a Glance' as of 3.8.
212
function wp_dashboard_right_now() {
218
foreach ( array( 'post', 'page' ) as $post_type ) {
219
$num_posts = wp_count_posts( $post_type );
220
if ( $num_posts && $num_posts->publish ) {
221
if ( 'post' == $post_type ) {
222
$text = _n( '%s Post', '%s Posts', $num_posts->publish );
224
$text = _n( '%s Page', '%s Pages', $num_posts->publish );
226
$text = sprintf( $text, number_format_i18n( $num_posts->publish ) );
227
$post_type_object = get_post_type_object( $post_type );
228
if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
229
printf( '<li class="%1$s-count"><a href="edit.php?post_type=%1$s">%2$s</a></li>', $post_type, $text );
231
printf( '<li class="%1$s-count"><span>%2$s</span></li>', $post_type, $text );
237
$num_comm = wp_count_comments();
238
if ( $num_comm && $num_comm->total_comments ) {
239
$text = sprintf( _n( '%s Comment', '%s Comments', $num_comm->total_comments ), number_format_i18n( $num_comm->total_comments ) );
241
<li class="comment-count"><a href="edit-comments.php"><?php echo $text; ?></a></li>
243
if ( $num_comm->moderated ) {
244
/* translators: Number of comments in moderation */
245
$text = sprintf( _nx( '%s in moderation', '%s in moderation', $num_comm->moderated, 'comments' ), number_format_i18n( $num_comm->moderated ) );
247
<li class="comment-mod-count"><a href="edit-comments.php?comment_status=moderated"><?php echo $text; ?></a></li>
253
* Filter the array of extra elements to list in the 'At a Glance'
256
* Prior to 3.8.0, the widget was named 'Right Now'. Each element
257
* is wrapped in list-item tags on output.
261
* @param array $items Array of extra 'At a Glance' widget items.
263
$elements = apply_filters( 'dashboard_glance_items', array() );
266
echo '<li>' . implode( "</li>\n<li>", $elements ) . "</li>\n";
272
update_right_now_message();
274
// Check if search engines are asked not to index this site.
275
if ( ! is_network_admin() && ! is_user_admin() && current_user_can( 'manage_options' ) && '1' != get_option( 'blog_public' ) ) {
278
* Filter the link title attribute for the 'Search Engines Discouraged'
279
* message displayed in the 'At a Glance' dashboard widget.
281
* Prior to 3.8.0, the widget was named 'Right Now'.
285
* @param string $title Default attribute text.
287
$title = apply_filters( 'privacy_on_link_title', __( 'Your site is asking search engines not to index its content' ) );
290
* Filter the link label for the 'Search Engines Discouraged' message
291
* displayed in the 'At a Glance' dashboard widget.
293
* Prior to 3.8.0, the widget was named 'Right Now'.
297
* @param string $content Default text.
299
$content = apply_filters( 'privacy_on_link_text' , __( 'Search Engines Discouraged' ) );
301
echo "<p><a href='options-reading.php' title='$title'>$content</a></p>";
307
* activity_box_end has a core action, but only prints content when multisite.
308
* Using an output buffer is the only way to really check if anything's displayed here.
313
* Fires at the end of the 'At a Glance' dashboard widget.
315
* Prior to 3.8.0, the widget was named 'Right Now'.
319
do_action( 'rightnow_end' );
322
* Fires at the end of the 'At a Glance' dashboard widget.
324
* Prior to 3.8.0, the widget was named 'Right Now'.
328
do_action( 'activity_box_end' );
330
$actions = ob_get_clean();
332
if ( !empty( $actions ) ) : ?>
334
<?php echo $actions; ?>
339
function wp_network_dashboard_right_now() {
341
if ( current_user_can('create_sites') )
342
$actions['create-site'] = '<a href="' . network_admin_url('site-new.php') . '">' . __( 'Create a New Site' ) . '</a>';
343
if ( current_user_can('create_users') )
344
$actions['create-user'] = '<a href="' . network_admin_url('user-new.php') . '">' . __( 'Create a New User' ) . '</a>';
346
$c_users = get_user_count();
347
$c_blogs = get_blog_count();
349
$user_text = sprintf( _n( '%s user', '%s users', $c_users ), number_format_i18n( $c_users ) );
350
$blog_text = sprintf( _n( '%s site', '%s sites', $c_blogs ), number_format_i18n( $c_blogs ) );
352
$sentence = sprintf( __( 'You have %1$s and %2$s.' ), $blog_text, $user_text );
355
echo '<ul class="subsubsub">';
356
foreach ( $actions as $class => $action ) {
357
$actions[ $class ] = "\t<li class='$class'>$action";
359
echo implode( " |</li>\n", $actions ) . "</li>\n";
365
<p class="youhave"><?php echo $sentence; ?></p>
370
* Fires in the Network Admin 'Right Now' dashboard widget
371
* just before the user and site search form fields.
375
* @param null $unused
377
do_action( 'wpmuadminresult', '' );
380
<form action="<?php echo network_admin_url('users.php'); ?>" method="get">
382
<input type="search" name="s" value="" size="30" autocomplete="off" />
383
<?php submit_button( __( 'Search Users' ), 'button', 'submit', false, array( 'id' => 'submit_users' ) ); ?>
387
<form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
389
<input type="search" name="s" value="" size="30" autocomplete="off" />
390
<?php submit_button( __( 'Search Sites' ), 'button', 'submit', false, array( 'id' => 'submit_sites' ) ); ?>
395
* Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
399
do_action( 'mu_rightnow_end' );
402
* Fires at the end of the 'Right Now' widget in the Network Admin dashboard.
406
do_action( 'mu_activity_box_end' );
410
* The Quick Draft widget display and creation of drafts.
414
* @param string $error_msg Optional. Error message. Default false.
416
function wp_dashboard_quick_press( $error_msg = false ) {
419
/* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
420
$last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
421
if ( $last_post_id ) {
422
$post = get_post( $last_post_id );
423
if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
424
$post = get_default_post_to_edit( 'post', true );
425
update_user_option( get_current_user_id(), 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
427
$post->post_title = ''; // Remove the auto draft title
430
$post = get_default_post_to_edit( 'post' , true);
431
$user_id = get_current_user_id();
432
// Don't create an option if this is a super admin who does not belong to this site.
433
if ( ! ( is_super_admin( $user_id ) && ! in_array( get_current_blog_id(), array_keys( get_blogs_of_user( $user_id ) ) ) ) )
434
update_user_option( $user_id, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
437
$post_ID = (int) $post->ID;
440
<form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press" class="initial-form hide-if-no-js">
442
<?php if ( $error_msg ) : ?>
443
<div class="error"><?php echo $error_msg; ?></div>
446
<div class="input-text-wrap" id="title-wrap">
447
<label class="screen-reader-text prompt" for="title" id="title-prompt-text">
450
/** This filter is documented in wp-admin/edit-form-advanced.php */
451
echo apply_filters( 'enter_title_here', __( 'Title' ), $post );
454
<input type="text" name="post_title" id="title" autocomplete="off" />
457
<div class="textarea-wrap" id="description-wrap">
458
<label class="screen-reader-text prompt" for="content" id="content-prompt-text"><?php _e( 'What’s on your mind?' ); ?></label>
459
<textarea name="content" id="content" class="mceEditor" rows="3" cols="15" autocomplete="off"></textarea>
463
<input type="hidden" name="action" id="quickpost-action" value="post-quickdraft-save" />
464
<input type="hidden" name="post_ID" value="<?php echo $post_ID; ?>" />
465
<input type="hidden" name="post_type" value="post" />
466
<?php wp_nonce_field( 'add-post' ); ?>
467
<?php submit_button( __( 'Save Draft' ), 'primary', 'save', false, array( 'id' => 'save-post' ) ); ?>
473
wp_dashboard_recent_drafts();
477
* Show recent drafts of the user on the dashboard.
481
function wp_dashboard_recent_drafts( $drafts = false ) {
484
'post_type' => 'post',
485
'post_status' => 'draft',
486
'author' => get_current_user_id(),
487
'posts_per_page' => 4,
488
'orderby' => 'modified',
491
$drafts = get_posts( $query_args );
497
echo '<div class="drafts">';
498
if ( count( $drafts ) > 3 ) {
499
echo '<p class="view-all"><a href="' . esc_url( admin_url( 'edit.php?post_status=draft' ) ) . '">' . _x( 'View all', 'drafts' ) . "</a></p>\n";
501
echo '<h4 class="hide-if-no-js">' . __( 'Drafts' ) . "</h4>\n<ul>";
503
$drafts = array_slice( $drafts, 0, 3 );
504
foreach ( $drafts as $draft ) {
505
$url = get_edit_post_link( $draft->ID );
506
$title = _draft_or_post_title( $draft->ID );
508
echo '<div class="draft-title"><a href="' . esc_url( $url ) . '" title="' . esc_attr( sprintf( __( 'Edit “%s”' ), $title ) ) . '">' . esc_html( $title ) . '</a>';
509
echo '<time datetime="' . get_the_time( 'c', $draft ) . '">' . get_the_time( get_option( 'date_format' ), $draft ) . '</time></div>';
510
if ( $the_content = wp_trim_words( $draft->post_content, 10 ) ) {
511
echo '<p>' . $the_content . '</p>';
515
echo "</ul>\n</div>";
518
function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
519
$GLOBALS['comment'] =& $comment;
521
$comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
523
if ( current_user_can( 'edit_post', $comment->comment_post_ID ) ) {
524
$comment_post_url = get_edit_post_link( $comment->comment_post_ID );
525
$comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
527
$comment_post_link = $comment_post_title;
530
$comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
532
$actions_string = '';
533
if ( current_user_can( 'edit_comment', $comment->comment_ID ) ) {
534
// Pre-order it: Approve | Reply | Edit | Spam | Trash.
536
'approve' => '', 'unapprove' => '',
540
'trash' => '', 'delete' => ''
543
$del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
544
$approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
546
$approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
547
$unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
548
$spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
549
$trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
550
$delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
552
$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>';
553
$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>';
554
$actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__('Edit comment') . "'>". __('Edit') . '</a>';
555
$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>';
556
$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>';
557
if ( !EMPTY_TRASH_DAYS )
558
$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>';
560
$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>';
563
* Filter the action links displayed for each comment in the 'Recent Comments'
568
* @param array $actions An array of comment actions. Default actions include:
569
* 'Approve', 'Unapprove', 'Edit', 'Reply', 'Spam',
570
* 'Delete', and 'Trash'.
571
* @param object $comment The comment object.
573
$actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
576
foreach ( $actions as $action => $link ) {
578
( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
580
// Reply and quickedit need a hide-if-no-js span
581
if ( 'reply' == $action || 'quickedit' == $action )
582
$action .= ' hide-if-no-js';
584
$actions_string .= "<span class='$action'>$sep$link</span>";
590
<div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
592
<?php echo get_avatar( $comment, 50, 'mystery' ); ?>
594
<?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
596
<div class="dashboard-comment-wrap">
597
<h4 class="comment-meta">
598
<?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
599
'<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
604
switch ( $comment->comment_type ) {
606
$type = __( 'Pingback' );
609
$type = __( 'Trackback' );
612
$type = ucwords( $comment->comment_type );
614
$type = esc_html( $type );
616
<div class="dashboard-comment-wrap">
617
<?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
618
<h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
619
<p class="comment-author"><?php comment_author_link(); ?></p>
621
<?php endif; // comment_type ?>
622
<blockquote><p><?php comment_excerpt(); ?></p></blockquote>
623
<p class="row-actions"><?php echo $actions_string; ?></p>
630
* Callback function for Activity widget.
634
function wp_dashboard_site_activity() {
636
echo '<div id="activity-widget">';
638
$future_posts = wp_dashboard_recent_posts( array(
640
'status' => 'future',
642
'title' => __( 'Publishing Soon' ),
643
'id' => 'future-posts',
645
$recent_posts = wp_dashboard_recent_posts( array(
647
'status' => 'publish',
649
'title' => __( 'Recently Published' ),
650
'id' => 'published-posts',
653
$recent_comments = wp_dashboard_recent_comments();
655
if ( !$future_posts && !$recent_posts && !$recent_comments ) {
656
echo '<div class="no-activity">';
657
echo '<p class="smiley"></p>';
658
echo '<p>' . __( 'No activity yet!' ) . '</p>';
666
* Generates Publishing Soon and Recently Published sections.
670
* @param array $args {
671
* An array of query and display arguments.
673
* @type int $max Number of posts to display.
674
* @type string $status Post status.
675
* @type string $order Designates ascending ('ASC') or descending ('DESC') order.
676
* @type string $title Section title.
677
* @type string $id The container id.
679
* @return bool False if no posts were found. True otherwise.
681
function wp_dashboard_recent_posts( $args ) {
683
'post_type' => 'post',
684
'post_status' => $args['status'],
686
'order' => $args['order'],
687
'posts_per_page' => intval( $args['max'] ),
688
'no_found_rows' => true,
689
'cache_results' => false,
690
'perm' => ( 'future' === $args['status'] ) ? 'editable' : 'readable',
692
$posts = new WP_Query( $query_args );
694
if ( $posts->have_posts() ) {
696
echo '<div id="' . $args['id'] . '" class="activity-block">';
698
echo '<h4>' . $args['title'] . '</h4>';
702
$today = date( 'Y-m-d', current_time( 'timestamp' ) );
703
$tomorrow = date( 'Y-m-d', strtotime( '+1 day', current_time( 'timestamp' ) ) );
705
while ( $posts->have_posts() ) {
708
$time = get_the_time( 'U' );
709
if ( date( 'Y-m-d', $time ) == $today ) {
710
$relative = __( 'Today' );
711
} elseif ( date( 'Y-m-d', $time ) == $tomorrow ) {
712
$relative = __( 'Tomorrow' );
714
/* translators: date and time format for recent posts on the dashboard, see http://php.net/date */
715
$relative = date_i18n( __( 'M jS' ), $time );
718
if ( current_user_can( 'edit_post', get_the_ID() ) ) {
719
/* translators: 1: relative date, 2: time, 3: post edit link, 4: post title */
720
$format = __( '<span>%1$s, %2$s</span> <a href="%3$s">%4$s</a>' );
721
printf( "<li>$format</li>", $relative, get_the_time(), get_edit_post_link(), _draft_or_post_title() );
723
/* translators: 1: relative date, 2: time, 3: post title */
724
$format = __( '<span>%1$s, %2$s</span> %3$s' );
725
printf( "<li>$format</li>", $relative, get_the_time(), _draft_or_post_title() );
742
* Show Comments section.
746
* @param int $total_items Optional. Number of comments to query. Default 5.
747
* @return bool False if no comments were found. True otherwise.
749
function wp_dashboard_recent_comments( $total_items = 5 ) {
750
// Select all comment types and filter out spam later for better query performance.
753
$comments_query = array(
754
'number' => $total_items * 5,
757
if ( ! current_user_can( 'edit_posts' ) )
758
$comments_query['status'] = 'approve';
760
while ( count( $comments ) < $total_items && $possible = get_comments( $comments_query ) ) {
761
foreach ( $possible as $comment ) {
762
if ( ! current_user_can( 'read_post', $comment->comment_post_ID ) )
764
$comments[] = $comment;
765
if ( count( $comments ) == $total_items )
768
$comments_query['offset'] += $comments_query['number'];
769
$comments_query['number'] = $total_items * 10;
773
echo '<div id="latest-comments" class="activity-block">';
774
echo '<h4>' . __( 'Comments' ) . '</h4>';
776
echo '<div id="the-comment-list" data-wp-lists="list:comment">';
777
foreach ( $comments as $comment )
778
_wp_dashboard_recent_comments_row( $comment );
781
if ( current_user_can('edit_posts') )
782
_get_list_table('WP_Comments_List_Table')->views();
784
wp_comment_reply( -1, false, 'dashboard', false );
785
wp_comment_trashnotice();
795
* Display generic dashboard RSS widget feed.
799
* @param string $widget_id
801
function wp_dashboard_rss_output( $widget_id ) {
802
$widgets = get_option( 'dashboard_widget_options' );
803
echo '<div class="rss-widget">';
804
wp_widget_rss_output( $widgets[ $widget_id ] );
809
* Checks to see if all of the feed url in $check_urls are cached.
811
* If $check_urls is empty, look for the rss feed url found in the dashboard
812
* widget options of $widget_id. If cached, call $callback, a function that
813
* echoes out output for this widget. If not cache, echo a "Loading..." stub
814
* which is later replaced by AJAX call (see top of /wp-admin/index.php)
818
* @param string $widget_id
819
* @param callback $callback
820
* @param array $check_urls RSS feeds
821
* @return bool False on failure. True on success.
823
function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
824
$loading = '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="hide-if-js">' . __( 'This widget requires JavaScript.' ) . '</p>';
825
$doing_ajax = ( defined('DOING_AJAX') && DOING_AJAX );
827
if ( empty($check_urls) ) {
828
$widgets = get_option( 'dashboard_widget_options' );
829
if ( empty($widgets[$widget_id]['url']) && ! $doing_ajax ) {
833
$check_urls = array( $widgets[$widget_id]['url'] );
836
$cache_key = 'dash_' . md5( $widget_id );
837
if ( false !== ( $output = get_transient( $cache_key ) ) ) {
842
if ( ! $doing_ajax ) {
847
if ( $callback && is_callable( $callback ) ) {
848
$args = array_slice( func_get_args(), 3 );
849
array_unshift( $args, $widget_id, $check_urls );
851
call_user_func_array( $callback, $args );
852
set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
858
/* Dashboard Widgets Controls */
860
// Calls widget_control callback
862
* Calls widget control callback.
866
* @param int $widget_control_id Registered Widget ID.
868
function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
869
global $wp_dashboard_control_callbacks;
871
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]) ) {
872
call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
877
* The RSS dashboard widget control.
879
* Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
880
* from RSS-type widgets.
884
* @param string $widget_id
885
* @param array $form_inputs
887
function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
888
if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
889
$widget_options = array();
891
if ( !isset($widget_options[$widget_id]) )
892
$widget_options[$widget_id] = array();
894
$number = 1; // Hack to use wp_widget_rss_form()
895
$widget_options[$widget_id]['number'] = $number;
897
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
898
$_POST['widget-rss'][$number] = wp_unslash( $_POST['widget-rss'][$number] );
899
$widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
900
$widget_options[$widget_id]['number'] = $number;
902
// Title is optional. If black, fill it if possible.
903
if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
904
$rss = fetch_feed($widget_options[$widget_id]['url']);
905
if ( is_wp_error($rss) ) {
906
$widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
908
$widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
913
update_option( 'dashboard_widget_options', $widget_options );
914
$cache_key = 'dash_' . md5( $widget_id );
915
delete_transient( $cache_key );
918
wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
922
* WordPress News dashboard widget.
926
function wp_dashboard_primary() {
931
* Filter the primary link URL for the 'WordPress News' dashboard widget.
935
* @param string $link The widget's primary link URL.
937
'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/news/' ) ),
940
* Filter the primary feed URL for the 'WordPress News' dashboard widget.
944
* @param string $url The widget's primary feed URL.
946
'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/news/feed/' ) ),
949
* Filter the primary link title for the 'WordPress News' dashboard widget.
953
* @param string $title Title attribute for the widget's primary link.
955
'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
964
* Filter the secondary link URL for the 'WordPress News' dashboard widget.
968
* @param string $link The widget's secondary link URL.
970
'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
973
* Filter the secondary feed URL for the 'WordPress News' dashboard widget.
977
* @param string $url The widget's secondary feed URL.
979
'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
982
* Filter the secondary link title for the 'WordPress News' dashboard widget.
986
* @param string $title Title attribute for the widget's secondary link.
988
'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
996
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' ) ) ) {
997
$feeds['plugins'] = array(
1000
'popular' => 'http://wordpress.org/plugins/rss/browse/popular/',
1004
'show_summary' => 0,
1010
wp_dashboard_cached_rss_widget( 'dashboard_primary', 'wp_dashboard_primary_output', $feeds );
1014
* Display the WordPress news feeds.
1018
* @param string $widget_id Widget ID.
1019
* @param array $feeds Array of RSS feeds.
1021
function wp_dashboard_primary_output( $widget_id, $feeds ) {
1022
foreach( $feeds as $type => $args ) {
1023
$args['type'] = $type;
1024
echo '<div class="rss-widget">';
1025
if ( $type === 'plugins' ) {
1026
wp_dashboard_plugins_output( $args['url'], $args );
1028
wp_widget_rss_output( $args['url'], $args );
1035
* Display plugins text for the WordPress news widget.
1039
function wp_dashboard_plugins_output( $rss, $args = array() ) {
1040
// Plugin feeds plus link to install them
1041
$popular = fetch_feed( $args['url']['popular'] );
1043
if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
1044
$plugin_slugs = array_keys( get_plugins() );
1045
set_transient( 'plugin_slugs', $plugin_slugs, DAY_IN_SECONDS );
1050
foreach ( array( $popular ) as $feed ) {
1051
if ( is_wp_error( $feed ) || ! $feed->get_item_quantity() )
1054
$items = $feed->get_items(0, 5);
1056
// Pick a random, non-installed plugin
1058
// Abort this foreach loop iteration if there's no plugins left of this type
1059
if ( 0 == count($items) )
1062
$item_key = array_rand($items);
1063
$item = $items[$item_key];
1065
list($link, $frag) = explode( '#', $item->get_link() );
1067
$link = esc_url($link);
1068
if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
1069
$slug = $matches[1];
1071
unset( $items[$item_key] );
1075
// Is this random plugin's slug already installed? If so, try again.
1076
reset( $plugin_slugs );
1077
foreach ( $plugin_slugs as $plugin_slug ) {
1078
if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
1079
unset( $items[$item_key] );
1084
// If we get to this point, then the random plugin isn't installed and we can stop the while().
1088
// Eliminate some common badly formed plugin descriptions
1089
while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
1090
unset($items[$item_key]);
1092
if ( !isset($items[$item_key]) )
1095
$title = esc_html( $item->get_title() );
1097
$ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) . '&TB_iframe=true&width=600&height=800';
1098
echo "<li class='dashboard-news-plugin'><span>" . __( 'Popular Plugin' ) . ":</span> <a href='$link' class='dashboard-news-plugin-link'>$title</a> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span></li>";
1100
$feed->__destruct();
1108
* Display file upload quota on dashboard.
1110
* Runs on the activity_box_end hook in wp_dashboard_right_now().
1114
* @return bool True if not multisite, user can't upload files, or the space check option is disabled.
1116
function wp_dashboard_quota() {
1117
if ( !is_multisite() || !current_user_can( 'upload_files' ) || get_site_option( 'upload_space_check_disabled' ) )
1120
$quota = get_space_allowed();
1121
$used = get_space_used();
1123
if ( $used > $quota )
1124
$percentused = '100';
1126
$percentused = ( $used / $quota ) * 100;
1127
$used_class = ( $percentused >= 70 ) ? ' warning' : '';
1128
$used = round( $used, 2 );
1129
$percentused = number_format( $percentused );
1132
<h4 class="mu-storage"><?php _e( 'Storage Space' ); ?></h4>
1133
<div class="mu-storage">
1135
<li class="storage-count">
1136
<?php $text = sprintf(
1137
/* translators: number of megabytes */
1138
__( '%s MB Space Allowed' ),
1139
number_format_i18n( $quota )
1142
'<a href="%1$s" title="%2$s">%3$s</a>',
1143
esc_url( admin_url( 'upload.php' ) ),
1144
__( 'Manage Uploads' ),
1147
</li><li class="storage-count <?php echo $used_class; ?>">
1148
<?php $text = sprintf(
1149
/* translators: 1: number of megabytes, 2: percentage */
1150
__( '%1$s MB (%2$s%%) Space Used' ),
1151
number_format_i18n( $used, 2 ),
1155
'<a href="%1$s" title="%2$s" class="musublink">%3$s</a>',
1156
esc_url( admin_url( 'upload.php' ) ),
1157
__( 'Manage Uploads' ),
1165
add_action( 'activity_box_end', 'wp_dashboard_quota' );
1167
// Display Browser Nag Meta Box
1168
function wp_dashboard_browser_nag() {
1170
$response = wp_check_browser_version();
1173
if ( $response['insecure'] ) {
1174
$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'] ) );
1176
$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'] ) );
1179
$browser_nag_class = '';
1180
if ( !empty( $response['img_src'] ) ) {
1181
$img_src = ( is_ssl() && ! empty( $response['img_src_ssl'] ) )? $response['img_src_ssl'] : $response['img_src'];
1183
$notice .= '<div class="alignright browser-icon"><a href="' . esc_attr($response['update_url']) . '"><img src="' . esc_attr( $img_src ) . '" alt="" /></a></div>';
1184
$browser_nag_class = ' has-browser-icon';
1186
$notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
1188
$browsehappy = 'http://browsehappy.com/';
1189
$locale = get_locale();
1190
if ( 'en_US' !== $locale )
1191
$browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
1193
$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>';
1194
$notice .= '<p class="hide-if-no-js"><a href="" class="dismiss">' . __( 'Dismiss' ) . '</a></p>';
1195
$notice .= '<div class="clear"></div>';
1199
* Filter the notice output for the 'Browse Happy' nag meta box.
1203
* @param string $notice The notice content.
1204
* @param array $response An array containing web browser information.
1206
echo apply_filters( 'browse-happy-notice', $notice, $response );
1209
function dashboard_browser_nag_class( $classes ) {
1210
$response = wp_check_browser_version();
1212
if ( $response && $response['insecure'] )
1213
$classes[] = 'browser-insecure';
1219
* Check if the user needs a browser update
1223
* @return array|bool False on failure, array of browser data on success.
1225
function wp_check_browser_version() {
1226
if ( empty( $_SERVER['HTTP_USER_AGENT'] ) )
1229
$key = md5( $_SERVER['HTTP_USER_AGENT'] );
1231
if ( false === ($response = get_site_transient('browser_' . $key) ) ) {
1235
'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
1236
'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url()
1239
$response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.1/', $options );
1241
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
1245
* Response should be an array with:
1246
* 'name' - string - A user friendly browser name
1247
* 'version' - string - The most recent version of the browser
1248
* 'current_version' - string - The version of the browser the user is using
1249
* 'upgrade' - boolean - Whether the browser needs an upgrade
1250
* 'insecure' - boolean - Whether the browser is deemed insecure
1251
* 'upgrade_url' - string - The url to visit to upgrade
1252
* 'img_src' - string - An image representing the browser
1253
* 'img_src_ssl' - string - An image (over SSL) representing the browser
1255
$response = json_decode( wp_remote_retrieve_body( $response ), true );
1257
if ( ! is_array( $response ) )
1260
set_site_transient( 'browser_' . $key, $response, WEEK_IN_SECONDS );
1267
* Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1269
function wp_dashboard_empty() {}
1272
* Displays a welcome panel to introduce users to WordPress.
1276
function wp_welcome_panel() {
1278
<div class="welcome-panel-content">
1279
<h3><?php _e( 'Welcome to WordPress!' ); ?></h3>
1280
<p class="about-description"><?php _e( 'We’ve assembled some links to get you started:' ); ?></p>
1281
<div class="welcome-panel-column-container">
1282
<div class="welcome-panel-column">
1283
<?php if ( current_user_can( 'customize' ) ): ?>
1284
<h4><?php _e( 'Get Started' ); ?></h4>
1285
<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>
1287
<a class="button button-primary button-hero hide-if-customize" href="<?php echo admin_url( 'themes.php' ); ?>"><?php _e( 'Customize Your Site' ); ?></a>
1288
<?php if ( current_user_can( 'install_themes' ) || ( current_user_can( 'switch_themes' ) && count( wp_get_themes( array( 'allowed' => true ) ) ) > 1 ) ) : ?>
1289
<p class="hide-if-no-customize"><?php printf( __( 'or, <a href="%s">change your theme completely</a>' ), admin_url( 'themes.php' ) ); ?></p>
1292
<div class="welcome-panel-column">
1293
<h4><?php _e( 'Next Steps' ); ?></h4>
1295
<?php if ( 'page' == get_option( 'show_on_front' ) && ! get_option( 'page_for_posts' ) ) : ?>
1296
<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>
1297
<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>
1298
<?php elseif ( 'page' == get_option( 'show_on_front' ) ) : ?>
1299
<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>
1300
<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>
1301
<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Add a blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1303
<li><?php printf( '<a href="%s" class="welcome-icon welcome-write-blog">' . __( 'Write your first blog post' ) . '</a>', admin_url( 'post-new.php' ) ); ?></li>
1304
<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>
1306
<li><?php printf( '<a href="%s" class="welcome-icon welcome-view-site">' . __( 'View your site' ) . '</a>', home_url( '/' ) ); ?></li>
1309
<div class="welcome-panel-column welcome-panel-last">
1310
<h4><?php _e( 'More Actions' ); ?></h4>
1312
<?php if ( current_theme_supports( 'widgets' ) || current_theme_supports( 'menus' ) ) : ?>
1313
<li><div class="welcome-icon welcome-widgets-menus"><?php
1314
if ( current_theme_supports( 'widgets' ) && current_theme_supports( 'menus' ) ) {
1315
printf( __( 'Manage <a href="%1$s">widgets</a> or <a href="%2$s">menus</a>' ),
1316
admin_url( 'widgets.php' ), admin_url( 'nav-menus.php' ) );
1317
} elseif ( current_theme_supports( 'widgets' ) ) {
1318
echo '<a href="' . admin_url( 'widgets.php' ) . '">' . __( 'Manage widgets' ) . '</a>';
1320
echo '<a href="' . admin_url( 'nav-menus.php' ) . '">' . __( 'Manage menus' ) . '</a>';
1324
<?php if ( current_user_can( 'manage_options' ) ) : ?>
1325
<li><?php printf( '<a href="%s" class="welcome-icon welcome-comments">' . __( 'Turn comments on or off' ) . '</a>', admin_url( 'options-discussion.php' ) ); ?></li>
1327
<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>