27 |
27 |
28 /** |
28 /** |
29 * Constructor. |
29 * Constructor. |
30 * |
30 * |
31 * @since 3.1.0 |
31 * @since 3.1.0 |
32 * @access public |
|
33 * |
32 * |
34 * @see WP_List_Table::__construct() for more information on default arguments. |
33 * @see WP_List_Table::__construct() for more information on default arguments. |
|
34 * |
|
35 * @global int $post_id |
35 * |
36 * |
36 * @param array $args An associative array of arguments. |
37 * @param array $args An associative array of arguments. |
37 */ |
38 */ |
38 public function __construct( $args = array() ) { |
39 public function __construct( $args = array() ) { |
39 global $post_id; |
40 global $post_id; |
40 |
41 |
41 $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0; |
42 $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0; |
42 |
43 |
43 if ( get_option('show_avatars') ) |
44 if ( get_option( 'show_avatars' ) ) { |
44 add_filter( 'comment_author', 'floated_admin_avatar' ); |
45 add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 ); |
|
46 } |
45 |
47 |
46 parent::__construct( array( |
48 parent::__construct( array( |
47 'plural' => 'comments', |
49 'plural' => 'comments', |
48 'singular' => 'comment', |
50 'singular' => 'comment', |
49 'ajax' => true, |
51 'ajax' => true, |
50 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
52 'screen' => isset( $args['screen'] ) ? $args['screen'] : null, |
51 ) ); |
53 ) ); |
52 } |
54 } |
53 |
55 |
|
56 public function floated_admin_avatar( $name, $comment_ID ) { |
|
57 $comment = get_comment( $comment_ID ); |
|
58 $avatar = get_avatar( $comment, 32, 'mystery' ); |
|
59 return "$avatar $name"; |
|
60 } |
|
61 |
|
62 /** |
|
63 * @return bool |
|
64 */ |
54 public function ajax_user_can() { |
65 public function ajax_user_can() { |
55 return current_user_can('edit_posts'); |
66 return current_user_can('edit_posts'); |
56 } |
67 } |
57 |
68 |
|
69 /** |
|
70 * |
|
71 * @global int $post_id |
|
72 * @global string $comment_status |
|
73 * @global string $search |
|
74 * @global string $comment_type |
|
75 */ |
58 public function prepare_items() { |
76 public function prepare_items() { |
59 global $post_id, $comment_status, $search, $comment_type; |
77 global $post_id, $comment_status, $search, $comment_type; |
60 |
78 |
61 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; |
79 $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all'; |
62 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) |
80 if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) |
114 'order' => $order, |
132 'order' => $order, |
115 'post_type' => $post_type, |
133 'post_type' => $post_type, |
116 ); |
134 ); |
117 |
135 |
118 $_comments = get_comments( $args ); |
136 $_comments = get_comments( $args ); |
119 |
137 if ( is_array( $_comments ) ) { |
120 update_comment_cache( $_comments ); |
138 update_comment_cache( $_comments ); |
121 |
139 |
122 $this->items = array_slice( $_comments, 0, $comments_per_page ); |
140 $this->items = array_slice( $_comments, 0, $comments_per_page ); |
123 $this->extra_items = array_slice( $_comments, $comments_per_page ); |
141 $this->extra_items = array_slice( $_comments, $comments_per_page ); |
124 |
142 |
125 $total_comments = get_comments( array_merge( $args, array('count' => true, 'offset' => 0, 'number' => 0) ) ); |
143 $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) ); |
126 |
144 |
127 $_comment_post_ids = array(); |
145 $this->pending_count = get_pending_comments_num( $_comment_post_ids ); |
128 foreach ( $_comments as $_c ) { |
146 } |
129 $_comment_post_ids[] = $_c->comment_post_ID; |
147 |
130 } |
148 $total_comments = get_comments( array_merge( $args, array( |
131 |
149 'count' => true, |
132 $_comment_post_ids = array_unique( $_comment_post_ids ); |
150 'offset' => 0, |
133 |
151 'number' => 0 |
134 $this->pending_count = get_pending_comments_num( $_comment_post_ids ); |
152 ) ) ); |
135 |
153 |
136 $this->set_pagination_args( array( |
154 $this->set_pagination_args( array( |
137 'total_items' => $total_comments, |
155 'total_items' => $total_comments, |
138 'per_page' => $comments_per_page, |
156 'per_page' => $comments_per_page, |
139 ) ); |
157 ) ); |
140 } |
158 } |
141 |
159 |
|
160 /** |
|
161 * |
|
162 * @param string $comment_status |
|
163 * @return int |
|
164 */ |
142 public function get_per_page( $comment_status = 'all' ) { |
165 public function get_per_page( $comment_status = 'all' ) { |
143 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' ); |
166 $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' ); |
144 /** |
167 /** |
145 * Filter the number of comments listed per page in the comments list table. |
168 * Filters the number of comments listed per page in the comments list table. |
146 * |
169 * |
147 * @since 2.6.0 |
170 * @since 2.6.0 |
148 * |
171 * |
149 * @param int $comments_per_page The number of comments to list per page. |
172 * @param int $comments_per_page The number of comments to list per page. |
150 * @param string $comment_status The comment status name. Default 'All'. |
173 * @param string $comment_status The comment status name. Default 'All'. |
151 */ |
174 */ |
152 $comments_per_page = apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); |
175 return apply_filters( 'comments_per_page', $comments_per_page, $comment_status ); |
153 return $comments_per_page; |
176 } |
154 } |
177 |
155 |
178 /** |
|
179 * |
|
180 * @global string $comment_status |
|
181 */ |
156 public function no_items() { |
182 public function no_items() { |
157 global $comment_status; |
183 global $comment_status; |
158 |
184 |
159 if ( 'moderated' == $comment_status ) |
185 if ( 'moderated' === $comment_status ) { |
160 _e( 'No comments awaiting moderation.' ); |
186 _e( 'No comments awaiting moderation.' ); |
161 else |
187 } else { |
162 _e( 'No comments found.' ); |
188 _e( 'No comments found.' ); |
163 } |
189 } |
164 |
190 } |
|
191 |
|
192 /** |
|
193 * |
|
194 * @global int $post_id |
|
195 * @global string $comment_status |
|
196 * @global string $comment_type |
|
197 */ |
165 protected function get_views() { |
198 protected function get_views() { |
166 global $post_id, $comment_status, $comment_type; |
199 global $post_id, $comment_status, $comment_type; |
167 |
200 |
168 $status_links = array(); |
201 $status_links = array(); |
169 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); |
202 $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments(); |
170 //, number_format_i18n($num_comments->moderated) ), "<span class='comment-count'>" . number_format_i18n($num_comments->moderated) . "</span>"), |
203 |
171 //, number_format_i18n($num_comments->spam) ), "<span class='spam-comment-count'>" . number_format_i18n($num_comments->spam) . "</span>") |
|
172 $stati = array( |
204 $stati = array( |
173 'all' => _nx_noop('All', 'All', 'comments'), // singular not used |
205 /* translators: %s: all comments count */ |
174 '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>'), |
206 'all' => _nx_noop( |
175 'approved' => _n_noop('Approved', 'Approved'), // singular not used |
207 'All <span class="count">(%s)</span>', |
176 '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>'), |
208 'All <span class="count">(%s)</span>', |
177 '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>') |
209 'comments' |
178 ); |
210 ), // singular not used |
|
211 |
|
212 /* translators: %s: pending comments count */ |
|
213 'moderated' => _nx_noop( |
|
214 'Pending <span class="count">(%s)</span>', |
|
215 'Pending <span class="count">(%s)</span>', |
|
216 'comments' |
|
217 ), |
|
218 |
|
219 /* translators: %s: approved comments count */ |
|
220 'approved' => _nx_noop( |
|
221 'Approved <span class="count">(%s)</span>', |
|
222 'Approved <span class="count">(%s)</span>', |
|
223 'comments' |
|
224 ), |
|
225 |
|
226 /* translators: %s: spam comments count */ |
|
227 'spam' => _nx_noop( |
|
228 'Spam <span class="count">(%s)</span>', |
|
229 'Spam <span class="count">(%s)</span>', |
|
230 'comments' |
|
231 ), |
|
232 |
|
233 /* translators: %s: trashed comments count */ |
|
234 'trash' => _nx_noop( |
|
235 'Trash <span class="count">(%s)</span>', |
|
236 'Trash <span class="count">(%s)</span>', |
|
237 'comments' |
|
238 ) |
|
239 ); |
179 |
240 |
180 if ( !EMPTY_TRASH_DAYS ) |
241 if ( !EMPTY_TRASH_DAYS ) |
181 unset($stati['trash']); |
242 unset($stati['trash']); |
182 |
243 |
183 $link = 'edit-comments.php'; |
244 $link = admin_url( 'edit-comments.php' ); |
184 if ( !empty($comment_type) && 'all' != $comment_type ) |
245 if ( !empty($comment_type) && 'all' != $comment_type ) |
185 $link = add_query_arg( 'comment_type', $comment_type, $link ); |
246 $link = add_query_arg( 'comment_type', $comment_type, $link ); |
186 |
247 |
187 foreach ( $stati as $status => $label ) { |
248 foreach ( $stati as $status => $label ) { |
188 $class = ( $status == $comment_status ) ? ' class="current"' : ''; |
249 $current_link_attributes = ''; |
|
250 |
|
251 if ( $status === $comment_status ) { |
|
252 $current_link_attributes = ' class="current" aria-current="page"'; |
|
253 } |
189 |
254 |
190 if ( !isset( $num_comments->$status ) ) |
255 if ( !isset( $num_comments->$status ) ) |
191 $num_comments->$status = 10; |
256 $num_comments->$status = 10; |
192 $link = add_query_arg( 'comment_status', $status, $link ); |
257 $link = add_query_arg( 'comment_status', $status, $link ); |
193 if ( $post_id ) |
258 if ( $post_id ) |
195 /* |
260 /* |
196 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
261 // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark |
197 if ( !empty( $_REQUEST['s'] ) ) |
262 if ( !empty( $_REQUEST['s'] ) ) |
198 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
263 $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link ); |
199 */ |
264 */ |
200 $status_links[$status] = "<a href='$link'$class>" . sprintf( |
265 $status_links[ $status ] = "<a href='$link'$current_link_attributes>" . sprintf( |
201 translate_nooped_plural( $label, $num_comments->$status ), |
266 translate_nooped_plural( $label, $num_comments->$status ), |
202 number_format_i18n( $num_comments->$status ) |
267 sprintf( '<span class="%s-count">%s</span>', |
|
268 ( 'moderated' === $status ) ? 'pending' : $status, |
|
269 number_format_i18n( $num_comments->$status ) |
|
270 ) |
203 ) . '</a>'; |
271 ) . '</a>'; |
204 } |
272 } |
205 |
273 |
206 /** |
274 /** |
207 * Filter the comment status links. |
275 * Filters the comment status links. |
208 * |
276 * |
209 * @since 2.5.0 |
277 * @since 2.5.0 |
210 * |
278 * |
211 * @param array $status_links An array of fully-formed status links. Default 'All'. |
279 * @param array $status_links An array of fully-formed status links. Default 'All'. |
212 * Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'. |
280 * Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'. |
213 */ |
281 */ |
214 $status_links = apply_filters( 'comment_status_links', $status_links ); |
282 return apply_filters( 'comment_status_links', $status_links ); |
215 return $status_links; |
283 } |
216 } |
284 |
217 |
285 /** |
|
286 * |
|
287 * @global string $comment_status |
|
288 * |
|
289 * @return array |
|
290 */ |
218 protected function get_bulk_actions() { |
291 protected function get_bulk_actions() { |
219 global $comment_status; |
292 global $comment_status; |
220 |
293 |
221 $actions = array(); |
294 $actions = array(); |
222 if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) |
295 if ( in_array( $comment_status, array( 'all', 'approved' ) ) ) |
224 if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) |
297 if ( in_array( $comment_status, array( 'all', 'moderated' ) ) ) |
225 $actions['approve'] = __( 'Approve' ); |
298 $actions['approve'] = __( 'Approve' ); |
226 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) |
299 if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) ) |
227 $actions['spam'] = _x( 'Mark as Spam', 'comment' ); |
300 $actions['spam'] = _x( 'Mark as Spam', 'comment' ); |
228 |
301 |
229 if ( 'trash' == $comment_status ) |
302 if ( 'trash' === $comment_status ) { |
230 $actions['untrash'] = __( 'Restore' ); |
303 $actions['untrash'] = __( 'Restore' ); |
231 elseif ( 'spam' == $comment_status ) |
304 } elseif ( 'spam' === $comment_status ) { |
232 $actions['unspam'] = _x( 'Not Spam', 'comment' ); |
305 $actions['unspam'] = _x( 'Not Spam', 'comment' ); |
|
306 } |
233 |
307 |
234 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS ) |
308 if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS ) |
235 $actions['delete'] = __( 'Delete Permanently' ); |
309 $actions['delete'] = __( 'Delete Permanently' ); |
236 else |
310 else |
237 $actions['trash'] = __( 'Move to Trash' ); |
311 $actions['trash'] = __( 'Move to Trash' ); |
238 |
312 |
239 return $actions; |
313 return $actions; |
240 } |
314 } |
241 |
315 |
|
316 /** |
|
317 * |
|
318 * @global string $comment_status |
|
319 * @global string $comment_type |
|
320 * |
|
321 * @param string $which |
|
322 */ |
242 protected function extra_tablenav( $which ) { |
323 protected function extra_tablenav( $which ) { |
243 global $comment_status, $comment_type; |
324 global $comment_status, $comment_type; |
|
325 static $has_items; |
|
326 |
|
327 if ( ! isset( $has_items ) ) { |
|
328 $has_items = $this->has_items(); |
|
329 } |
244 ?> |
330 ?> |
245 <div class="alignleft actions"> |
331 <div class="alignleft actions"> |
246 <?php |
332 <?php |
247 if ( 'top' == $which ) { |
333 if ( 'top' === $which ) { |
248 ?> |
334 ?> |
249 <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label> |
335 <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label> |
250 <select id="filter-by-comment-type" name="comment_type"> |
336 <select id="filter-by-comment-type" name="comment_type"> |
251 <option value=""><?php _e( 'All comment types' ); ?></option> |
337 <option value=""><?php _e( 'All comment types' ); ?></option> |
252 <?php |
338 <?php |
253 /** |
339 /** |
254 * Filter the comment types dropdown menu. |
340 * Filters the comment types dropdown menu. |
255 * |
341 * |
256 * @since 2.7.0 |
342 * @since 2.7.0 |
257 * |
343 * |
258 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. |
344 * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'. |
259 */ |
345 */ |
354 <?php |
476 <?php |
355 |
477 |
356 $this->display_tablenav( 'bottom' ); |
478 $this->display_tablenav( 'bottom' ); |
357 } |
479 } |
358 |
480 |
359 public function single_row( $a_comment ) { |
481 /** |
|
482 * @global WP_Post $post |
|
483 * @global WP_Comment $comment |
|
484 * |
|
485 * @param WP_Comment $item |
|
486 */ |
|
487 public function single_row( $item ) { |
360 global $post, $comment; |
488 global $post, $comment; |
361 |
489 |
362 $comment = $a_comment; |
490 $comment = $item; |
363 $the_comment_class = wp_get_comment_status( $comment->comment_ID ); |
491 |
|
492 $the_comment_class = wp_get_comment_status( $comment ); |
364 if ( ! $the_comment_class ) { |
493 if ( ! $the_comment_class ) { |
365 $the_comment_class = ''; |
494 $the_comment_class = ''; |
366 } |
495 } |
367 $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment->comment_ID, $comment->comment_post_ID ) ); |
496 $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) ); |
368 |
497 |
369 $post = get_post( $comment->comment_post_ID ); |
498 if ( $comment->comment_post_ID > 0 ) { |
370 |
499 $post = get_post( $comment->comment_post_ID ); |
|
500 } |
371 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); |
501 $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); |
372 |
502 |
373 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; |
503 echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>"; |
374 $this->single_row_columns( $comment ); |
504 $this->single_row_columns( $comment ); |
375 echo "</tr>\n"; |
505 echo "</tr>\n"; |
376 } |
506 |
377 |
507 unset( $GLOBALS['post'], $GLOBALS['comment'] ); |
|
508 } |
|
509 |
|
510 /** |
|
511 * Generate and display row actions links. |
|
512 * |
|
513 * @since 4.3.0 |
|
514 * |
|
515 * @global string $comment_status Status for the current listed comments. |
|
516 * |
|
517 * @param WP_Comment $comment The comment object. |
|
518 * @param string $column_name Current column name. |
|
519 * @param string $primary Primary column name. |
|
520 * @return string|void Comment row actions output. |
|
521 */ |
|
522 protected function handle_row_actions( $comment, $column_name, $primary ) { |
|
523 global $comment_status; |
|
524 |
|
525 if ( $primary !== $column_name ) { |
|
526 return ''; |
|
527 } |
|
528 |
|
529 if ( ! $this->user_can ) { |
|
530 return; |
|
531 } |
|
532 |
|
533 $the_comment_status = wp_get_comment_status( $comment ); |
|
534 |
|
535 $out = ''; |
|
536 |
|
537 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); |
|
538 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); |
|
539 |
|
540 $url = "comment.php?c=$comment->comment_ID"; |
|
541 |
|
542 $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" ); |
|
543 $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" ); |
|
544 $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" ); |
|
545 $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" ); |
|
546 $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" ); |
|
547 $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" ); |
|
548 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); |
|
549 |
|
550 // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash. |
|
551 $actions = array( |
|
552 'approve' => '', 'unapprove' => '', |
|
553 'reply' => '', |
|
554 'quickedit' => '', |
|
555 'edit' => '', |
|
556 'spam' => '', 'unspam' => '', |
|
557 'trash' => '', 'untrash' => '', 'delete' => '' |
|
558 ); |
|
559 |
|
560 // Not looking at all comments. |
|
561 if ( $comment_status && 'all' != $comment_status ) { |
|
562 if ( 'approved' === $the_comment_status ) { |
|
563 $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' class='vim-u vim-destructive' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; |
|
564 } elseif ( 'unapproved' === $the_comment_status ) { |
|
565 $actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; |
|
566 } |
|
567 } else { |
|
568 $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' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; |
|
569 $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' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; |
|
570 } |
|
571 |
|
572 if ( 'spam' !== $the_comment_status ) { |
|
573 $actions['spam'] = "<a href='$spam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; |
|
574 } elseif ( 'spam' === $the_comment_status ) { |
|
575 $actions['unspam'] = "<a href='$unspam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the spam' ) . "'>" . _x( 'Not Spam', 'comment' ) . '</a>'; |
|
576 } |
|
577 |
|
578 if ( 'trash' === $the_comment_status ) { |
|
579 $actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the Trash' ) . "'>" . __( 'Restore' ) . '</a>'; |
|
580 } |
|
581 |
|
582 if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || !EMPTY_TRASH_DAYS ) { |
|
583 $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>'; |
|
584 } else { |
|
585 $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' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>'; |
|
586 } |
|
587 |
|
588 if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) { |
|
589 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>'; |
|
590 |
|
591 $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" aria-label="%s" href="#">%s</a>'; |
|
592 |
|
593 $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline', esc_attr__( 'Quick edit this comment inline' ), __( 'Quick Edit' ) ); |
|
594 |
|
595 $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) ); |
|
596 } |
|
597 |
|
598 /** This filter is documented in wp-admin/includes/dashboard.php */ |
|
599 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); |
|
600 |
|
601 $i = 0; |
|
602 $out .= '<div class="row-actions">'; |
|
603 foreach ( $actions as $action => $link ) { |
|
604 ++$i; |
|
605 ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; |
|
606 |
|
607 // Reply and quickedit need a hide-if-no-js span when not added with ajax |
|
608 if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) |
|
609 $action .= ' hide-if-no-js'; |
|
610 elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) { |
|
611 if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) |
|
612 $action .= ' approve'; |
|
613 else |
|
614 $action .= ' unapprove'; |
|
615 } |
|
616 |
|
617 $out .= "<span class='$action'>$sep$link</span>"; |
|
618 } |
|
619 $out .= '</div>'; |
|
620 |
|
621 $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>'; |
|
622 |
|
623 return $out; |
|
624 } |
|
625 |
|
626 /** |
|
627 * |
|
628 * @param WP_Comment $comment The comment object. |
|
629 */ |
378 public function column_cb( $comment ) { |
630 public function column_cb( $comment ) { |
379 if ( $this->user_can ) { ?> |
631 if ( $this->user_can ) { ?> |
380 <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label> |
632 <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label> |
381 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> |
633 <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" /> |
382 <?php |
634 <?php |
383 } |
635 } |
384 } |
636 } |
385 |
637 |
|
638 /** |
|
639 * @param WP_Comment $comment The comment object. |
|
640 */ |
386 public function column_comment( $comment ) { |
641 public function column_comment( $comment ) { |
387 global $comment_status; |
|
388 $post = get_post(); |
|
389 |
|
390 $comment_url = esc_url( get_comment_link( $comment->comment_ID ) ); |
|
391 $the_comment_status = wp_get_comment_status( $comment->comment_ID ); |
|
392 |
|
393 if ( $this->user_can ) { |
|
394 $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); |
|
395 $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); |
|
396 |
|
397 $url = "comment.php?c=$comment->comment_ID"; |
|
398 |
|
399 $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" ); |
|
400 $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" ); |
|
401 $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" ); |
|
402 $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" ); |
|
403 $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" ); |
|
404 $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" ); |
|
405 $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); |
|
406 } |
|
407 |
|
408 echo '<div class="comment-author">'; |
642 echo '<div class="comment-author">'; |
409 $this->column_author( $comment ); |
643 $this->column_author( $comment ); |
410 echo '</div>'; |
644 echo '</div>'; |
411 |
645 |
412 echo '<div class="submitted-on">'; |
|
413 /* translators: 2: comment date, 3: comment time */ |
|
414 printf( __( 'Submitted on <a href="%1$s">%2$s at %3$s</a>' ), $comment_url, |
|
415 /* translators: comment date format. See http://php.net/date */ |
|
416 get_comment_date( __( 'Y/m/d' ) ), |
|
417 get_comment_date( get_option( 'time_format' ) ) |
|
418 ); |
|
419 |
|
420 if ( $comment->comment_parent ) { |
646 if ( $comment->comment_parent ) { |
421 $parent = get_comment( $comment->comment_parent ); |
647 $parent = get_comment( $comment->comment_parent ); |
422 $parent_link = esc_url( get_comment_link( $comment->comment_parent ) ); |
648 if ( $parent ) { |
423 $name = get_comment_author( $parent->comment_ID ); |
649 $parent_link = esc_url( get_comment_link( $parent ) ); |
424 printf( ' | '.__( 'In reply to <a href="%1$s">%2$s</a>.' ), $parent_link, $name ); |
650 $name = get_comment_author( $parent ); |
425 } |
651 printf( |
426 |
652 /* translators: %s: comment link */ |
427 echo '</div>'; |
653 __( 'In reply to %s.' ), |
428 comment_text(); |
654 '<a href="' . $parent_link . '">' . $name . '</a>' |
|
655 ); |
|
656 } |
|
657 } |
|
658 |
|
659 comment_text( $comment ); |
429 if ( $this->user_can ) { ?> |
660 if ( $this->user_can ) { ?> |
430 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> |
661 <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden"> |
431 <textarea class="comment" rows="1" cols="1"><?php |
662 <textarea class="comment" rows="1" cols="1"><?php |
432 /** This filter is documented in wp-admin/includes/comment.php */ |
663 /** This filter is documented in wp-admin/includes/comment.php */ |
433 echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); |
664 echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) ); |
437 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div> |
668 <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div> |
438 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> |
669 <div class="comment_status"><?php echo $comment->comment_approved; ?></div> |
439 </div> |
670 </div> |
440 <?php |
671 <?php |
441 } |
672 } |
442 |
673 } |
443 if ( $this->user_can ) { |
674 |
444 // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash. |
675 /** |
445 $actions = array( |
676 * |
446 'approve' => '', 'unapprove' => '', |
677 * @global string $comment_status |
447 'reply' => '', |
678 * |
448 'quickedit' => '', |
679 * @param WP_Comment $comment The comment object. |
449 'edit' => '', |
680 */ |
450 'spam' => '', 'unspam' => '', |
|
451 'trash' => '', 'untrash' => '', 'delete' => '' |
|
452 ); |
|
453 |
|
454 // Not looking at all comments. |
|
455 if ( $comment_status && 'all' != $comment_status ) { |
|
456 if ( 'approved' == $the_comment_status ) { |
|
457 $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' class='vim-u vim-destructive' title='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; |
|
458 } elseif ( 'unapproved' == $the_comment_status ) { |
|
459 $actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' class='vim-a vim-destructive' title='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; |
|
460 } |
|
461 } else { |
|
462 $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>'; |
|
463 $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>'; |
|
464 } |
|
465 |
|
466 if ( 'spam' != $the_comment_status ) { |
|
467 $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>'; |
|
468 } elseif ( 'spam' == $the_comment_status ) { |
|
469 $actions['unspam'] = "<a href='$unspam_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' class='vim-z vim-destructive'>" . _x( 'Not Spam', 'comment' ) . '</a>'; |
|
470 } |
|
471 |
|
472 if ( 'trash' == $the_comment_status ) { |
|
473 $actions['untrash'] = "<a href='$untrash_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' class='vim-z vim-destructive'>" . __( 'Restore' ) . '</a>'; |
|
474 } |
|
475 |
|
476 if ( 'spam' == $the_comment_status || 'trash' == $the_comment_status || !EMPTY_TRASH_DAYS ) { |
|
477 $actions['delete'] = "<a href='$delete_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive'>" . __( 'Delete Permanently' ) . '</a>'; |
|
478 } else { |
|
479 $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>'; |
|
480 } |
|
481 |
|
482 if ( 'spam' != $the_comment_status && 'trash' != $the_comment_status ) { |
|
483 $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' title='" . esc_attr__( 'Edit comment' ) . "'>". __( 'Edit' ) . '</a>'; |
|
484 |
|
485 $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" title="%s" href="#">%s</a>'; |
|
486 |
|
487 $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $post->ID, 'edit', 'vim-q comment-inline',esc_attr__( 'Edit this item inline' ), __( 'Quick Edit' ) ); |
|
488 |
|
489 $actions['reply'] = sprintf( $format, $comment->comment_ID, $post->ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) ); |
|
490 } |
|
491 |
|
492 /** This filter is documented in wp-admin/includes/dashboard.php */ |
|
493 $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); |
|
494 |
|
495 $i = 0; |
|
496 echo '<div class="row-actions">'; |
|
497 foreach ( $actions as $action => $link ) { |
|
498 ++$i; |
|
499 ( ( ( 'approve' == $action || 'unapprove' == $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; |
|
500 |
|
501 // Reply and quickedit need a hide-if-no-js span when not added with ajax |
|
502 if ( ( 'reply' == $action || 'quickedit' == $action ) && ! defined('DOING_AJAX') ) |
|
503 $action .= ' hide-if-no-js'; |
|
504 elseif ( ( $action == 'untrash' && $the_comment_status == 'trash' ) || ( $action == 'unspam' && $the_comment_status == 'spam' ) ) { |
|
505 if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) |
|
506 $action .= ' approve'; |
|
507 else |
|
508 $action .= ' unapprove'; |
|
509 } |
|
510 |
|
511 echo "<span class='$action'>$sep$link</span>"; |
|
512 } |
|
513 echo '</div>'; |
|
514 } |
|
515 } |
|
516 |
|
517 public function column_author( $comment ) { |
681 public function column_author( $comment ) { |
518 global $comment_status; |
682 global $comment_status; |
519 |
683 |
520 $author_url = get_comment_author_url(); |
684 $author_url = get_comment_author_url( $comment ); |
521 if ( 'http://' == $author_url ) |
685 |
522 $author_url = ''; |
686 $author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) ); |
523 $author_url_display = preg_replace( '|http://(www\.)?|i', '', $author_url ); |
687 if ( strlen( $author_url_display ) > 50 ) { |
524 if ( strlen( $author_url_display ) > 50 ) |
688 $author_url_display = wp_html_excerpt( $author_url_display, 49, '…' ); |
525 $author_url_display = substr( $author_url_display, 0, 49 ) . '…'; |
689 } |
526 |
690 |
527 echo "<strong>"; comment_author(); echo '</strong><br />'; |
691 echo "<strong>"; comment_author( $comment ); echo '</strong><br />'; |
528 if ( !empty( $author_url ) ) |
692 if ( ! empty( $author_url_display ) ) { |
529 echo "<a title='$author_url' href='$author_url'>$author_url_display</a><br />"; |
693 printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) ); |
|
694 } |
530 |
695 |
531 if ( $this->user_can ) { |
696 if ( $this->user_can ) { |
532 if ( !empty( $comment->comment_author_email ) ) { |
697 if ( ! empty( $comment->comment_author_email ) ) { |
533 comment_author_email_link(); |
698 /** This filter is documented in wp-includes/comment-template.php */ |
534 echo '<br />'; |
699 $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment ); |
|
700 |
|
701 if ( ! empty( $email ) && '@' !== $email ) { |
|
702 printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) ); |
|
703 } |
535 } |
704 } |
536 |
705 |
537 $author_ip = get_comment_author_IP(); |
706 $author_ip = get_comment_author_IP( $comment ); |
538 if ( $author_ip ) { |
707 if ( $author_ip ) { |
539 $author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), 'edit-comments.php' ); |
708 $author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), admin_url( 'edit-comments.php' ) ); |
540 if ( 'spam' == $comment_status ) { |
709 if ( 'spam' === $comment_status ) { |
541 $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url ); |
710 $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url ); |
542 } |
711 } |
543 printf( '<a href="%s">%s</a>', esc_url( $author_ip_url ), $author_ip ); |
712 printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) ); |
544 } |
713 } |
545 } |
714 } |
546 } |
715 } |
547 |
716 |
548 public function column_date() { |
717 /** |
549 return get_comment_date( __( 'Y/m/d \a\t g:i a' ) ); |
718 * |
550 } |
719 * @param WP_Comment $comment The comment object. |
551 |
720 */ |
552 public function column_response() { |
721 public function column_date( $comment ) { |
|
722 /* translators: 1: comment date, 2: comment time */ |
|
723 $submitted = sprintf( __( '%1$s at %2$s' ), |
|
724 /* translators: comment date format. See https://secure.php.net/date */ |
|
725 get_comment_date( __( 'Y/m/d' ), $comment ), |
|
726 get_comment_date( __( 'g:i a' ), $comment ) |
|
727 ); |
|
728 |
|
729 echo '<div class="submitted-on">'; |
|
730 if ( 'approved' === wp_get_comment_status( $comment ) && ! empty ( $comment->comment_post_ID ) ) { |
|
731 printf( |
|
732 '<a href="%s">%s</a>', |
|
733 esc_url( get_comment_link( $comment ) ), |
|
734 $submitted |
|
735 ); |
|
736 } else { |
|
737 echo $submitted; |
|
738 } |
|
739 echo '</div>'; |
|
740 } |
|
741 |
|
742 /** |
|
743 * |
|
744 * @param WP_Comment $comment The comment object. |
|
745 */ |
|
746 public function column_response( $comment ) { |
553 $post = get_post(); |
747 $post = get_post(); |
|
748 |
|
749 if ( ! $post ) { |
|
750 return; |
|
751 } |
554 |
752 |
555 if ( isset( $this->pending_count[$post->ID] ) ) { |
753 if ( isset( $this->pending_count[$post->ID] ) ) { |
556 $pending_comments = $this->pending_count[$post->ID]; |
754 $pending_comments = $this->pending_count[$post->ID]; |
557 } else { |
755 } else { |
558 $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); |
756 $_pending_count_temp = get_pending_comments_num( array( $post->ID ) ); |
559 $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; |
757 $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID]; |
560 } |
758 } |
561 |
759 |
562 if ( current_user_can( 'edit_post', $post->ID ) ) { |
760 if ( current_user_can( 'edit_post', $post->ID ) ) { |
563 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "'>"; |
761 $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>"; |
564 $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>'; |
762 $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>'; |
565 } else { |
763 } else { |
566 $post_link = esc_html( get_the_title( $post->ID ) ); |
764 $post_link = esc_html( get_the_title( $post->ID ) ); |
567 } |
765 } |
568 |
766 |
569 echo '<div class="response-links"><span class="post-com-count-wrapper">'; |
767 echo '<div class="response-links">'; |
570 echo $post_link . '<br />'; |
768 if ( 'attachment' === $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) { |
|
769 echo $thumb; |
|
770 } |
|
771 echo $post_link; |
|
772 $post_type_object = get_post_type_object( $post->post_type ); |
|
773 echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>'; |
|
774 echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">'; |
571 $this->comments_bubble( $post->ID, $pending_comments ); |
775 $this->comments_bubble( $post->ID, $pending_comments ); |
572 echo '</span> '; |
776 echo '</span> '; |
573 $post_type_object = get_post_type_object( $post->post_type ); |
|
574 echo "<a href='" . get_permalink( $post->ID ) . "'>" . $post_type_object->labels->view_item . '</a>'; |
|
575 echo '</div>'; |
777 echo '</div>'; |
576 if ( 'attachment' == $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) |
778 } |
577 echo $thumb; |
779 |
578 } |
780 /** |
579 |
781 * |
|
782 * @param WP_Comment $comment The comment object. |
|
783 * @param string $column_name The custom column's name. |
|
784 */ |
580 public function column_default( $comment, $column_name ) { |
785 public function column_default( $comment, $column_name ) { |
581 /** |
786 /** |
582 * Fires when the default column output is displayed for a single row. |
787 * Fires when the default column output is displayed for a single row. |
583 * |
788 * |
584 * @since 2.8.0 |
789 * @since 2.8.0 |