|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Comments\Modules; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Comments\CommentsModule; |
|
6
|
|
|
|
|
7
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Delete Comments by Author Module. |
|
11
|
|
|
* |
|
12
|
|
|
* @since 6.1.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
class DeleteCommentsByAuthorModule extends CommentsModule { |
|
15
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
16
|
|
|
protected function initialize() { |
|
17
|
|
|
$this->item_type = 'comments'; |
|
18
|
|
|
$this->field_slug = 'comments_by_author'; |
|
19
|
|
|
$this->meta_box_slug = 'bd_comments_by_author'; |
|
20
|
|
|
$this->action = 'delete_comments_by_author'; |
|
21
|
|
|
$this->cron_hook = 'do-bulk-delete-comments-by-author'; |
|
22
|
|
|
$this->scheduler_url = 'https://bulkwp.com/addons/scheduler-for-deleting-comments-by-author/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-sp'; |
|
23
|
|
|
$this->messages = array( |
|
24
|
|
|
'box_label' => __( 'By Author', 'bulk-delete' ), |
|
25
|
|
|
'scheduled' => __( 'The selected comments are scheduled for deletion', 'bulk-delete' ), |
|
26
|
|
|
'cron_label' => __( 'Delete Comments By author', 'bulk-delete' ), |
|
27
|
|
|
'confirm_deletion' => __( 'Are you sure you want to delete all the comments from the selected condition?', 'bulk-delete' ), |
|
28
|
|
|
'confirm_scheduled' => __( 'Are you sure you want to schedule deletion for all the comments from the selected condition?', 'bulk-delete' ), |
|
29
|
|
|
'validation_error' => __( 'Please enter author name or email or URL based on which comments should be deleted', 'bulk-delete' ), |
|
30
|
|
|
/* translators: 1 Number of comments deleted */ |
|
31
|
|
|
'deleted_one' => __( 'Deleted %d comment with selected condition', 'bulk-delete' ), |
|
32
|
|
|
/* translators: 1 Number of comments deleted */ |
|
33
|
|
|
'deleted_multiple' => __( 'Deleted %d comments with selected condition', 'bulk-delete' ), |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
38
|
|
|
public function render() { |
|
39
|
|
|
?> |
|
40
|
|
|
<!-- Pages start--> |
|
41
|
|
|
<h4><?php _e( 'Enter Author name or email or URL whose comments you want to delete', 'bulk-delete' ); ?></h4> |
|
42
|
|
|
|
|
43
|
|
|
<fieldset class="options"> |
|
44
|
|
|
<table class="optiontable"> |
|
45
|
|
|
<tr> |
|
46
|
|
|
<td> |
|
47
|
|
|
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_name" type="text" placeholder="<?php _e( 'Author Name', 'bulk-delete' ); ?>"> |
|
48
|
|
|
</td> |
|
49
|
|
|
<td> <?php _e( 'Or', 'bulk-delete' ); ?></td> |
|
50
|
|
|
<td> |
|
51
|
|
|
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_email" type="text" placeholder="<?php _e( 'Author Email', 'bulk-delete' ); ?>"> |
|
52
|
|
|
</td> |
|
53
|
|
|
<td> <?php _e( 'Or', 'bulk-delete' ); ?></td> |
|
54
|
|
|
<td> |
|
55
|
|
|
<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_url" type="text" placeholder="<?php _e( 'Author URL', 'bulk-delete' ); ?>"> |
|
56
|
|
|
</td> |
|
57
|
|
|
</tr> |
|
58
|
|
|
</table> |
|
59
|
|
|
|
|
60
|
|
|
<table class="optiontable"> |
|
61
|
|
|
<?php |
|
62
|
|
|
$this->render_filtering_table_header(); |
|
63
|
|
|
$this->render_restrict_settings(); |
|
64
|
|
|
$this->render_delete_settings(); |
|
65
|
|
|
$this->render_limit_settings(); |
|
66
|
|
|
$this->render_cron_settings(); |
|
67
|
|
|
?> |
|
68
|
|
|
</table> |
|
69
|
|
|
</fieldset> |
|
70
|
|
|
|
|
71
|
|
|
<?php |
|
72
|
|
|
$this->render_submit_button(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
76
|
|
|
protected function append_to_js_array( $js_array ) { |
|
77
|
|
|
$js_array['validators'][ $this->action ] = 'noValidation'; |
|
78
|
|
|
|
|
79
|
|
|
return $js_array; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
83
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
|
84
|
|
|
$options['author_name'] = sanitize_text_field( bd_array_get( $request, 'smbd_' . $this->field_slug . '_name', '' ) ); |
|
85
|
|
|
$options['author_email'] = sanitize_text_field( bd_array_get( $request, 'smbd_' . $this->field_slug . '_email', '' ) ); |
|
86
|
|
|
$options['author_url'] = sanitize_text_field( bd_array_get( $request, 'smbd_' . $this->field_slug . '_url', '' ) ); |
|
87
|
|
|
|
|
88
|
|
|
return $options; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
|
92
|
|
|
protected function build_query( $options ) { |
|
93
|
|
|
$query = array(); |
|
94
|
|
|
if ( ! empty( $options['author_name'] ) ) { |
|
95
|
|
|
// TODO: to be decided. |
|
96
|
|
|
$query['author__in'] = array(); |
|
97
|
|
|
} |
|
98
|
|
|
if ( ! empty( $options['author_email'] ) ) { |
|
99
|
|
|
$query['author_email'] = $options['author_email']; |
|
100
|
|
|
} |
|
101
|
|
|
if ( ! empty( $options['author_url'] ) ) { |
|
102
|
|
|
$query['author_url'] = $options['author_url']; |
|
103
|
|
|
} |
|
104
|
|
|
$date_query = $this->get_date_query( $options ); |
|
105
|
|
|
|
|
106
|
|
|
if ( ! empty( $date_query ) ) { |
|
107
|
|
|
$query['date_query'] = $date_query; |
|
108
|
|
|
} |
|
109
|
|
|
error_log( var_export( $query, true ) ); |
|
110
|
|
|
|
|
111
|
|
|
return $query; |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|