選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

794 行
25 KiB

  1. <?php
  2. /**
  3. * List Table API: WP_Comments_List_Table class
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. * @since 3.1.0
  8. */
  9. /**
  10. * Core class used to implement displaying comments in a list table.
  11. *
  12. * @since 3.1.0
  13. * @access private
  14. *
  15. * @see WP_List_Table
  16. */
  17. class WP_Comments_List_Table extends WP_List_Table {
  18. public $checkbox = true;
  19. public $pending_count = array();
  20. public $extra_items;
  21. private $user_can;
  22. /**
  23. * Constructor.
  24. *
  25. * @since 3.1.0
  26. * @access public
  27. *
  28. * @see WP_List_Table::__construct() for more information on default arguments.
  29. *
  30. * @global int $post_id
  31. *
  32. * @param array $args An associative array of arguments.
  33. */
  34. public function __construct( $args = array() ) {
  35. global $post_id;
  36. $post_id = isset( $_REQUEST['p'] ) ? absint( $_REQUEST['p'] ) : 0;
  37. if ( get_option( 'show_avatars' ) ) {
  38. add_filter( 'comment_author', array( $this, 'floated_admin_avatar' ), 10, 2 );
  39. }
  40. parent::__construct( array(
  41. 'plural' => 'comments',
  42. 'singular' => 'comment',
  43. 'ajax' => true,
  44. 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
  45. ) );
  46. }
  47. public function floated_admin_avatar( $name, $comment_ID ) {
  48. $comment = get_comment( $comment_ID );
  49. $avatar = get_avatar( $comment, 32, 'mystery' );
  50. return "$avatar $name";
  51. }
  52. /**
  53. * @return bool
  54. */
  55. public function ajax_user_can() {
  56. return current_user_can('edit_posts');
  57. }
  58. /**
  59. *
  60. * @global int $post_id
  61. * @global string $comment_status
  62. * @global string $search
  63. * @global string $comment_type
  64. */
  65. public function prepare_items() {
  66. global $post_id, $comment_status, $search, $comment_type;
  67. $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
  68. if ( !in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) )
  69. $comment_status = 'all';
  70. $comment_type = !empty( $_REQUEST['comment_type'] ) ? $_REQUEST['comment_type'] : '';
  71. $search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : '';
  72. $post_type = ( isset( $_REQUEST['post_type'] ) ) ? sanitize_key( $_REQUEST['post_type'] ) : '';
  73. $user_id = ( isset( $_REQUEST['user_id'] ) ) ? $_REQUEST['user_id'] : '';
  74. $orderby = ( isset( $_REQUEST['orderby'] ) ) ? $_REQUEST['orderby'] : '';
  75. $order = ( isset( $_REQUEST['order'] ) ) ? $_REQUEST['order'] : '';
  76. $comments_per_page = $this->get_per_page( $comment_status );
  77. $doing_ajax = wp_doing_ajax();
  78. if ( isset( $_REQUEST['number'] ) ) {
  79. $number = (int) $_REQUEST['number'];
  80. }
  81. else {
  82. $number = $comments_per_page + min( 8, $comments_per_page ); // Grab a few extra
  83. }
  84. $page = $this->get_pagenum();
  85. if ( isset( $_REQUEST['start'] ) ) {
  86. $start = $_REQUEST['start'];
  87. } else {
  88. $start = ( $page - 1 ) * $comments_per_page;
  89. }
  90. if ( $doing_ajax && isset( $_REQUEST['offset'] ) ) {
  91. $start += $_REQUEST['offset'];
  92. }
  93. $status_map = array(
  94. 'moderated' => 'hold',
  95. 'approved' => 'approve',
  96. 'all' => '',
  97. );
  98. $args = array(
  99. 'status' => isset( $status_map[$comment_status] ) ? $status_map[$comment_status] : $comment_status,
  100. 'search' => $search,
  101. 'user_id' => $user_id,
  102. 'offset' => $start,
  103. 'number' => $number,
  104. 'post_id' => $post_id,
  105. 'type' => $comment_type,
  106. 'orderby' => $orderby,
  107. 'order' => $order,
  108. 'post_type' => $post_type,
  109. );
  110. $_comments = get_comments( $args );
  111. if ( is_array( $_comments ) ) {
  112. update_comment_cache( $_comments );
  113. $this->items = array_slice( $_comments, 0, $comments_per_page );
  114. $this->extra_items = array_slice( $_comments, $comments_per_page );
  115. $_comment_post_ids = array_unique( wp_list_pluck( $_comments, 'comment_post_ID' ) );
  116. $this->pending_count = get_pending_comments_num( $_comment_post_ids );
  117. }
  118. $total_comments = get_comments( array_merge( $args, array(
  119. 'count' => true,
  120. 'offset' => 0,
  121. 'number' => 0
  122. ) ) );
  123. $this->set_pagination_args( array(
  124. 'total_items' => $total_comments,
  125. 'per_page' => $comments_per_page,
  126. ) );
  127. }
  128. /**
  129. *
  130. * @param string $comment_status
  131. * @return int
  132. */
  133. public function get_per_page( $comment_status = 'all' ) {
  134. $comments_per_page = $this->get_items_per_page( 'edit_comments_per_page' );
  135. /**
  136. * Filters the number of comments listed per page in the comments list table.
  137. *
  138. * @since 2.6.0
  139. *
  140. * @param int $comments_per_page The number of comments to list per page.
  141. * @param string $comment_status The comment status name. Default 'All'.
  142. */
  143. return apply_filters( 'comments_per_page', $comments_per_page, $comment_status );
  144. }
  145. /**
  146. *
  147. * @global string $comment_status
  148. */
  149. public function no_items() {
  150. global $comment_status;
  151. if ( 'moderated' === $comment_status ) {
  152. _e( 'No comments awaiting moderation.' );
  153. } else {
  154. _e( 'No comments found.' );
  155. }
  156. }
  157. /**
  158. *
  159. * @global int $post_id
  160. * @global string $comment_status
  161. * @global string $comment_type
  162. */
  163. protected function get_views() {
  164. global $post_id, $comment_status, $comment_type;
  165. $status_links = array();
  166. $num_comments = ( $post_id ) ? wp_count_comments( $post_id ) : wp_count_comments();
  167. $stati = array(
  168. /* translators: %s: all comments count */
  169. 'all' => _nx_noop(
  170. 'All <span class="count">(%s)</span>',
  171. 'All <span class="count">(%s)</span>',
  172. 'comments'
  173. ), // singular not used
  174. /* translators: %s: pending comments count */
  175. 'moderated' => _nx_noop(
  176. 'Pending <span class="count">(%s)</span>',
  177. 'Pending <span class="count">(%s)</span>',
  178. 'comments'
  179. ),
  180. /* translators: %s: approved comments count */
  181. 'approved' => _nx_noop(
  182. 'Approved <span class="count">(%s)</span>',
  183. 'Approved <span class="count">(%s)</span>',
  184. 'comments'
  185. ),
  186. /* translators: %s: spam comments count */
  187. 'spam' => _nx_noop(
  188. 'Spam <span class="count">(%s)</span>',
  189. 'Spam <span class="count">(%s)</span>',
  190. 'comments'
  191. ),
  192. /* translators: %s: trashed comments count */
  193. 'trash' => _nx_noop(
  194. 'Trash <span class="count">(%s)</span>',
  195. 'Trash <span class="count">(%s)</span>',
  196. 'comments'
  197. )
  198. );
  199. if ( !EMPTY_TRASH_DAYS )
  200. unset($stati['trash']);
  201. $link = admin_url( 'edit-comments.php' );
  202. if ( !empty($comment_type) && 'all' != $comment_type )
  203. $link = add_query_arg( 'comment_type', $comment_type, $link );
  204. foreach ( $stati as $status => $label ) {
  205. $class = ( $status === $comment_status ) ? ' class="current"' : '';
  206. if ( !isset( $num_comments->$status ) )
  207. $num_comments->$status = 10;
  208. $link = add_query_arg( 'comment_status', $status, $link );
  209. if ( $post_id )
  210. $link = add_query_arg( 'p', absint( $post_id ), $link );
  211. /*
  212. // I toyed with this, but decided against it. Leaving it in here in case anyone thinks it is a good idea. ~ Mark
  213. if ( !empty( $_REQUEST['s'] ) )
  214. $link = add_query_arg( 's', esc_attr( wp_unslash( $_REQUEST['s'] ) ), $link );
  215. */
  216. $status_links[ $status ] = "<a href='$link'$class>" . sprintf(
  217. translate_nooped_plural( $label, $num_comments->$status ),
  218. sprintf( '<span class="%s-count">%s</span>',
  219. ( 'moderated' === $status ) ? 'pending' : $status,
  220. number_format_i18n( $num_comments->$status )
  221. )
  222. ) . '</a>';
  223. }
  224. /**
  225. * Filters the comment status links.
  226. *
  227. * @since 2.5.0
  228. *
  229. * @param array $status_links An array of fully-formed status links. Default 'All'.
  230. * Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
  231. */
  232. return apply_filters( 'comment_status_links', $status_links );
  233. }
  234. /**
  235. *
  236. * @global string $comment_status
  237. *
  238. * @return array
  239. */
  240. protected function get_bulk_actions() {
  241. global $comment_status;
  242. $actions = array();
  243. if ( in_array( $comment_status, array( 'all', 'approved' ) ) )
  244. $actions['unapprove'] = __( 'Unapprove' );
  245. if ( in_array( $comment_status, array( 'all', 'moderated' ) ) )
  246. $actions['approve'] = __( 'Approve' );
  247. if ( in_array( $comment_status, array( 'all', 'moderated', 'approved', 'trash' ) ) )
  248. $actions['spam'] = _x( 'Mark as Spam', 'comment' );
  249. if ( 'trash' === $comment_status ) {
  250. $actions['untrash'] = __( 'Restore' );
  251. } elseif ( 'spam' === $comment_status ) {
  252. $actions['unspam'] = _x( 'Not Spam', 'comment' );
  253. }
  254. if ( in_array( $comment_status, array( 'trash', 'spam' ) ) || !EMPTY_TRASH_DAYS )
  255. $actions['delete'] = __( 'Delete Permanently' );
  256. else
  257. $actions['trash'] = __( 'Move to Trash' );
  258. return $actions;
  259. }
  260. /**
  261. *
  262. * @global string $comment_status
  263. * @global string $comment_type
  264. *
  265. * @param string $which
  266. */
  267. protected function extra_tablenav( $which ) {
  268. global $comment_status, $comment_type;
  269. ?>
  270. <div class="alignleft actions">
  271. <?php
  272. if ( 'top' === $which ) {
  273. ?>
  274. <label class="screen-reader-text" for="filter-by-comment-type"><?php _e( 'Filter by comment type' ); ?></label>
  275. <select id="filter-by-comment-type" name="comment_type">
  276. <option value=""><?php _e( 'All comment types' ); ?></option>
  277. <?php
  278. /**
  279. * Filters the comment types dropdown menu.
  280. *
  281. * @since 2.7.0
  282. *
  283. * @param array $comment_types An array of comment types. Accepts 'Comments', 'Pings'.
  284. */
  285. $comment_types = apply_filters( 'admin_comment_types_dropdown', array(
  286. 'comment' => __( 'Comments' ),
  287. 'pings' => __( 'Pings' ),
  288. ) );
  289. foreach ( $comment_types as $type => $label )
  290. echo "\t" . '<option value="' . esc_attr( $type ) . '"' . selected( $comment_type, $type, false ) . ">$label</option>\n";
  291. ?>
  292. </select>
  293. <?php
  294. /**
  295. * Fires just before the Filter submit button for comment types.
  296. *
  297. * @since 3.5.0
  298. */
  299. do_action( 'restrict_manage_comments' );
  300. submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) );
  301. }
  302. if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) ) {
  303. wp_nonce_field( 'bulk-destroy', '_destroy_nonce' );
  304. $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' );
  305. submit_button( $title, 'apply', 'delete_all', false );
  306. }
  307. /**
  308. * Fires after the Filter submit button for comment types.
  309. *
  310. * @since 2.5.0
  311. *
  312. * @param string $comment_status The comment status name. Default 'All'.
  313. */
  314. do_action( 'manage_comments_nav', $comment_status );
  315. echo '</div>';
  316. }
  317. /**
  318. * @return string|false
  319. */
  320. public function current_action() {
  321. if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
  322. return 'delete_all';
  323. return parent::current_action();
  324. }
  325. /**
  326. *
  327. * @global int $post_id
  328. *
  329. * @return array
  330. */
  331. public function get_columns() {
  332. global $post_id;
  333. $columns = array();
  334. if ( $this->checkbox )
  335. $columns['cb'] = '<input type="checkbox" />';
  336. $columns['author'] = __( 'Author' );
  337. $columns['comment'] = _x( 'Comment', 'column name' );
  338. if ( ! $post_id ) {
  339. /* translators: column name or table row header */
  340. $columns['response'] = __( 'In Response To' );
  341. }
  342. $columns['date'] = _x( 'Submitted On', 'column name' );
  343. return $columns;
  344. }
  345. /**
  346. *
  347. * @return array
  348. */
  349. protected function get_sortable_columns() {
  350. return array(
  351. 'author' => 'comment_author',
  352. 'response' => 'comment_post_ID',
  353. 'date' => 'comment_date'
  354. );
  355. }
  356. /**
  357. * Get the name of the default primary column.
  358. *
  359. * @since 4.3.0
  360. * @access protected
  361. *
  362. * @return string Name of the default primary column, in this case, 'comment'.
  363. */
  364. protected function get_default_primary_column_name() {
  365. return 'comment';
  366. }
  367. /**
  368. * @access public
  369. */
  370. public function display() {
  371. wp_nonce_field( "fetch-list-" . get_class( $this ), '_ajax_fetch_list_nonce' );
  372. $this->display_tablenav( 'top' );
  373. $this->screen->render_screen_reader_content( 'heading_list' );
  374. ?>
  375. <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
  376. <thead>
  377. <tr>
  378. <?php $this->print_column_headers(); ?>
  379. </tr>
  380. </thead>
  381. <tbody id="the-comment-list" data-wp-lists="list:comment">
  382. <?php $this->display_rows_or_placeholder(); ?>
  383. </tbody>
  384. <tbody id="the-extra-comment-list" data-wp-lists="list:comment" style="display: none;">
  385. <?php
  386. $this->items = $this->extra_items;
  387. $this->display_rows_or_placeholder();
  388. ?>
  389. </tbody>
  390. <tfoot>
  391. <tr>
  392. <?php $this->print_column_headers( false ); ?>
  393. </tr>
  394. </tfoot>
  395. </table>
  396. <?php
  397. $this->display_tablenav( 'bottom' );
  398. }
  399. /**
  400. * @global WP_Post $post
  401. * @global WP_Comment $comment
  402. *
  403. * @param WP_Comment $item
  404. */
  405. public function single_row( $item ) {
  406. global $post, $comment;
  407. $comment = $item;
  408. $the_comment_class = wp_get_comment_status( $comment );
  409. if ( ! $the_comment_class ) {
  410. $the_comment_class = '';
  411. }
  412. $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) );
  413. if ( $comment->comment_post_ID > 0 ) {
  414. $post = get_post( $comment->comment_post_ID );
  415. }
  416. $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID );
  417. echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class'>";
  418. $this->single_row_columns( $comment );
  419. echo "</tr>\n";
  420. unset( $GLOBALS['post'], $GLOBALS['comment'] );
  421. }
  422. /**
  423. * Generate and display row actions links.
  424. *
  425. * @since 4.3.0
  426. * @access protected
  427. *
  428. * @global string $comment_status Status for the current listed comments.
  429. *
  430. * @param WP_Comment $comment The comment object.
  431. * @param string $column_name Current column name.
  432. * @param string $primary Primary column name.
  433. * @return string|void Comment row actions output.
  434. */
  435. protected function handle_row_actions( $comment, $column_name, $primary ) {
  436. global $comment_status;
  437. if ( $primary !== $column_name ) {
  438. return '';
  439. }
  440. if ( ! $this->user_can ) {
  441. return;
  442. }
  443. $the_comment_status = wp_get_comment_status( $comment );
  444. $out = '';
  445. $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) );
  446. $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) );
  447. $url = "comment.php?c=$comment->comment_ID";
  448. $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" );
  449. $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" );
  450. $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" );
  451. $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" );
  452. $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" );
  453. $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" );
  454. $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" );
  455. // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash.
  456. $actions = array(
  457. 'approve' => '', 'unapprove' => '',
  458. 'reply' => '',
  459. 'quickedit' => '',
  460. 'edit' => '',
  461. 'spam' => '', 'unspam' => '',
  462. 'trash' => '', 'untrash' => '', 'delete' => ''
  463. );
  464. // Not looking at all comments.
  465. if ( $comment_status && 'all' != $comment_status ) {
  466. if ( 'approved' === $the_comment_status ) {
  467. $actions['unapprove'] = "<a href='$unapprove_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=unapproved' class='vim-u vim-destructive' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>';
  468. } elseif ( 'unapproved' === $the_comment_status ) {
  469. $actions['approve'] = "<a href='$approve_url' data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&amp;new=approved' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';
  470. }
  471. } else {
  472. $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>';
  473. $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>';
  474. }
  475. if ( 'spam' !== $the_comment_status ) {
  476. $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>';
  477. } elseif ( 'spam' === $the_comment_status ) {
  478. $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>';
  479. }
  480. if ( 'trash' === $the_comment_status ) {
  481. $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>';
  482. }
  483. if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || !EMPTY_TRASH_DAYS ) {
  484. $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>';
  485. } else {
  486. $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>';
  487. }
  488. if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) {
  489. $actions['edit'] = "<a href='comment.php?action=editcomment&amp;c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>';
  490. $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" aria-label="%s" href="#">%s</a>';
  491. $actions['quickedit'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'edit', 'vim-q comment-inline', esc_attr__( 'Quick edit this comment inline' ), __( 'Quick&nbsp;Edit' ) );
  492. $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) );
  493. }
  494. /** This filter is documented in wp-admin/includes/dashboard.php */
  495. $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment );
  496. $i = 0;
  497. $out .= '<div class="row-actions">';
  498. foreach ( $actions as $action => $link ) {
  499. ++$i;
  500. ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | ';
  501. // Reply and quickedit need a hide-if-no-js span when not added with ajax
  502. if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_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. $out .= "<span class='$action'>$sep$link</span>";
  511. }
  512. $out .= '</div>';
  513. $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
  514. return $out;
  515. }
  516. /**
  517. *
  518. * @param WP_Comment $comment The comment object.
  519. */
  520. public function column_cb( $comment ) {
  521. if ( $this->user_can ) { ?>
  522. <label class="screen-reader-text" for="cb-select-<?php echo $comment->comment_ID; ?>"><?php _e( 'Select comment' ); ?></label>
  523. <input id="cb-select-<?php echo $comment->comment_ID; ?>" type="checkbox" name="delete_comments[]" value="<?php echo $comment->comment_ID; ?>" />
  524. <?php
  525. }
  526. }
  527. /**
  528. * @param WP_Comment $comment The comment object.
  529. */
  530. public function column_comment( $comment ) {
  531. echo '<div class="comment-author">';
  532. $this->column_author( $comment );
  533. echo '</div>';
  534. if ( $comment->comment_parent ) {
  535. $parent = get_comment( $comment->comment_parent );
  536. if ( $parent ) {
  537. $parent_link = esc_url( get_comment_link( $parent ) );
  538. $name = get_comment_author( $parent );
  539. printf(
  540. /* translators: %s: comment link */
  541. __( 'In reply to %s.' ),
  542. '<a href="' . $parent_link . '">' . $name . '</a>'
  543. );
  544. }
  545. }
  546. comment_text( $comment );
  547. if ( $this->user_can ) { ?>
  548. <div id="inline-<?php echo $comment->comment_ID; ?>" class="hidden">
  549. <textarea class="comment" rows="1" cols="1"><?php
  550. /** This filter is documented in wp-admin/includes/comment.php */
  551. echo esc_textarea( apply_filters( 'comment_edit_pre', $comment->comment_content ) );
  552. ?></textarea>
  553. <div class="author-email"><?php echo esc_attr( $comment->comment_author_email ); ?></div>
  554. <div class="author"><?php echo esc_attr( $comment->comment_author ); ?></div>
  555. <div class="author-url"><?php echo esc_attr( $comment->comment_author_url ); ?></div>
  556. <div class="comment_status"><?php echo $comment->comment_approved; ?></div>
  557. </div>
  558. <?php
  559. }
  560. }
  561. /**
  562. *
  563. * @global string $comment_status
  564. *
  565. * @param WP_Comment $comment The comment object.
  566. */
  567. public function column_author( $comment ) {
  568. global $comment_status;
  569. $author_url = get_comment_author_url( $comment );
  570. $author_url_display = untrailingslashit( preg_replace( '|^http(s)?://(www\.)?|i', '', $author_url ) );
  571. if ( strlen( $author_url_display ) > 50 ) {
  572. $author_url_display = wp_html_excerpt( $author_url_display, 49, '&hellip;' );
  573. }
  574. echo "<strong>"; comment_author( $comment ); echo '</strong><br />';
  575. if ( ! empty( $author_url_display ) ) {
  576. printf( '<a href="%s">%s</a><br />', esc_url( $author_url ), esc_html( $author_url_display ) );
  577. }
  578. if ( $this->user_can ) {
  579. if ( ! empty( $comment->comment_author_email ) ) {
  580. /* This filter is documented in wp-includes/comment-template.php */
  581. $email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );
  582. if ( ! empty( $email ) && '@' !== $email ) {
  583. printf( '<a href="%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
  584. }
  585. }
  586. $author_ip = get_comment_author_IP( $comment );
  587. if ( $author_ip ) {
  588. $author_ip_url = add_query_arg( array( 's' => $author_ip, 'mode' => 'detail' ), admin_url( 'edit-comments.php' ) );
  589. if ( 'spam' === $comment_status ) {
  590. $author_ip_url = add_query_arg( 'comment_status', 'spam', $author_ip_url );
  591. }
  592. printf( '<a href="%1$s">%2$s</a>', esc_url( $author_ip_url ), esc_html( $author_ip ) );
  593. }
  594. }
  595. }
  596. /**
  597. * @access public
  598. *
  599. * @param WP_Comment $comment The comment object.
  600. */
  601. public function column_date( $comment ) {
  602. /* translators: 1: comment date, 2: comment time */
  603. $submitted = sprintf( __( '%1$s at %2$s' ),
  604. /* translators: comment date format. See https://secure.php.net/date */
  605. get_comment_date( __( 'Y/m/d' ), $comment ),
  606. get_comment_date( __( 'g:i a' ), $comment )
  607. );
  608. echo '<div class="submitted-on">';
  609. if ( 'approved' === wp_get_comment_status( $comment ) && ! empty ( $comment->comment_post_ID ) ) {
  610. printf(
  611. '<a href="%s">%s</a>',
  612. esc_url( get_comment_link( $comment ) ),
  613. $submitted
  614. );
  615. } else {
  616. echo $submitted;
  617. }
  618. echo '</div>';
  619. }
  620. /**
  621. * @access public
  622. *
  623. * @param WP_Comment $comment The comment object.
  624. */
  625. public function column_response( $comment ) {
  626. $post = get_post();
  627. if ( ! $post ) {
  628. return;
  629. }
  630. if ( isset( $this->pending_count[$post->ID] ) ) {
  631. $pending_comments = $this->pending_count[$post->ID];
  632. } else {
  633. $_pending_count_temp = get_pending_comments_num( array( $post->ID ) );
  634. $pending_comments = $this->pending_count[$post->ID] = $_pending_count_temp[$post->ID];
  635. }
  636. if ( current_user_can( 'edit_post', $post->ID ) ) {
  637. $post_link = "<a href='" . get_edit_post_link( $post->ID ) . "' class='comments-edit-item-link'>";
  638. $post_link .= esc_html( get_the_title( $post->ID ) ) . '</a>';
  639. } else {
  640. $post_link = esc_html( get_the_title( $post->ID ) );
  641. }
  642. echo '<div class="response-links">';
  643. if ( 'attachment' === $post->post_type && ( $thumb = wp_get_attachment_image( $post->ID, array( 80, 60 ), true ) ) ) {
  644. echo $thumb;
  645. }
  646. echo $post_link;
  647. $post_type_object = get_post_type_object( $post->post_type );
  648. echo "<a href='" . get_permalink( $post->ID ) . "' class='comments-view-item-link'>" . $post_type_object->labels->view_item . '</a>';
  649. echo '<span class="post-com-count-wrapper post-com-count-', $post->ID, '">';
  650. $this->comments_bubble( $post->ID, $pending_comments );
  651. echo '</span> ';
  652. echo '</div>';
  653. }
  654. /**
  655. *
  656. * @param WP_Comment $comment The comment object.
  657. * @param string $column_name The custom column's name.
  658. */
  659. public function column_default( $comment, $column_name ) {
  660. /**
  661. * Fires when the default column output is displayed for a single row.
  662. *
  663. * @since 2.8.0
  664. *
  665. * @param string $column_name The custom column's name.
  666. * @param int $comment->comment_ID The custom column's unique ID number.
  667. */
  668. do_action( 'manage_comments_custom_column', $column_name, $comment->comment_ID );
  669. }
  670. }