comment-meta.php
6 years ago
comment.php
5 years ago
meta.php
5 years ago
options.php
5 years ago
post-meta.php
6 years ago
post.php
5 years ago
user-meta.php
6 years ago
user.php
5 years ago
comment.php
110 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SearchRegex; |
| 4 | |
| 5 | use SearchRegex\Search_Source; |
| 6 | use SearchRegex\Result; |
| 7 | |
| 8 | class Source_Comment extends Search_Source { |
| 9 | public function get_columns() { |
| 10 | $columns = [ |
| 11 | 'comment_author', |
| 12 | 'comment_author_email', |
| 13 | 'comment_author_url', |
| 14 | 'comment_content', |
| 15 | ]; |
| 16 | |
| 17 | return $columns; |
| 18 | } |
| 19 | |
| 20 | public function get_column_label( $column, $data ) { |
| 21 | $labels = [ |
| 22 | 'comment_author' => __( 'Name', 'search-regex' ), |
| 23 | 'comment_author_email' => __( 'Email', 'search-regex' ), |
| 24 | 'comment_author_url' => __( 'URL', 'search-regex' ), |
| 25 | 'comment_content' => __( 'Comment', 'search-regex' ), |
| 26 | ]; |
| 27 | |
| 28 | if ( isset( $labels[ $column ] ) ) { |
| 29 | return $labels[ $column ]; |
| 30 | } |
| 31 | |
| 32 | return $column; |
| 33 | } |
| 34 | |
| 35 | public function get_search_conditions() { |
| 36 | global $wpdb; |
| 37 | |
| 38 | // If searching a particular post type then just look there |
| 39 | if ( ! $this->source_flags->has_flag( 'comment_spam' ) ) { |
| 40 | return 'comment_approved=1'; |
| 41 | } |
| 42 | |
| 43 | return ''; |
| 44 | } |
| 45 | |
| 46 | public function get_actions( Result $result ) { |
| 47 | $id = $result->get_row_id(); |
| 48 | $link = get_edit_comment_link( $id ); |
| 49 | $comment = get_comment( $id ); |
| 50 | $raw = $result->get_raw(); |
| 51 | |
| 52 | if ( $link && is_object( $comment ) ) { |
| 53 | $view = get_comment_link( $comment ); |
| 54 | |
| 55 | return array_filter( [ |
| 56 | 'edit' => str_replace( '&', '&', $link ), |
| 57 | 'view' => $view, |
| 58 | ] ); |
| 59 | } |
| 60 | |
| 61 | return []; |
| 62 | } |
| 63 | |
| 64 | public function get_supported_flags() { |
| 65 | return [ |
| 66 | 'comment_spam' => __( 'Include spam comments', 'search-regex' ), |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | public function get_table_id() { |
| 71 | return 'comment_ID'; |
| 72 | } |
| 73 | |
| 74 | public function get_info_columns() { |
| 75 | return [ 'comment_post_ID' ]; |
| 76 | } |
| 77 | |
| 78 | public function get_table_name() { |
| 79 | global $wpdb; |
| 80 | |
| 81 | return $wpdb->comments; |
| 82 | } |
| 83 | |
| 84 | public function get_title_column() { |
| 85 | return 'comment_author'; |
| 86 | } |
| 87 | |
| 88 | public function save( $row_id, $column_id, $content ) { |
| 89 | // This does all the sanitization |
| 90 | $result = wp_update_comment( [ |
| 91 | $this->get_table_id() => $row_id, |
| 92 | $column_id => $content, |
| 93 | ] ); |
| 94 | |
| 95 | if ( $result ) { |
| 96 | return true; |
| 97 | } |
| 98 | |
| 99 | return new \WP_Error( 'searchregex', 'Failed to save comment' ); |
| 100 | } |
| 101 | |
| 102 | public function delete_row( $row_id ) { |
| 103 | if ( wp_delete_comment( $row_id, true ) ) { |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | return new \WP_Error( 'searchregex_delete', 'Failed to delete comment', 401 ); |
| 108 | } |
| 109 | } |
| 110 |