3 * WordPress Dashboard Widget Administration Panel 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();
21 $widget_options = get_option( 'dashboard_widget_options' );
22 if ( !$widget_options || !is_array($widget_options) )
23 $widget_options = array();
25 /* Register Widgets and Controls */
28 wp_add_dashboard_widget( 'dashboard_right_now', __( 'Right Now' ), 'wp_dashboard_right_now' );
30 // Recent Comments Widget
31 if ( !isset( $widget_options['dashboard_recent_comments'] ) || !isset( $widget_options['dashboard_recent_comments']['items'] ) ) {
33 $widget_options['dashboard_recent_comments'] = array(
37 $recent_comments_title = __( 'Recent Comments' );
38 wp_add_dashboard_widget( 'dashboard_recent_comments', $recent_comments_title, 'wp_dashboard_recent_comments', 'wp_dashboard_recent_comments_control' );
40 // Incoming Links Widget
41 if ( !isset( $widget_options['dashboard_incoming_links'] ) || !isset( $widget_options['dashboard_incoming_links']['home'] ) || $widget_options['dashboard_incoming_links']['home'] != get_option('home') ) {
43 $num_items = isset($widget_options['dashboard_incoming_links']['items']) ? $widget_options['dashboard_incoming_links']['items'] : 10;
44 $widget_options['dashboard_incoming_links'] = array(
45 'home' => get_option('home'),
46 'link' => apply_filters( 'dashboard_incoming_links_link', 'http://blogsearch.google.com/blogsearch?scoring=d&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
47 'url' => isset($widget_options['dashboard_incoming_links']['url']) ? apply_filters( 'dashboard_incoming_links_feed', $widget_options['dashboard_incoming_links']['url'] ) : apply_filters( 'dashboard_incoming_links_feed', 'http://blogsearch.google.com/blogsearch_feeds?scoring=d&ie=utf-8&num=' . $num_items . '&output=rss&partner=wordpress&q=link:' . trailingslashit( get_option('home') ) ),
48 'items' => $num_items,
49 'show_date' => isset($widget_options['dashboard_incoming_links']['show_date']) ? $widget_options['dashboard_incoming_links']['show_date'] : false
52 wp_add_dashboard_widget( 'dashboard_incoming_links', __( 'Incoming Links' ), 'wp_dashboard_incoming_links', 'wp_dashboard_incoming_links_control' );
55 if ( current_user_can( 'install_plugins' ) )
56 wp_add_dashboard_widget( 'dashboard_plugins', __( 'Plugins' ), 'wp_dashboard_plugins' );
59 if ( current_user_can('edit_posts') )
60 wp_add_dashboard_widget( 'dashboard_quick_press', __( 'QuickPress' ), 'wp_dashboard_quick_press' );
63 if ( current_user_can('edit_posts') )
64 wp_add_dashboard_widget( 'dashboard_recent_drafts', __('Recent Drafts'), 'wp_dashboard_recent_drafts' );
66 // Primary feed (Dev Blog) Widget
67 if ( !isset( $widget_options['dashboard_primary'] ) ) {
69 $widget_options['dashboard_primary'] = array(
70 'link' => apply_filters( 'dashboard_primary_link', __( 'http://wordpress.org/development/' ) ),
71 'url' => apply_filters( 'dashboard_primary_feed', __( 'http://wordpress.org/development/feed/' ) ),
72 'title' => apply_filters( 'dashboard_primary_title', __( 'WordPress Blog' ) ),
79 wp_add_dashboard_widget( 'dashboard_primary', $widget_options['dashboard_primary']['title'], 'wp_dashboard_primary', 'wp_dashboard_primary_control' );
81 // Secondary Feed (Planet) Widget
82 if ( !isset( $widget_options['dashboard_secondary'] ) ) {
84 $widget_options['dashboard_secondary'] = array(
85 'link' => apply_filters( 'dashboard_secondary_link', __( 'http://planet.wordpress.org/' ) ),
86 'url' => apply_filters( 'dashboard_secondary_feed', __( 'http://planet.wordpress.org/feed/' ) ),
87 'title' => apply_filters( 'dashboard_secondary_title', __( 'Other WordPress News' ) ),
94 wp_add_dashboard_widget( 'dashboard_secondary', $widget_options['dashboard_secondary']['title'], 'wp_dashboard_secondary', 'wp_dashboard_secondary_control' );
96 // Hook to register new widgets
97 do_action( 'wp_dashboard_setup' );
99 // Filter widget order
100 $dashboard_widgets = apply_filters( 'wp_dashboard_widgets', array() );
102 foreach ( $dashboard_widgets as $widget_id ) {
103 $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>';
104 wp_add_dashboard_widget( $widget_id, $name, $wp_registered_widgets[$widget_id]['callback'], $wp_registered_widget_controls[$widget_id]['callback'] );
107 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget_id']) ) {
108 ob_start(); // hack - but the same hack wp-admin/widgets.php uses
109 wp_dashboard_trigger_widget_control( $_POST['widget_id'] );
111 wp_redirect( remove_query_arg( 'edit' ) );
116 update_option( 'dashboard_widget_options', $widget_options );
118 do_action('do_meta_boxes', 'dashboard', 'normal', '');
119 do_action('do_meta_boxes', 'dashboard', 'side', '');
122 function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_callback = null ) {
123 global $wp_dashboard_control_callbacks;
124 if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) {
125 $wp_dashboard_control_callbacks[$widget_id] = $control_callback;
126 if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) {
127 list($url) = explode( '#', add_query_arg( 'edit', false ), 2 );
128 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( $url ) . '">' . __( 'Cancel' ) . '</a></span>';
129 add_meta_box( $widget_id, $widget_name, '_wp_dashboard_control_callback', 'dashboard', 'normal', 'core' );
132 list($url) = explode( '#', add_query_arg( 'edit', $widget_id ), 2 );
133 $widget_name .= ' <span class="postbox-title-action"><a href="' . esc_url( "$url#$widget_id" ) . '" class="edit-box open-box">' . __( 'Configure' ) . '</a></span>';
135 $side_widgets = array('dashboard_quick_press', 'dashboard_recent_drafts', 'dashboard_primary', 'dashboard_secondary');
136 $location = 'normal';
137 if ( in_array($widget_id, $side_widgets) )
139 add_meta_box( $widget_id, $widget_name , $callback, 'dashboard', $location, 'core' );
142 function _wp_dashboard_control_callback( $dashboard, $meta_box ) {
143 echo '<form action="" method="post" class="dashboard-widget-control-form">';
144 wp_dashboard_trigger_widget_control( $meta_box['id'] );
145 echo '<p class="submit"><input type="hidden" name="widget_id" value="' . esc_attr($meta_box['id']) . '" /><input type="submit" value="' . esc_attr__( 'Submit' ) . '" /></p>';
151 * Displays the dashboard.
155 function wp_dashboard() {
156 global $screen_layout_columns;
158 $hide2 = $hide3 = $hide4 = '';
159 switch ( $screen_layout_columns ) {
161 $width = 'width:24.5%;';
164 $width = 'width:32.67%;';
165 $hide4 = 'display:none;';
168 $width = 'width:49%;';
169 $hide3 = $hide4 = 'display:none;';
172 $width = 'width:98%;';
173 $hide2 = $hide3 = $hide4 = 'display:none;';
176 <div id="dashboard-widgets" class="metabox-holder">
178 echo "\t<div class='postbox-container' style='$width'>\n";
179 do_meta_boxes( 'dashboard', 'normal', '' );
181 echo "\t</div><div class='postbox-container' style='{$hide2}$width'>\n";
182 do_meta_boxes( 'dashboard', 'side', '' );
184 echo "\t</div><div class='postbox-container' style='{$hide3}$width'>\n";
185 do_meta_boxes( 'dashboard', 'column3', '' );
187 echo "\t</div><div class='postbox-container' style='{$hide4}$width'>\n";
188 do_meta_boxes( 'dashboard', 'column4', '' );
192 <form style="display:none" method="get" action="">
195 wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
196 wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
204 /* Dashboard Widgets */
206 function wp_dashboard_right_now() {
207 global $wp_registered_sidebars;
209 $num_posts = wp_count_posts( 'post' );
210 $num_pages = wp_count_posts( 'page' );
212 $num_cats = wp_count_terms('category');
214 $num_tags = wp_count_terms('post_tag');
216 $num_comm = wp_count_comments( );
218 echo "\n\t".'<div class="table table_content">';
219 echo "\n\t".'<p class="sub">' . __('Content') . '</p>'."\n\t".'<table>';
220 echo "\n\t".'<tr class="first">';
223 $num = number_format_i18n( $num_posts->publish );
224 $text = _n( 'Post', 'Posts', intval($num_posts->publish) );
225 if ( current_user_can( 'edit_posts' ) ) {
226 $num = "<a href='edit.php'>$num</a>";
227 $text = "<a href='edit.php'>$text</a>";
229 echo '<td class="first b b-posts">' . $num . '</td>';
230 echo '<td class="t posts">' . $text . '</td>';
233 /* TODO: Show status breakdown on hover
234 if ( $can_edit_pages && !empty($num_pages->publish) ) { // how many pages is not exposed in feeds. Don't show if !current_user_can
235 $post_type_texts[] = '<a href="edit-pages.php">'.sprintf( _n( '%s page', '%s pages', $num_pages->publish ), number_format_i18n( $num_pages->publish ) ).'</a>';
237 if ( $can_edit_posts && !empty($num_posts->draft) ) {
238 $post_type_texts[] = '<a href="edit.php?post_status=draft">'.sprintf( _n( '%s draft', '%s drafts', $num_posts->draft ), number_format_i18n( $num_posts->draft ) ).'</a>';
240 if ( $can_edit_posts && !empty($num_posts->future) ) {
241 $post_type_texts[] = '<a href="edit.php?post_status=future">'.sprintf( _n( '%s scheduled post', '%s scheduled posts', $num_posts->future ), number_format_i18n( $num_posts->future ) ).'</a>';
243 if ( current_user_can('publish_posts') && !empty($num_posts->pending) ) {
244 $pending_text = sprintf( _n( 'There is <a href="%1$s">%2$s post</a> pending your review.', 'There are <a href="%1$s">%2$s posts</a> pending your review.', $num_posts->pending ), 'edit.php?post_status=pending', number_format_i18n( $num_posts->pending ) );
251 $num = number_format_i18n( $num_pages->publish );
252 $text = _n( 'Page', 'Pages', $num_pages->publish );
253 if ( current_user_can( 'edit_pages' ) ) {
254 $num = "<a href='edit.php?post_type=page'>$num</a>";
255 $text = "<a href='edit.php?post_type=page'>$text</a>";
257 echo '<td class="first b b_pages">' . $num . '</td>';
258 echo '<td class="t pages">' . $text . '</td>';
263 $num = number_format_i18n( $num_cats );
264 $text = _n( 'Category', 'Categories', $num_cats );
265 if ( current_user_can( 'manage_categories' ) ) {
266 $num = "<a href='edit-tags.php?taxonomy=category'>$num</a>";
267 $text = "<a href='edit-tags.php?taxonomy=category'>$text</a>";
269 echo '<td class="first b b-cats">' . $num . '</td>';
270 echo '<td class="t cats">' . $text . '</td>';
275 $num = number_format_i18n( $num_tags );
276 $text = _n( 'Tag', 'Tags', $num_tags );
277 if ( current_user_can( 'manage_categories' ) ) {
278 $num = "<a href='edit-tags.php'>$num</a>";
279 $text = "<a href='edit-tags.php'>$text</a>";
281 echo '<td class="first b b-tags">' . $num . '</td>';
282 echo '<td class="t tags">' . $text . '</td>';
285 do_action('right_now_content_table_end');
286 echo "\n\t</table>\n\t</div>";
289 echo "\n\t".'<div class="table table_discussion">';
290 echo "\n\t".'<p class="sub">' . __('Discussion') . '</p>'."\n\t".'<table>';
291 echo "\n\t".'<tr class="first">';
294 $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
295 $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
296 if ( current_user_can( 'moderate_comments' ) ) {
297 $num = '<a href="edit-comments.php">' . $num . '</a>';
298 $text = '<a href="edit-comments.php">' . $text . '</a>';
300 echo '<td class="b b-comments">' . $num . '</td>';
301 echo '<td class="last t comments">' . $text . '</td>';
306 $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
307 $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
308 if ( current_user_can( 'moderate_comments' ) ) {
309 $num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
310 $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>$text</a>";
312 echo '<td class="b b_approved">' . $num . '</td>';
313 echo '<td class="last t">' . $text . '</td>';
315 echo "</tr>\n\t<tr>";
318 $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
319 $text = _n( 'Pending', 'Pending', $num_comm->moderated );
320 if ( current_user_can( 'moderate_comments' ) ) {
321 $num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
322 $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
324 echo '<td class="b b-waiting">' . $num . '</td>';
325 echo '<td class="last t">' . $text . '</td>';
327 echo "</tr>\n\t<tr>";
330 $num = number_format_i18n($num_comm->spam);
331 $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
332 if ( current_user_can( 'moderate_comments' ) ) {
333 $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>$num</span></a>";
334 $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>$text</a>";
336 echo '<td class="b b-spam">' . $num . '</td>';
337 echo '<td class="last t">' . $text . '</td>';
340 do_action('right_now_table_end');
341 do_action('right_now_discussion_table_end');
342 echo "\n\t</table>\n\t</div>";
344 echo "\n\t".'<div class="versions">';
345 $ct = current_theme_info();
348 if ( !empty($wp_registered_sidebars) ) {
349 $sidebars_widgets = wp_get_sidebars_widgets();
351 foreach ( (array) $sidebars_widgets as $k => $v ) {
352 if ( 'wp_inactive_widgets' == $k )
355 $num_widgets = $num_widgets + count($v);
357 $num = number_format_i18n( $num_widgets );
359 $switch_themes = $ct->title;
360 if ( current_user_can( 'switch_themes') ) {
361 echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
362 $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
364 if ( current_user_can( 'edit_theme_options' ) ) {
365 printf(_n('Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widget</a></span>', 'Theme <span class="b">%1$s</span> with <span class="b"><a href="widgets.php">%2$s Widgets</a></span>', $num_widgets), $switch_themes, $num);
367 printf(_n('Theme <span class="b">%1$s</span> with <span class="b">%2$s Widget</span>', 'Theme <span class="b">%1$s</span> with <span class="b">%2$s Widgets</span>', $num_widgets), $switch_themes, $num);
370 if ( current_user_can( 'switch_themes' ) ) {
371 echo '<a href="themes.php" class="button rbutton">' . __('Change Theme') . '</a>';
372 printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
374 printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
379 update_right_now_message();
381 echo "\n\t".'<br class="clear" /></div>';
382 do_action( 'rightnow_end' );
383 do_action( 'activity_box_end' );
386 function wp_dashboard_quick_press_output() {
390 if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
391 $view = get_permalink( $_POST['post_ID'] );
392 $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
393 if ( 'post-quickpress-publish' == $_POST['action'] ) {
394 if ( current_user_can('publish_posts') )
395 printf( '<div class="updated"><p>' . __( 'Post published. <a href="%s">View post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( $view ), $edit );
397 printf( '<div class="updated"><p>' . __( 'Post submitted. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
399 printf( '<div class="updated"><p>' . __( 'Draft saved. <a href="%s">Preview post</a> | <a href="%s">Edit post</a>' ) . '</p></div>', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
400 $drafts_query = new WP_Query( array(
401 'post_type' => 'post',
402 'post_status' => 'draft',
403 'author' => $GLOBALS['current_user']->ID,
404 'posts_per_page' => 1,
405 'orderby' => 'modified',
409 if ( $drafts_query->posts )
410 $drafts =& $drafts_query->posts;
412 printf('<p class="textright">' . __('You can also try %s, easy blogging from anywhere on the Web.') . '</p>', '<a href="' . esc_url( admin_url( 'tools.php' ) ) . '">' . __('Press This') . '</a>' );
413 $_REQUEST = array(); // hack for get_default_post_to_edit()
416 /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
417 $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
418 if ( $last_post_id ) {
419 $post = get_post( $last_post_id );
420 if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
421 $post = get_default_post_to_edit('post', true);
422 update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
424 $post->post_title = ''; // Remove the auto draft title
427 $post = get_default_post_to_edit('post', true);
428 update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
431 $post_ID = (int) $post->ID;
434 <form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
435 <h4 id="quick-post-title"><label for="title"><?php _e('Title') ?></label></h4>
436 <div class="input-text-wrap">
437 <input type="text" name="post_title" id="title" tabindex="1" autocomplete="off" value="<?php echo esc_attr( $post->post_title ); ?>" />
440 <?php if ( current_user_can( 'upload_files' ) ) : ?>
441 <div id="media-buttons" class="hide-if-no-js">
442 <?php do_action( 'media_buttons' ); ?>
446 <h4 id="content-label"><label for="content"><?php _e('Content') ?></label></h4>
447 <div class="textarea-wrap">
448 <textarea name="content" id="content" class="mceEditor" rows="3" cols="15" tabindex="2"><?php echo $post->post_content; ?></textarea>
451 <script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
453 <h4><label for="tags-input"><?php _e('Tags') ?></label></h4>
454 <div class="input-text-wrap">
455 <input type="text" name="tags_input" id="tags-input" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" />
459 <input type="hidden" name="action" id="quickpost-action" value="post-quickpress-save" />
460 <input type="hidden" name="quickpress_post_ID" value="<?php echo $post_ID; ?>" />
461 <input type="hidden" name="post_type" value="post" />
462 <?php wp_nonce_field('add-post'); ?>
463 <input type="submit" name="save" id="save-post" class="button" tabindex="4" value="<?php esc_attr_e('Save Draft'); ?>" />
464 <input type="reset" value="<?php esc_attr_e( 'Reset' ); ?>" class="button" />
465 <span id="publishing-action">
466 <input type="submit" name="publish" id="publish" accesskey="p" tabindex="5" class="button-primary" value="<?php current_user_can('publish_posts') ? esc_attr_e('Publish') : esc_attr_e('Submit for Review'); ?>" />
467 <img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
476 wp_dashboard_recent_drafts( $drafts );
479 function wp_dashboard_quick_press() {
480 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
483 function wp_dashboard_recent_drafts( $drafts = false ) {
485 $drafts_query = new WP_Query( array(
486 'post_type' => 'post',
487 'post_status' => 'draft',
488 'author' => $GLOBALS['current_user']->ID,
489 'posts_per_page' => 5,
490 'orderby' => 'modified',
493 $drafts =& $drafts_query->posts;
496 if ( $drafts && is_array( $drafts ) ) {
498 foreach ( $drafts as $draft ) {
499 $url = get_edit_post_link( $draft->ID );
500 $title = _draft_or_post_title( $draft->ID );
501 $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit “%s”' ), esc_attr( $title ) ) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
502 if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
503 $item .= '<p>' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '…' : '' ) . '</p>';
508 <li><?php echo join( "</li>\n<li>", $list ); ?></li>
510 <p class="textright"><a href="edit.php?post_status=draft" class="button"><?php _e('View all'); ?></a></p>
513 _e('There are no drafts at the moment');
518 * Display recent comments dashboard widget content.
522 function wp_dashboard_recent_comments() {
525 if ( current_user_can('edit_posts') )
526 $allowed_states = array('0', '1');
528 $allowed_states = array('1');
530 // Select all comment types and filter out spam later for better query performance.
534 $widgets = get_option( 'dashboard_widget_options' );
535 if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) )
536 $total_items = (int) $widgets['dashboard_recent_comments']['items'];
540 while ( count( $comments ) < 5 && $possible = $wpdb->get_results( "SELECT * FROM $wpdb->comments c LEFT JOIN $wpdb->posts p ON c.comment_post_ID = p.ID WHERE p.post_status != 'trash' ORDER BY c.comment_date_gmt DESC LIMIT $start, 50" ) ) {
542 foreach ( $possible as $comment ) {
543 if ( count( $comments ) >= $total_items )
545 if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
546 $comments[] = $comment;
549 $start = $start + 50;
555 <div id="the-comment-list" class="list:comment">
557 foreach ( $comments as $comment )
558 _wp_dashboard_recent_comments_row( $comment );
564 if ( current_user_can('edit_posts') ) { ?>
565 <p class="textright"><a href="edit-comments.php" class="button"><?php _e('View all'); ?></a></p>
568 wp_comment_reply( -1, false, 'dashboard', false );
569 wp_comment_trashnotice();
574 <p><?php _e( 'No comments yet.' ); ?></p>
580 function _wp_dashboard_recent_comments_row( &$comment, $show_date = true ) {
581 $GLOBALS['comment'] =& $comment;
583 $comment_post_url = get_edit_post_link( $comment->comment_post_ID );
584 $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
585 $comment_post_link = "<a href='$comment_post_url'>$comment_post_title</a>";
586 $comment_link = '<a class="comment-link" href="' . esc_url(get_comment_link()) . '">#</a>';
588 $actions_string = '';
589 if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
590 // preorder it: Approve | Reply | Edit | Spam | Trash
592 'approve' => '', 'unapprove' => '',
596 'trash' => '', 'delete' => ''
599 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
600 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
602 $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
603 $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
604 $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
605 $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
606 $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
608 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
609 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . __( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
610 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . __('Edit comment') . "'>". __('Edit') . '</a>';
611 $actions['reply'] = '<a onclick="commentReply.open(\''.$comment->comment_ID.'\',\''.$comment->comment_post_ID.'\');return false;" class="vim-r hide-if-no-js" title="'.__('Reply to this comment').'" href="#">' . __('Reply') . '</a>';
612 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . __( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
613 if ( !EMPTY_TRASH_DAYS )
614 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
616 $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . __( 'Move this comment to the trash' ) . "'>" . _x('Trash', 'verb') . '</a>';
618 $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
621 foreach ( $actions as $action => $link ) {
623 ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
625 // Reply and quickedit need a hide-if-no-js span
626 if ( 'reply' == $action || 'quickedit' == $action )
627 $action .= ' hide-if-no-js';
629 $actions_string .= "<span class='$action'>$sep$link</span>";
635 <div id="comment-<?php echo $comment->comment_ID; ?>" <?php comment_class( array( 'comment-item', wp_get_comment_status($comment->comment_ID) ) ); ?>>
636 <?php if ( !$comment->comment_type || 'comment' == $comment->comment_type ) : ?>
638 <?php echo get_avatar( $comment, 50 ); ?>
640 <div class="dashboard-comment-wrap">
641 <h4 class="comment-meta">
642 <?php printf( /* translators: 1: comment author, 2: post link, 3: notification if the comment is pending */__( 'From %1$s on %2$s%3$s' ),
643 '<cite class="comment-author">' . get_comment_author_link() . '</cite>', $comment_post_link.' '.$comment_link, ' <span class="approve">' . __( '[Pending]' ) . '</span>' ); ?>
648 switch ( $comment->comment_type ) :
650 $type = __( 'Pingback' );
653 $type = __( 'Trackback' );
656 $type = ucwords( $comment->comment_type );
658 $type = esc_html( $type );
660 <div class="dashboard-comment-wrap">
661 <?php /* translators: %1$s is type of comment, %2$s is link to the post */ ?>
662 <h4 class="comment-meta"><?php printf( _x( '%1$s on %2$s', 'dashboard' ), "<strong>$type</strong>", $comment_post_link." ".$comment_link ); ?></h4>
663 <p class="comment-author"><?php comment_author_link(); ?></p>
665 <?php endif; // comment_type ?>
666 <blockquote><p><?php comment_excerpt(); ?></p></blockquote>
667 <p class="row-actions"><?php echo $actions_string; ?></p>
674 * The recent comments dashboard widget control.
678 function wp_dashboard_recent_comments_control() {
679 if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
680 $widget_options = array();
682 if ( !isset($widget_options['dashboard_recent_comments']) )
683 $widget_options['dashboard_recent_comments'] = array();
685 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-recent-comments']) ) {
686 $number = (int) stripslashes($_POST['widget-recent-comments']['items']);
687 if ( $number < 1 || $number > 30 )
689 $widget_options['dashboard_recent_comments']['items'] = $number;
690 update_option( 'dashboard_widget_options', $widget_options );
693 $number = isset( $widget_options['dashboard_recent_comments']['items'] ) ? (int) $widget_options['dashboard_recent_comments']['items'] : '';
695 echo '<p><label for="comments-number">' . __('Number of comments to show:') . '</label>';
696 echo '<input id="comments-number" name="widget-recent-comments[items]" type="text" value="' . $number . '" size="3" /> <small>' . __( '(at most 30)' ) . '</small></p>';
699 function wp_dashboard_incoming_links() {
700 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
704 * Display incoming links dashboard widget content.
708 function wp_dashboard_incoming_links_output() {
709 $widgets = get_option( 'dashboard_widget_options' );
710 @extract( @$widgets['dashboard_incoming_links'], EXTR_SKIP );
711 $rss = fetch_feed( $url );
713 if ( is_wp_error($rss) ) {
714 if ( is_admin() || current_user_can('manage_options') ) {
716 printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
722 if ( !$rss->get_item_quantity() ) {
723 echo '<p>' . __('This dashboard widget queries <a href="http://blogsearch.google.com/">Google Blog Search</a> so that when another blog links to your site it will show up here. It has found no incoming links… yet. It’s okay — there is no rush.') . "</p>\n";
731 if ( !isset($items) )
734 foreach ( $rss->get_items(0, $items) as $item ) {
740 $link = esc_url( strip_tags( $item->get_link() ) );
742 $author = $item->get_author();
744 $site_link = esc_url( strip_tags( $author->get_link() ) );
746 if ( !$publisher = esc_html( strip_tags( $author->get_name() ) ) )
747 $publisher = __( 'Somebody' );
749 $publisher = __( 'Somebody' );
752 $publisher = "<a href='$site_link'>$publisher</a>";
754 $publisher = "<strong>$publisher</strong>";
756 $content = $item->get_content();
757 $content = wp_html_excerpt($content, 50) . ' ...';
760 /* translators: incoming links feed, %1$s is other person, %3$s is content */
761 $text = __( '%1$s linked here <a href="%2$s">saying</a>, "%3$s"' );
763 /* translators: incoming links feed, %1$s is other person, %3$s is content */
764 $text = __( '%1$s linked here saying, "%3$s"' );
767 if ( $show_author || $show_summary )
768 /* translators: incoming links feed, %4$s is the date */
769 $text .= ' ' . __( 'on %4$s' );
770 $date = esc_html( strip_tags( $item->get_date() ) );
771 $date = strtotime( $date );
772 $date = gmdate( get_option( 'date_format' ), $date );
775 echo "\t<li>" . sprintf( $text, $publisher, $link, $content, $date ) . "</li>\n";
783 function wp_dashboard_incoming_links_control() {
784 wp_dashboard_rss_control( 'dashboard_incoming_links', array( 'title' => false, 'show_summary' => false, 'show_author' => false ) );
787 function wp_dashboard_primary() {
788 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
791 function wp_dashboard_primary_control() {
792 wp_dashboard_rss_control( 'dashboard_primary' );
796 * {@internal Missing Short Description}}
800 * @param int $widget_id
802 function wp_dashboard_rss_output( $widget_id ) {
803 $widgets = get_option( 'dashboard_widget_options' );
804 echo '<div class="rss-widget">';
805 wp_widget_rss_output( $widgets[$widget_id] );
809 function wp_dashboard_secondary() {
810 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
813 function wp_dashboard_secondary_control() {
814 wp_dashboard_rss_control( 'dashboard_secondary' );
818 * Display secondary dashboard RSS widget feed.
824 function wp_dashboard_secondary_output() {
825 $widgets = get_option( 'dashboard_widget_options' );
826 @extract( @$widgets['dashboard_secondary'], EXTR_SKIP );
827 $rss = @fetch_feed( $url );
829 if ( is_wp_error($rss) ) {
830 if ( is_admin() || current_user_can('manage_options') ) {
831 echo '<div class="rss-widget"><p>';
832 printf(__('<strong>RSS Error</strong>: %s'), $rss->get_error_message());
835 } elseif ( !$rss->get_item_quantity() ) {
840 echo '<div class="rss-widget">';
841 wp_widget_rss_output( $rss, $widgets['dashboard_secondary'] );
848 function wp_dashboard_plugins() {
849 echo '<p class="widget-loading hide-if-no-js">' . __( 'Loading…' ) . '</p><p class="describe hide-if-js">' . __('This widget requires JavaScript.') . '</p>';
853 * Display plugins most popular, newest plugins, and recently updated widget text.
857 function wp_dashboard_plugins_output() {
858 $popular = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/popular/' );
859 $new = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/new/' );
860 $updated = fetch_feed( 'http://wordpress.org/extend/plugins/rss/browse/updated/' );
862 if ( false === $plugin_slugs = get_transient( 'plugin_slugs' ) ) {
863 $plugin_slugs = array_keys( get_plugins() );
864 set_transient( 'plugin_slugs', $plugin_slugs, 86400 );
867 foreach ( array( 'popular' => __('Most Popular'), 'new' => __('Newest Plugins'), 'updated' => __('Recently Updated') ) as $feed => $label ) {
868 if ( is_wp_error($$feed) || !$$feed->get_item_quantity() )
871 $items = $$feed->get_items(0, 5);
873 // Pick a random, non-installed plugin
875 // Abort this foreach loop iteration if there's no plugins left of this type
876 if ( 0 == count($items) )
879 $item_key = array_rand($items);
880 $item = $items[$item_key];
882 list($link, $frag) = explode( '#', $item->get_link() );
884 $link = esc_url($link);
885 if ( preg_match( '|/([^/]+?)/?$|', $link, $matches ) )
888 unset( $items[$item_key] );
892 // Is this random plugin's slug already installed? If so, try again.
893 reset( $plugin_slugs );
894 foreach ( $plugin_slugs as $plugin_slug ) {
895 if ( $slug == substr( $plugin_slug, 0, strlen( $slug ) ) ) {
896 unset( $items[$item_key] );
901 // If we get to this point, then the random plugin isn't installed and we can stop the while().
905 // Eliminate some common badly formed plugin descriptions
906 while ( ( null !== $item_key = array_rand($items) ) && false !== strpos( $items[$item_key]->get_description(), 'Plugin Name:' ) )
907 unset($items[$item_key]);
909 if ( !isset($items[$item_key]) )
912 // current bbPress feed item titles are: user on "topic title"
913 if ( preg_match( '/"(.*)"/s', $item->get_title(), $matches ) )
914 $title = $matches[1];
915 else // but let's make it forward compatible if things change
916 $title = $item->get_title();
917 $title = esc_html( $title );
919 $description = esc_html( strip_tags(@html_entity_decode($item->get_description(), ENT_QUOTES, get_option('blog_charset'))) );
921 $ilink = wp_nonce_url('plugin-install.php?tab=plugin-information&plugin=' . $slug, 'install-plugin_' . $slug) .
922 '&TB_iframe=true&width=600&height=800';
924 echo "<h4>$label</h4>\n";
925 echo "<h5><a href='$link'>$title</a></h5> <span>(<a href='$ilink' class='thickbox' title='$title'>" . __( 'Install' ) . "</a>)</span>\n";
926 echo "<p>$description</p>\n";
928 $$feed->__destruct();
934 * Checks to see if all of the feed url in $check_urls are cached.
936 * If $check_urls is empty, look for the rss feed url found in the dashboard
937 * widget optios of $widget_id. If cached, call $callback, a function that
938 * echoes out output for this widget. If not cache, echo a "Loading..." stub
939 * which is later replaced by AJAX call (see top of /wp-admin/index.php)
943 * @param int $widget_id
944 * @param callback $callback
945 * @param array $check_urls RSS feeds
946 * @return bool False on failure. True on success.
948 function wp_dashboard_cached_rss_widget( $widget_id, $callback, $check_urls = array() ) {
949 $loading = '<p class="widget-loading">' . __( 'Loading…' ) . '</p>';
951 if ( empty($check_urls) ) {
952 $widgets = get_option( 'dashboard_widget_options' );
953 if ( empty($widgets[$widget_id]['url']) ) {
957 $check_urls = array( $widgets[$widget_id]['url'] );
960 include_once ABSPATH . WPINC . '/class-feed.php';
961 foreach ( $check_urls as $check_url ) {
962 $cache = new WP_Feed_Cache_Transient('', md5($check_url), '');
963 if ( ! $cache->load() ) {
969 if ( $callback && is_callable( $callback ) ) {
970 $args = array_slice( func_get_args(), 2 );
971 array_unshift( $args, $widget_id );
972 call_user_func_array( $callback, $args );
978 /* Dashboard Widgets Controls */
980 // Calls widget_control callback
982 * Calls widget control callback.
986 * @param int $widget_control_id Registered Widget ID.
988 function wp_dashboard_trigger_widget_control( $widget_control_id = false ) {
989 global $wp_dashboard_control_callbacks;
991 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]) ) {
992 call_user_func( $wp_dashboard_control_callbacks[$widget_control_id], '', array( 'id' => $widget_control_id, 'callback' => $wp_dashboard_control_callbacks[$widget_control_id] ) );
997 * The RSS dashboard widget control.
999 * Sets up $args to be used as input to wp_widget_rss_form(). Handles POST data
1000 * from RSS-type widgets.
1004 * @param string widget_id
1005 * @param array form_inputs
1007 function wp_dashboard_rss_control( $widget_id, $form_inputs = array() ) {
1008 if ( !$widget_options = get_option( 'dashboard_widget_options' ) )
1009 $widget_options = array();
1011 if ( !isset($widget_options[$widget_id]) )
1012 $widget_options[$widget_id] = array();
1014 $number = 1; // Hack to use wp_widget_rss_form()
1015 $widget_options[$widget_id]['number'] = $number;
1017 if ( 'POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['widget-rss'][$number]) ) {
1018 $_POST['widget-rss'][$number] = stripslashes_deep( $_POST['widget-rss'][$number] );
1019 $widget_options[$widget_id] = wp_widget_rss_process( $_POST['widget-rss'][$number] );
1020 // title is optional. If black, fill it if possible
1021 if ( !$widget_options[$widget_id]['title'] && isset($_POST['widget-rss'][$number]['title']) ) {
1022 $rss = fetch_feed($widget_options[$widget_id]['url']);
1023 if ( is_wp_error($rss) ) {
1024 $widget_options[$widget_id]['title'] = htmlentities(__('Unknown Feed'));
1026 $widget_options[$widget_id]['title'] = htmlentities(strip_tags($rss->get_title()));
1031 update_option( 'dashboard_widget_options', $widget_options );
1034 wp_widget_rss_form( $widget_options[$widget_id], $form_inputs );
1038 * Empty function usable by plugins to output empty dashboard widget (to be populated later by JS).
1040 function wp_dashboard_empty() {}