PluginProbe ʕ •ᴥ•ʔ
Search Regex / 2.0
Search Regex v2.0
trunk 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 2.0 2.0.1 2.1 2.2 2.2.1 2.3 2.3.1 2.3.2 2.3.3 2.4 2.4.1 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.1 3.1.1 3.1.2 3.2 3.3 3.3.0 3.3.1 3.4 3.4.1 3.4.2
search-regex / source / core / comment.php
search-regex / source / core Last commit date
comment-meta.php 6 years ago comment.php 6 years ago meta.php 6 years ago options.php 6 years ago post-meta.php 6 years ago post.php 6 years ago user-meta.php 6 years ago user.php 6 years ago
comment.php
100 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 ) {
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( $search ) {
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 $link = get_edit_comment_link( $result->get_row_id() );
48
49 if ( $link ) {
50 return [
51 'edit' => str_replace( '&amp;', '&', $link ),
52 ];
53 }
54
55 return [];
56 }
57
58 public function get_supported_flags() {
59 return [
60 'comment_spam' => __( 'Include spam comments', 'search-regex' ),
61 ];
62 }
63
64 public function get_table_id() {
65 return 'comment_ID';
66 }
67
68 public function get_table_name() {
69 global $wpdb;
70
71 return $wpdb->comments;
72 }
73
74 public function get_title_column() {
75 return 'comment_author';
76 }
77
78 public function save( $row_id, $column_id, $content ) {
79 // This does all the sanitization
80 $result = wp_update_comment( [
81 $this->get_table_id() => $row_id,
82 $column_id => $content,
83 ] );
84
85 if ( $result ) {
86 return true;
87 }
88
89 return new \WP_Error( 'searchregex', 'Failed to save comment' );
90 }
91
92 public function delete_row( $row_id ) {
93 if ( wp_delete_comment( $row_id, true ) ) {
94 return true;
95 }
96
97 return new \WP_Error( 'searchregex_delete', 'Failed to delete comment', 401 );
98 }
99 }
100