' . __( 'See All' ) . '';
-
- $content_class = 'dashboard-widget-content';
- if ( current_user_can( 'edit_dashboard' ) && isset($wp_registered_widget_controls[$widget_id]) && is_callable($wp_registered_widget_controls[$widget_id]['callback']) ) {
- // Switch this widget to edit mode
- if ( isset($_GET['edit']) && $_GET['edit'] == $widget_id ) {
- $content_class .= ' dashboard-widget-control';
- $wp_registered_widgets[$widget_id]['callback'] = 'wp_dashboard_empty';
- $sidebar_widget_name = $wp_registered_widget_controls[$widget_id]['name'];
- $params[1] = 'wp_dashboard_trigger_widget_control';
- $sidebar_before_widget .= '
';
- }
+/* Dashboard Widgets */
+
+function wp_dashboard_right_now() {
+ global $wp_registered_sidebars;
+
+ $num_posts = wp_count_posts( 'post' );
+ $num_pages = wp_count_posts( 'page' );
+
+ $num_cats = wp_count_terms('category');
+
+ $num_tags = wp_count_terms('post_tag');
+
+ $num_comm = wp_count_comments( );
+
+ echo "\n\t".'
\n\n";
+ echo "\n\t".'
';
+ echo "\n\t".'
' . __('Discussion') . '
'."\n\t".'
';
+ echo "\n\t".'';
- $sidebar_after_widget .= "\t\t\t\n\n";
+ // Total Comments
+ $num = '' . number_format_i18n($num_comm->total_comments) . '';
+ $text = _n( 'Comment', 'Comments', $num_comm->total_comments );
+ if ( current_user_can( 'moderate_comments' ) ) {
+ $num = '' . $num . '';
+ $text = '' . $text . '';
+ }
+ echo '';
+ echo '';
+
+ echo '
';
- foreach( array_keys( $params[0] ) as $key )
- $$key = ${'sidebar_' . $key};
+ // Approved Comments
+ $num = '' . number_format_i18n($num_comm->approved) . '';
+ $text = _nx( 'Approved', 'Approved', $num_comm->approved, 'Right Now' );
+ if ( current_user_can( 'moderate_comments' ) ) {
+ $num = "$num";
+ $text = "$text";
+ }
+ echo '' . $num . ' | ';
+ echo '' . $text . ' | ';
- $params[0] = compact( array_keys( $params[0] ) );
+ echo "
\n\t";
- return $params;
+ // Pending Comments
+ $num = '' . number_format_i18n($num_comm->moderated) . '';
+ $text = _n( 'Pending', 'Pending', $num_comm->moderated );
+ if ( current_user_can( 'moderate_comments' ) ) {
+ $num = "$num";
+ $text = "$text";
+ }
+ echo '' . $num . ' | ';
+ echo '' . $text . ' | ';
+
+ echo "
\n\t";
+
+ // Spam Comments
+ $num = number_format_i18n($num_comm->spam);
+ $text = _nx( 'Spam', 'Spam', $num_comm->spam, 'comment' );
+ if ( current_user_can( 'moderate_comments' ) ) {
+ $num = "$num";
+ $text = "$text";
+ }
+ echo '' . $num . ' | ';
+ echo '' . $text . ' | ';
+
+ echo "
";
+ do_action('right_now_table_end');
+ do_action('right_now_discussion_table_end');
+ echo "\n\t
\n\t
";
+
+ echo "\n\t".'
';
+ $ct = current_theme_info();
+
+ echo "\n\t
";
+ if ( !empty($wp_registered_sidebars) ) {
+ $sidebars_widgets = wp_get_sidebars_widgets();
+ $num_widgets = 0;
+ foreach ( (array) $sidebars_widgets as $k => $v ) {
+ if ( 'wp_inactive_widgets' == $k )
+ continue;
+ if ( is_array($v) )
+ $num_widgets = $num_widgets + count($v);
+ }
+ $num = number_format_i18n( $num_widgets );
+
+ $switch_themes = $ct->title;
+ if ( current_user_can( 'switch_themes') ) {
+ echo '' . __('Change Theme') . '';
+ $switch_themes = '' . $switch_themes . '';
+ }
+ if ( current_user_can( 'edit_theme_options' ) ) {
+ printf(_n('Theme %1$s with %2$s Widget', 'Theme %1$s with %2$s Widgets', $num_widgets), $switch_themes, $num);
+ } else {
+ printf(_n('Theme %1$s with %2$s Widget', 'Theme %1$s with %2$s Widgets', $num_widgets), $switch_themes, $num);
+ }
+ } else {
+ if ( current_user_can( 'switch_themes' ) ) {
+ echo '' . __('Change Theme') . '';
+ printf( __('Theme %1$s'), $ct->title );
+ } else {
+ printf( __('Theme %1$s'), $ct->title );
+ }
+ }
+ echo '
';
+
+ update_right_now_message();
+
+ echo "\n\t".'
';
+ do_action( 'rightnow_end' );
+ do_action( 'activity_box_end' );
}
+function wp_dashboard_quick_press_output() {
+ global $post_ID;
-/* Dashboard Widgets */
+ $drafts = false;
+ if ( 'post' === strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST['action'] ) && 0 === strpos( $_POST['action'], 'post-quickpress' ) && (int) $_POST['post_ID'] ) {
+ $view = get_permalink( $_POST['post_ID'] );
+ $edit = esc_url( get_edit_post_link( $_POST['post_ID'] ) );
+ if ( 'post-quickpress-publish' == $_POST['action'] ) {
+ if ( current_user_can('publish_posts') )
+ printf( '
', esc_url( $view ), $edit );
+ else
+ printf( '
', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
+ } else {
+ printf( '
', esc_url( add_query_arg( 'preview', 1, $view ) ), $edit );
+ $drafts_query = new WP_Query( array(
+ 'post_type' => 'post',
+ 'post_status' => 'draft',
+ 'author' => $GLOBALS['current_user']->ID,
+ 'posts_per_page' => 1,
+ 'orderby' => 'modified',
+ 'order' => 'DESC'
+ ) );
+
+ if ( $drafts_query->posts )
+ $drafts =& $drafts_query->posts;
+ }
+ printf('
' . __('You can also try %s, easy blogging from anywhere on the Web.') . '
', '
' . __('Press This') . '' );
+ $_REQUEST = array(); // hack for get_default_post_to_edit()
+ }
+
+ /* Check if a new auto-draft (= no new post_ID) is needed or if the old can be used */
+ $last_post_id = (int) get_user_option( 'dashboard_quick_press_last_post_id' ); // Get the last post_ID
+ if ( $last_post_id ) {
+ $post = get_post( $last_post_id );
+ if ( empty( $post ) || $post->post_status != 'auto-draft' ) { // auto-draft doesn't exists anymore
+ $post = get_default_post_to_edit('post', true);
+ update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
+ } else {
+ $post->post_title = ''; // Remove the auto draft title
+ }
+ } else {
+ $post = get_default_post_to_edit('post', true);
+ update_user_option( (int) $GLOBALS['current_user']->ID, 'dashboard_quick_press_last_post_id', (int) $post->ID ); // Save post_ID
+ }
+
+ $post_ID = (int) $post->ID;
+?>
+
+
+
+' . __( 'Loading…' ) . '
' . __('This widget requires JavaScript.') . '
';
+}
-function wp_dashboard_recent_comments( $sidebar_args ) {
- global $comment;
- extract( $sidebar_args, EXTR_SKIP );
+function wp_dashboard_recent_drafts( $drafts = false ) {
+ if ( !$drafts ) {
+ $drafts_query = new WP_Query( array(
+ 'post_type' => 'post',
+ 'post_status' => 'draft',
+ 'author' => $GLOBALS['current_user']->ID,
+ 'posts_per_page' => 5,
+ 'orderby' => 'modified',
+ 'order' => 'DESC'
+ ) );
+ $drafts =& $drafts_query->posts;
+ }
- echo $before_widget;
+ if ( $drafts && is_array( $drafts ) ) {
+ $list = array();
+ foreach ( $drafts as $draft ) {
+ $url = get_edit_post_link( $draft->ID );
+ $title = _draft_or_post_title( $draft->ID );
+ $item = "
" . esc_html($title) . " " . get_the_time( get_option( 'date_format' ), $draft ) . '
';
+ if ( $the_content = preg_split( '#\s#', strip_tags( $draft->post_content ), 11, PREG_SPLIT_NO_EMPTY ) )
+ $item .= '
' . join( ' ', array_slice( $the_content, 0, 10 ) ) . ( 10 < count( $the_content ) ? '…' : '' ) . '
';
+ $list[] = $item;
+ }
+?>
+
+
+ 'rss2', 'withcomments' => 1));
- remove_filter( 'option_posts_per_rss', $lambda );
+ if ( current_user_can('edit_posts') )
+ $allowed_states = array('0', '1');
+ else
+ $allowed_states = array('1');
- $is_first = true;
+ // Select all comment types and filter out spam later for better query performance.
+ $comments = array();
+ $start = 0;
- if ( $comments_query->have_comments() ) {
- while ( $comments_query->have_comments() ) { $comments_query->the_comment();
+ $widgets = get_option( 'dashboard_widget_options' );
+ if ( isset( $widgets['dashboard_recent_comments'] ) && isset( $widgets['dashboard_recent_comments']['items'] ) )
+ $total_items = (int) $widgets['dashboard_recent_comments']['items'];
+ else
+ $total_items = 5;
+
+ 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" ) ) {
+
+ foreach ( $possible as $comment ) {
+ if ( count( $comments ) >= $total_items )
+ break;
+ if ( in_array( $comment->comment_approved, $allowed_states ) && current_user_can( 'read_post', $comment->comment_post_ID ) )
+ $comments[] = $comment;
+ }
- $comment_post_url = get_permalink( $comment->comment_post_ID );
- $comment_post_title = get_the_title( $comment->comment_post_ID );
- $comment_post_link = "
$comment_post_title";
- $comment_link = '';
- $comment_meta = sprintf( __( 'From
%1$s on %2$s %3$s' ), get_comment_author(), $comment_post_link, $comment_link );
+ $start = $start + 50;
+ }
- if ( $is_first ) : $is_first = false;
+ if ( $comments ) :
?>
-
“”
-
+
+
+
+
+
-
+
+
comment_post_ID );
+ $comment_post_title = strip_tags(get_the_title( $comment->comment_post_ID ));
+ $comment_post_link = "
$comment_post_title";
+ $comment_link = '';
+
+ $actions_string = '';
+ if ( current_user_can('edit_post', $comment->comment_post_ID) ) {
+ // preorder it: Approve | Reply | Edit | Spam | Trash
+ $actions = array(
+ 'approve' => '', 'unapprove' => '',
+ 'reply' => '',
+ 'edit' => '',
+ 'spam' => '',
+ 'trash' => '', 'delete' => ''
+ );
+
+ $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
+ $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
+
+ $approve_url = esc_url( "comment.php?action=approvecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
+ $unapprove_url = esc_url( "comment.php?action=unapprovecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$approve_nonce" );
+ $spam_url = esc_url( "comment.php?action=spamcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
+ $trash_url = esc_url( "comment.php?action=trashcomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
+ $delete_url = esc_url( "comment.php?action=deletecomment&p=$comment->comment_post_ID&c=$comment->comment_ID&$del_nonce" );
+
+ $actions['approve'] = "';
+ $actions['unapprove'] = "';
+ $actions['edit'] = "
". __('Edit') . '';
+ $actions['reply'] = '
' . __('Reply') . '';
+ $actions['spam'] = "';
+ if ( !EMPTY_TRASH_DAYS )
+ $actions['delete'] = "';
+ else
+ $actions['trash'] = "';
+
+ $actions = apply_filters( 'comment_row_actions', array_filter($actions), $comment );
+
+ $i = 0;
+ foreach ( $actions as $action => $link ) {
+ ++$i;
+ ( ( ('approve' == $action || 'unapprove' == $action) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
+
+ // Reply and quickedit need a hide-if-no-js span
+ if ( 'reply' == $action || 'quickedit' == $action )
+ $action .= ' hide-if-no-js';
+
+ $actions_string .= "
$sep$link";
}
+ }
- if ( $comments_query->comment_count > 1 ) : ?>
-
+?>
+
+
+ foreach ( $comments as $comment ) + _wp_dashboard_recent_comments_row( $comment ); +?> + +