| | 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 | /** |
| | 11 | * Core class used to implement displaying comments in a list table. |
| | 12 | * |
| | 13 | * @since 3.1.0 |
| | 14 | * @access private |
| | 15 | * |
| | 16 | * @see WP_List_Table |
| | 17 | */ |
| | 18 | class WP_Comments_Reactive_List_Table extends WP_Comments_List_Table { |
| | 19 | // Because it's private in WP_Comments_List_Table... |
| | 20 | protected $user_can; |
| | 21 | |
| | 22 | public function get_column_data() { |
| | 23 | list( $columns ) = $this->get_column_info(); |
| | 24 | $data = array(); |
| | 25 | foreach ( $columns as $key => $name ) { |
| | 26 | $data[] = compact( 'key', 'name' ); |
| | 27 | } |
| | 28 | return $data; |
| | 29 | } |
| | 30 | |
| | 31 | /** |
| | 32 | * @global WP_Post $post |
| | 33 | * @global WP_Comment $comment |
| | 34 | * |
| | 35 | * @param WP_Comment $item |
| | 36 | */ |
| | 37 | public function single_row( $item ) { |
| | 38 | // return; |
| | 39 | global $post, $comment; |
| | 40 | |
| | 41 | $comment = $item; |
| | 42 | |
| | 43 | $the_comment_class = wp_get_comment_status( $comment ); |
| | 44 | if ( ! $the_comment_class ) { |
| | 45 | $the_comment_class = ''; |
| | 46 | } |
| | 47 | $the_comment_class = join( ' ', get_comment_class( $the_comment_class, $comment, $comment->comment_post_ID ) ); |
| | 48 | |
| | 49 | if ( $comment->comment_post_ID > 0 ) { |
| | 50 | $post = get_post( $comment->comment_post_ID ); |
| | 51 | } |
| | 52 | $this->user_can = current_user_can( 'edit_comment', $comment->comment_ID ); |
| | 53 | |
| | 54 | echo "<tr id='comment-$comment->comment_ID' class='$the_comment_class' data-comment-id='{$comment->comment_ID}'>"; |
| | 55 | $this->single_row_columns( $comment ); |
| | 56 | echo "</tr>\n"; |
| | 57 | |
| | 58 | unset( $GLOBALS['post'], $GLOBALS['comment'] ); |
| | 59 | } |
| | 60 | |
| | 61 | /** |
| | 62 | * @access public |
| | 63 | */ |
| | 64 | public function display() { |
| | 65 | $this->display_tablenav( 'top' ); |
| | 66 | |
| | 67 | $this->screen->render_screen_reader_content( 'heading_list' ); |
| | 68 | |
| | 69 | ?> |
| | 70 | <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>"> |
| | 71 | <thead> |
| | 72 | <tr> |
| | 73 | <?php $this->print_column_headers(); ?> |
| | 74 | </tr> |
| | 75 | </thead> |
| | 76 | |
| | 77 | <tbody id="the-comment-list"> |
| | 78 | <?php //$this->display_rows_or_placeholder(); ?> |
| | 79 | </tbody> |
| | 80 | |
| | 81 | <tbody id="the-extra-comment-list" style="display: none;"> |
| | 82 | <?php |
| | 83 | // $this->items = $this->extra_items; |
| | 84 | // $this->display_rows_or_placeholder(); |
| | 85 | ?> |
| | 86 | </tbody> |
| | 87 | |
| | 88 | <tfoot> |
| | 89 | <tr> |
| | 90 | <?php $this->print_column_headers( false ); ?> |
| | 91 | </tr> |
| | 92 | </tfoot> |
| | 93 | |
| | 94 | </table> |
| | 95 | <?php |
| | 96 | |
| | 97 | $this->display_tablenav( 'bottom' ); |
| | 98 | } |
| | 99 | |
| | 100 | protected function get_row_actions( $comment ) { |
| | 101 | global $comment_status; |
| | 102 | |
| | 103 | $the_comment_status = wp_get_comment_status( $comment ); |
| | 104 | |
| | 105 | $del_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "delete-comment_$comment->comment_ID" ) ); |
| | 106 | $approve_nonce = esc_html( '_wpnonce=' . wp_create_nonce( "approve-comment_$comment->comment_ID" ) ); |
| | 107 | |
| | 108 | $url = "comment.php?c=$comment->comment_ID"; |
| | 109 | |
| | 110 | $approve_url = esc_url( $url . "&action=approvecomment&$approve_nonce" ); |
| | 111 | $unapprove_url = esc_url( $url . "&action=unapprovecomment&$approve_nonce" ); |
| | 112 | $spam_url = esc_url( $url . "&action=spamcomment&$del_nonce" ); |
| | 113 | $unspam_url = esc_url( $url . "&action=unspamcomment&$del_nonce" ); |
| | 114 | $trash_url = esc_url( $url . "&action=trashcomment&$del_nonce" ); |
| | 115 | $untrash_url = esc_url( $url . "&action=untrashcomment&$del_nonce" ); |
| | 116 | $delete_url = esc_url( $url . "&action=deletecomment&$del_nonce" ); |
| | 117 | |
| | 118 | // Preorder it: Approve | Reply | Quick Edit | Edit | Spam | Trash. |
| | 119 | $actions = array( |
| | 120 | 'approve' => '', 'unapprove' => '', |
| | 121 | 'reply' => '', |
| | 122 | 'quickedit' => '', |
| | 123 | 'edit' => '', |
| | 124 | 'spam' => '', 'unspam' => '', |
| | 125 | 'trash' => '', 'untrash' => '', 'delete' => '' |
| | 126 | ); |
| | 127 | |
| | 128 | // Not looking at all comments. |
| | 129 | if ( $comment_status && 'all' != $comment_status ) { |
| | 130 | if ( 'approved' === $the_comment_status ) { |
| | 131 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=unapproved' |
| | 132 | $actions['unapprove'] = "<a href='$unapprove_url' class='vim-u vim-destructive' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; |
| | 133 | } elseif ( 'unapproved' === $the_comment_status ) { |
| | 134 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:e7e7d3:action=dim-comment&new=approved' |
| | 135 | $actions['approve'] = "<a href='$approve_url' class='vim-a vim-destructive' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; |
| | 136 | } |
| | 137 | } else { |
| | 138 | // data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved' |
| | 139 | $actions['approve'] = "<a href='$approve_url' class='vim-a' aria-label='" . esc_attr__( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>'; |
| | 140 | // data-wp-lists='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=unapproved' |
| | 141 | $actions['unapprove'] = "<a href='$unapprove_url' class='vim-u' aria-label='" . esc_attr__( 'Unapprove this comment' ) . "'>" . __( 'Unapprove' ) . '</a>'; |
| | 142 | } |
| | 143 | |
| | 144 | if ( 'spam' !== $the_comment_status ) { |
| | 145 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::spam=1' class='vim-s vim-destructive' |
| | 146 | $actions['spam'] = "<a href='$spam_url' aria-label='" . esc_attr__( 'Mark this comment as spam' ) . "'>" . /* translators: mark as spam link */ _x( 'Spam', 'verb' ) . '</a>'; |
| | 147 | } elseif ( 'spam' === $the_comment_status ) { |
| | 148 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:unspam=1' |
| | 149 | $actions['unspam'] = "<a href='$unspam_url'class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the spam' ) . "'>" . _x( 'Not Spam', 'comment' ) . '</a>'; |
| | 150 | } |
| | 151 | |
| | 152 | if ( 'trash' === $the_comment_status ) { |
| | 153 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID:66cc66:untrash=1' |
| | 154 | $actions['untrash'] = "<a href='$untrash_url' class='vim-z vim-destructive' aria-label='" . esc_attr__( 'Restore this comment from the Trash' ) . "'>" . __( 'Restore' ) . '</a>'; |
| | 155 | } |
| | 156 | |
| | 157 | if ( 'spam' === $the_comment_status || 'trash' === $the_comment_status || !EMPTY_TRASH_DAYS ) { |
| | 158 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::delete=1' class='delete vim-d vim-destructive' |
| | 159 | $actions['delete'] = "<a href='$delete_url' aria-label='" . esc_attr__( 'Delete this comment permanently' ) . "'>" . __( 'Delete Permanently' ) . '</a>'; |
| | 160 | } else { |
| | 161 | // data-wp-lists='delete:the-comment-list:comment-$comment->comment_ID::trash=1' class='delete vim-d vim-destructive' |
| | 162 | $actions['trash'] = "<a href='$trash_url' aria-label='" . esc_attr__( 'Move this comment to the Trash' ) . "'>" . _x( 'Trash', 'verb' ) . '</a>'; |
| | 163 | } |
| | 164 | |
| | 165 | if ( 'spam' !== $the_comment_status && 'trash' !== $the_comment_status ) { |
| | 166 | $actions['edit'] = "<a href='comment.php?action=editcomment&c={$comment->comment_ID}' aria-label='" . esc_attr__( 'Edit this comment' ) . "'>". __( 'Edit' ) . '</a>'; |
| | 167 | |
| | 168 | $format = '<a data-comment-id="%d" data-post-id="%d" data-action="%s" class="%s" aria-label="%s" href="#">%s</a>'; |
| | 169 | |
| | 170 | $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' ) ); |
| | 171 | |
| | 172 | $actions['reply'] = sprintf( $format, $comment->comment_ID, $comment->comment_post_ID, 'replyto', 'vim-r comment-inline', esc_attr__( 'Reply to this comment' ), __( 'Reply' ) ); |
| | 173 | } |
| | 174 | |
| | 175 | /** This filter is documented in wp-admin/includes/dashboard.php */ |
| | 176 | $actions = apply_filters( 'comment_row_actions', array_filter( $actions ), $comment ); |
| | 177 | |
| | 178 | return $actions; |
| | 179 | } |
| | 180 | |
| | 181 | /** |
| | 182 | * Generate and display row actions links. |
| | 183 | * |
| | 184 | * @since 4.3.0 |
| | 185 | * @access protected |
| | 186 | * |
| | 187 | * @global string $comment_status Status for the current listed comments. |
| | 188 | * |
| | 189 | * @param WP_Comment $comment The comment object. |
| | 190 | * @param string $column_name Current column name. |
| | 191 | * @param string $primary Primary column name. |
| | 192 | * @return string|void Comment row actions output. |
| | 193 | */ |
| | 194 | protected function handle_row_actions( $comment, $column_name, $primary ) { |
| | 195 | global $comment_status; |
| | 196 | |
| | 197 | if ( $primary !== $column_name ) { |
| | 198 | return ''; |
| | 199 | } |
| | 200 | |
| | 201 | if ( ! $this->user_can ) { |
| | 202 | return; |
| | 203 | } |
| | 204 | |
| | 205 | $the_comment_status = wp_get_comment_status( $comment ); |
| | 206 | |
| | 207 | $out = ''; |
| | 208 | |
| | 209 | |
| | 210 | $actions = $this->get_row_actions( $comment ); |
| | 211 | |
| | 212 | $i = 0; |
| | 213 | $out .= '<div class="row-actions">'; |
| | 214 | foreach ( $actions as $action => $link ) { |
| | 215 | ++$i; |
| | 216 | ( ( ( 'approve' === $action || 'unapprove' === $action ) && 2 === $i ) || 1 === $i ) ? $sep = '' : $sep = ' | '; |
| | 217 | |
| | 218 | // Reply and quickedit need a hide-if-no-js span when not added with ajax |
| | 219 | if ( ( 'reply' === $action || 'quickedit' === $action ) && ! wp_doing_ajax() ) |
| | 220 | $action .= ' hide-if-no-js'; |
| | 221 | elseif ( ( $action === 'untrash' && $the_comment_status === 'trash' ) || ( $action === 'unspam' && $the_comment_status === 'spam' ) ) { |
| | 222 | if ( '1' == get_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', true ) ) |
| | 223 | $action .= ' approve'; |
| | 224 | else |
| | 225 | $action .= ' unapprove'; |
| | 226 | } |
| | 227 | |
| | 228 | $out .= "<span class='$action'>$sep$link</span>"; |
| | 229 | } |
| | 230 | $out .= '</div>'; |
| | 231 | |
| | 232 | $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>'; |
| | 233 | |
| | 234 | return $out; |
| | 235 | } |
| | 236 | } |