3 * Comments and Post Comments List Table classes.
6 * @subpackage List_Table
11 * Comments List Table class.
14 * @subpackage List_Table
18 class WP_Comments_List_Table extends WP_List_Table {
22 var $pending_count = array();
24 function WP_Comments_List_Table() {
27 $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
29 if ( get_option('show_avatars') )
30 add_filter( 'comment_author', 'floated_admin_avatar' );
32 parent::WP_List_Table( array(
33 'plural' => 'comments',
34 'singular' => 'comment',
39 function ajax_user_can() {
40 return current_user_can('edit_posts');
43 function prepare_items() {
44 global $post_id, $comment_status, $search, $comment_type;
46 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
47 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
48 $comment_status = 'all';
50 $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
52 $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
54 $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
56 $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
57 $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
59 $comments_per_page = $this->get_per_page( $comment_status );
61 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
63 if ( isset( $_REQUEST['number'] ) ) {
64 $number = (int) $_REQUEST['number'];
67 $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
70 $page = $this->get_pagenum();
72 if ( isset( $_REQUEST['start'] ) ) {
73 $start = $_REQUEST['start'];
75 $start = ( $page - 1 ) * $comments_per_page;
78 if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
79 $start += $_REQUEST['offset'];
83 'moderated' => 'hold',
84 'approved' => 'approve'
88 'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
90 'user_id' => $user_id,
93 'post_id' => $post_id,
94 'type' => $comment_type,
95 'orderby' => $orderby,
99 $_comments = get_comments( $args );
101 update_comment_cache( $_comments );
103 $this->items = array_slice( $_comments, 0, $comments_per_page );
104 $this->extra_items = array_slice( $_comments, $comments_per_page );
106 $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) );
108 $_comment_post_ids = array();
109 foreach ( $_comments as $_c ) {
110 $_comment_post_ids[] = $_c->comment_post_ID;
113 $this->pending_count = get_pending_comments_num( $_comment_post_ids );
115 $this->set_pagination_args( array(
116 'total_items' => $total_comments,
117 'per_page' => $comments_per_page,
121 function get_per_page( $comment_status = 'all' ) {
122 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
123 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
124 return $comments_per_page;
127 function no_items() {
128 global $comment_status;
130 if ( 'moderated' == $comment_status )
131 _e( 'No comments awaiting moderation… yet.' );
133 _e( 'No comments found.' );
136 function get_views() {
137 global $post_id, $comment_status;
139 $status_links = array();
140 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
141 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"),
142 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>")
144 'all' => _nx_noop('All', 'All', 'comments'), // singular not used
145 'moderated' => _n_noop('Pending <span class="count">(<span class="pending-count">%s</span>)</span>', 'Pending <span class="count">(<span class="pending-count">%s</span>)</span>'),
146 'approved' => _n_noop('Approved', 'Approved'), // singular not used
147 'spam' => _n_noop('Spam <span class="count">(<span class="spam-count">%s</span>)</span>', 'Spam <span class="count">(<span class="spam-count">%s</span>)</span>'),
148 'trash' => _n_noop('Trash <span class="count">(<span class="trash-count">%s</span>)</span>', 'Trash <span class="count">(<span class="trash-count">%s</span>)</span>')
151 if ( !EMPTY_TRASH_DAYS )
152 unset($stati['trash']);
154 $link = 'edit-comments.php';
155 if ( !empty($comment_type) && 'all' != $comment_type )
156 $link = add_query_arg( 'comment_type', $comment_type, $link );
158 foreach ( $stati as $status => $label ) {
159 $class = ( $status == $comment_status ) ? ' class="current"' : '';
161 if ( !isset( $num_comments->$status ) )
162 $num_comments->$status = 10;
163 $link = add_query_arg( 'comment_status', $status, $link );
165 $link = add_query_arg( 'p', absint( $post_id ), $link );
167 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
168 if ( !empty( $_REQUEST['s'] ) )
169 $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
171 $status_links[$status] = "<a href='$link'$class>" . sprintf(
172 translate_nooped_plural( $label, $num_comments->$status ),
173 number_format_i18n( $num_comments->$status )
177 $status_links = apply_filters( 'comment_status_links', $status_links );
178 return $status_links;
181 function get_bulk_actions() {
182 global $comment_status;
185 if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
186 $actions['unapprove'] = __( 'Unapprove' );
187 if ( in_array( $comment_status, array( 'all', 'moderated', 'spam' ) ) )
188 $actions['approve'] = __( 'Approve' );
189 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved' ) ) )
190 $actions['spam'] = _x( 'Mark as Spam', 'comment' );
192 if ( 'trash' == $comment_status )
193 $actions['untrash'] = __( 'Restore' );
194 elseif ( 'spam' == $comment_status )
195 $actions['unspam'] = _x( 'Not Spam', 'comment' );
197 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
198 $actions['delete'] = __( 'Delete Permanently' );
200 $actions['trash'] = __( 'Move to Trash' );
205 function extra_tablenav( $which ) {
206 global $comment_status, $comment_type;
208 <div class="alignleft actions">
210 if ( 'top' == $which ) {
212 <select name="comment_type">
213 <option value=""><?php _e( 'Show all comment types' ); ?></option>
215 $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
216 'comment' => __( 'Comments' ),
217 'pings' => __( 'Pings' ),
220 foreach ( $comment_types as $type => $label )
221 echo "\t<option value='" . esc_attr( $type ) . "'" . selected( $comment_type, $type, false ) . ">$label</option>\n";
225 submit_button( __( 'Filter' ), 'secondary', false, false, array( 'id' => 'post-query-submit' ) );
228 if ( ( 'spam' == $comment_status || 'trash' == $comment_status ) && current_user_can( 'moderate_comments' ) ) {
229 wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
230 $title = ( 'spam' == $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
231 submit_button( $title, 'button-secondary apply', 'delete_all', false );
233 do_action( 'manage_comments_nav', $comment_status );
237 function current_action() {
238 if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
241 return parent::current_action();
244 function get_columns() {
249 if ( $this->checkbox )
250 $columns['cb'] = '<input type="checkbox" />';
252 $columns['author'] = __( 'Author' );
253 $columns['comment'] = _x( 'Comment', 'column name' );
256 $columns['response'] = _x( 'In Response To', 'column name' );
261 function get_sortable_columns() {
263 'author' => 'comment_author',
264 'response' => 'comment_post_ID'
269 extract( $this->_args );
271 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
273 $this->display_tablenav( 'top' );
276 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
279 <?php $this->print_column_headers(); ?>
285 <?php $this->print_column_headers( false ); ?>
289 <tbody id="the-comment-list" class="list:comment">
290 <?php $this->display_rows_or_placeholder(); ?>
293 <tbody id="the-extra-comment-list" class="list:comment" style="display: none;">
294 <?php $this->items = $this->extra_items; $this->display_rows(); ?>
299 $this->display_tablenav( 'bottom' );
302 function single_row( $a_comment ) {
303 global $post, $comment, $the_comment_status;
305 $comment = $a_comment;
306 $the_comment_status = wp_get_comment_status( $comment->comment_ID );
308 $post = get_post( $comment->comment_post_ID );
310 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
312 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_status'>";
313 echo $this->single_row_columns( $comment );
317 function column_cb( $comment ) {
318 if ( $this->user_can )
319 echo "<input type='checkbox' name='delete_comments[]' value='$comment->comment_ID' />";
322 function column_comment( $comment ) {
323 global $post, $comment_status, $the_comment_status;
325 $user_can = $this->user_can;
327 $comment_url = esc_url( get_comment_link( $comment->comment_ID ) );
329 $ptime = date( 'G', strtotime( $comment->comment_date ) );
330 if ( ( abs( time() - $ptime ) ) < 86400 )
331 $ptime = sprintf( __( '%s ago' ), human_time_diff( $ptime ) );
333 $ptime = mysql2date( __( 'Y/m/d \a\t g:i A' ), $comment->comment_date );
336 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
337 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
339 $url = "comment.php?c=$comment->comment_ID";
341 $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
342 $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
343 $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
344 $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
345 $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
346 $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
347 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
350 echo '<div class="submitted-on">';
351 /* translators: 2: comment date, 3: comment time */
352 printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url,
353 /* translators: comment date format. See http://php.net/date */ get_comment_date( __( 'Y/m/d' ) ),
354 /* translators: comment time format. See http://php.net/date */ get_comment_date( get_option( 'time_format' ) ) );
356 if ( $comment->comment_parent ) {
357 $parent = get_comment( $comment->comment_parent );
358 $parent_link = esc_url( get_comment_link( $comment->comment_parent ) );
359 $name = get_comment_author( $parent->comment_ID );
360 printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name );
365 if ( $user_can ) { ?>
366 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
367 <textarea class="comment" rows="1" cols="1"><?php echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); ?></textarea>
368 <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
369 <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
370 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
371 <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
377 // preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash
379 'approve' => '', 'unapprove' => '',
383 'spam' => '', 'unspam' => '',
384 'trash' => '', 'untrash' => '', 'delete' => ''
387 if ( $comment_status && 'all' != $comment_status ) { // not looking at all comments
388 if ( 'approved' == $the_comment_status )
389 $actions['unapprove'] = "<a href='$unapprove_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
390 else if ( 'unapproved' == $the_comment_status )
391 $actions['approve'] = "<a href='$approve_url' class='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
393 $actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
394 $actions['unapprove'] = "<a href='$unapprove_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved vim-u' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
397 if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) {
398 $actions['spam'] = "<a href='$spam_url' class='delete:the-comment-list:comment-$comment->comment_ID::spam=1 vim-s vim-destructive' title='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>';
399 } elseif ( 'spam' == $the_comment_status ) {
400 $actions['unspam'] = "<a href='$unspam_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1 vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>';
401 } elseif ( 'trash' == $the_comment_status ) {
402 $actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
405 if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) {
406 $actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>';
408 $actions['trash'] = "<a href='$trash_url' class='delete:the-comment-list:comment-$comment->comment_ID::trash=1 delete vim-d vim-destructive' title='" . esc_attr__( 'Move this comment to the trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>';
411 if ( 'trash' != $the_comment_status ) {
412 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>';
413 $actions['quickedit'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\',\'edit\' );return false;" class="vim-q" title="'.esc_attr__( 'Quick Edit' ).'" href="#">' . __( 'Quick Edit' ) . '</a>';
414 if ( 'spam' != $the_comment_status )
415 $actions['reply'] = '<a onclick="commentReply.open( \''.$comment->comment_ID.'\',\''.$post->ID.'\' );return false;" class="vim-r" title="'.esc_attr__( 'Reply to this comment' ).'" href="#">' . __( 'Reply' ) . '</a>';
418 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
421 echo '<div class="row-actions">';
422 foreach ( $actions as $action => $link ) {
424 ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
426 // Reply and quickedit need a hide-if-no-js span when not added with ajax
427 if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') )
428 $action .= ' hide-if-no-js';
429 elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) {
430 if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) )
431 $action .= ' approve';
433 $action .= ' unapprove';
436 echo "<span class='$action'>$sep$link</span>";
442 function column_author( $comment ) {
443 global $comment_status;
445 $author_url = get_comment_author_url();
446 if ( 'http://' == $author_url )
448 $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url );
449 if ( strlen( $author_url_display ) > 50 )
450 $author_url_display = substr( $author_url_display, 0, 49 ) . '...';
452 echo "<strong>"; comment_author(); echo '</strong><br />';
453 if ( !empty( $author_url ) )
454 echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />";
456 if ( $this->user_can ) {
457 if ( !empty( $comment->comment_author_email ) ) {
458 comment_author_email_link();
461 echo '<a href="edit-comments.php?s=';
463 echo '&mode=detail';
464 if ( 'spam' == $comment_status )
465 echo '&comment_status=spam';
472 function column_date( $comment ) {
473 return get_comment_date( __( 'Y/m/d \a\t g:ia' ) );
476 function column_response( $comment ) {
479 if ( isset( $this->pending_count[$post->ID] ) ) {
480 $pending_comments = $this->pending_count[$post->ID];
482 $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
483 $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
486 if ( current_user_can( 'edit_post', $post->ID ) ) {
487 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>";
488 $post_link .= get_the_title( $post->ID ) . '</a>';
490 $post_link = get_the_title( $post->ID );
493 echo '<div class="response-links"><span class="post-com-count-wrapper">';
494 echo $post_link . '<br />';
495 $this->comments_bubble( $post->ID, $pending_comments );
497 echo "<a href='" . get_permalink( $post->ID ) . "'>#</a>";
499 if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) )
503 function column_default( $comment, $column_name ) {
504 do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
509 * Post Comments List Table class.
512 * @subpackage List_Table
516 * @see WP_Comments_Table
518 class WP_Post_Comments_List_Table extends WP_Comments_List_Table {
520 function get_column_info() {
521 $this->_column_headers = array(
523 'author' => __( 'Author' ),
524 'comment' => _x( 'Comment', 'column name' ),
530 return $this->_column_headers;
533 function get_table_classes() {
534 $classes = parent::get_table_classes();
535 $classes[] = 'comments-box';
539 function display( $output_empty = false ) {
540 extract( $this->_args );
542 wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
544 <table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0" style="display:none;">
545 <tbody id="the-comment-list"<?php if ( $singular ) echo " class='list:$singular'"; ?>>
546 <?php if ( ! $output_empty ) $this->display_rows_or_placeholder(); ?>
552 function get_per_page( $comment_status = false ) {