|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\CLI\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Base\BaseCommand; |
|
6
|
|
|
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByAuthorModule; |
|
7
|
|
|
use BulkWP\BulkDelete\Core\Comments\Modules\DeleteCommentsByIPModule; |
|
8
|
|
|
|
|
9
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Delete Comments CLI Command. |
|
13
|
|
|
* |
|
14
|
|
|
* @since 6.1.0 |
|
15
|
|
|
*/ |
|
16
|
|
|
class DeleteCommentsCommand extends BaseCommand { |
|
17
|
|
|
/** |
|
18
|
|
|
* Get the command. |
|
19
|
|
|
* |
|
20
|
|
|
* @return string Command name. |
|
21
|
|
|
*/ |
|
22
|
|
|
public static function get_command() { |
|
23
|
|
|
return 'comments'; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Delete comments by author details. |
|
28
|
|
|
* |
|
29
|
|
|
* ## OPTIONS |
|
30
|
|
|
* |
|
31
|
|
|
* --details=<details> |
|
32
|
|
|
* : Comment author details based on which comments should be deleted. You can either enter the name, email or the url of the comment author. |
|
33
|
|
|
* |
|
34
|
|
|
* [--restrict=<restrict>] |
|
35
|
|
|
* : Restricts comments deletion with comment date filter. |
|
36
|
|
|
* --- |
|
37
|
|
|
* default: false |
|
38
|
|
|
* options: |
|
39
|
|
|
* - true |
|
40
|
|
|
* - false |
|
41
|
|
|
* --- |
|
42
|
|
|
* |
|
43
|
|
|
* [--op=<op>] |
|
44
|
|
|
* : Can be used only when --restrict=true. Restricts comments deletion with older than(before) or in the last(after) filter. |
|
45
|
|
|
* --- |
|
46
|
|
|
* options: |
|
47
|
|
|
* - before |
|
48
|
|
|
* - after |
|
49
|
|
|
* --- |
|
50
|
|
|
* |
|
51
|
|
|
* [--days=<days>] |
|
52
|
|
|
* : Can be used only when --restrict=true. Restricts comments deletion with creation date. |
|
53
|
|
|
* |
|
54
|
|
|
* [--limit_to=<limit_to>] |
|
55
|
|
|
* : Limits the number of comments to be deleted. |
|
56
|
|
|
* --- |
|
57
|
|
|
* default: 0 |
|
58
|
|
|
* --- |
|
59
|
|
|
* |
|
60
|
|
|
* [--force_delete=<force_delete>] |
|
61
|
|
|
* : Should comments be permanently deleted. Set to false to move them to trash. |
|
62
|
|
|
* --- |
|
63
|
|
|
* default: false |
|
64
|
|
|
* options: |
|
65
|
|
|
* - true |
|
66
|
|
|
* - false |
|
67
|
|
|
* --- |
|
68
|
|
|
* |
|
69
|
|
|
* ## EXAMPLES |
|
70
|
|
|
* |
|
71
|
|
|
* # Delete all comments with author name apple. |
|
72
|
|
|
* $ wp bulk-delete comments by-author --details=apple |
|
73
|
|
|
* Success: Deleted 10 comments with selected condition |
|
74
|
|
|
* |
|
75
|
|
|
* # Delete all comments with author email [email protected] and older than 10 days. |
|
76
|
|
|
* $ wp bulk-delete comments by-author [email protected] --restrict=true --op=before --days=10 |
|
77
|
|
|
* Success: Deleted 5 comments with selected condition |
|
78
|
|
|
* |
|
79
|
|
|
* # Delete all comments with author url www.apple.com that are created in the last 5 days. |
|
80
|
|
|
* $ wp bulk-delete comments by-author --details=www.apple.com --restrict=true --op=after --days=5 |
|
81
|
|
|
* Success: Deleted 5 comments with selected condition |
|
82
|
|
|
* |
|
83
|
|
|
* # Move 500 comments to trash. |
|
84
|
|
|
* $ wp bulk-delete comments by-author --details=www.apple.com --limit_to=500 |
|
85
|
|
|
* Success: Deleted 500 comments with selected condition |
|
86
|
|
|
* |
|
87
|
|
|
* # Permanently delete 500 comments by author apple. |
|
88
|
|
|
* $ wp bulk-delete comments by-author --details=apple --limit_to=500 --force_delete=true |
|
89
|
|
|
* Success: Deleted 500 comments with selected condition |
|
90
|
|
|
* |
|
91
|
|
|
* @subcommand by-author |
|
92
|
|
|
* |
|
93
|
|
|
* @param array $args Arguments to be supplied. |
|
94
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
95
|
|
|
* |
|
96
|
|
|
* @return void |
|
97
|
|
|
*/ |
|
98
|
|
|
public function by_author( $args, $assoc_args ) { |
|
99
|
|
|
$module = new DeleteCommentsByAuthorModule(); |
|
100
|
|
|
|
|
101
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
102
|
|
|
|
|
103
|
|
|
\WP_CLI::success( $message ); |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Delete comments by ip address. |
|
108
|
|
|
* |
|
109
|
|
|
* ## OPTIONS |
|
110
|
|
|
* |
|
111
|
|
|
* --address=<address> |
|
112
|
|
|
* : IP Address based on which comments should be deleted. |
|
113
|
|
|
* |
|
114
|
|
|
* [--restrict=<restrict>] |
|
115
|
|
|
* : Restricts comments deletion with comment date filter. |
|
116
|
|
|
* --- |
|
117
|
|
|
* default: false |
|
118
|
|
|
* options: |
|
119
|
|
|
* - true |
|
120
|
|
|
* - false |
|
121
|
|
|
* --- |
|
122
|
|
|
* |
|
123
|
|
|
* [--op=<op>] |
|
124
|
|
|
* : Can be used only when --restrict=true. Restricts comments deletion with older than(before) or in the last(after) filter. |
|
125
|
|
|
* --- |
|
126
|
|
|
* options: |
|
127
|
|
|
* - before |
|
128
|
|
|
* - after |
|
129
|
|
|
* --- |
|
130
|
|
|
* |
|
131
|
|
|
* [--days=<days>] |
|
132
|
|
|
* : Can be used only when --restrict=true. Restricts comments deletion with creation date. |
|
133
|
|
|
* |
|
134
|
|
|
* [--limit_to=<limit_to>] |
|
135
|
|
|
* : Limits the number of comments to be deleted. |
|
136
|
|
|
* --- |
|
137
|
|
|
* default: 0 |
|
138
|
|
|
* --- |
|
139
|
|
|
* |
|
140
|
|
|
* [--force_delete=<force_delete>] |
|
141
|
|
|
* : Should comments be permanently deleted. Set to false to move them to trash. |
|
142
|
|
|
* --- |
|
143
|
|
|
* default: false |
|
144
|
|
|
* options: |
|
145
|
|
|
* - true |
|
146
|
|
|
* - false |
|
147
|
|
|
* --- |
|
148
|
|
|
* |
|
149
|
|
|
* ## EXAMPLES |
|
150
|
|
|
* |
|
151
|
|
|
* # Delete all comments with ip address 127.0.0.1. |
|
152
|
|
|
* $ wp bulk-delete comments by-ip --address=127.0.0.1 |
|
153
|
|
|
* Success: Deleted 10 comments with selected condition |
|
154
|
|
|
* |
|
155
|
|
|
* # Delete all comments with ip address 127.0.0.1 and older than 10 days. |
|
156
|
|
|
* $ wp bulk-delete comments by-ip --address=127.0.0.1 --restrict=true --op=before --days=10 |
|
157
|
|
|
* Success: Deleted 5 comments with selected condition |
|
158
|
|
|
* |
|
159
|
|
|
* # Delete all comments with ip address 127.0.0.1 that are created in the last 5 days. |
|
160
|
|
|
* $ wp bulk-delete comments by-ip --address=127.0.0.1 --restrict=true --op=after --days=5 |
|
161
|
|
|
* Success: Deleted 5 comments with selected condition |
|
162
|
|
|
* |
|
163
|
|
|
* # Move 500 comments to trash with ip address 127.0.0.1. |
|
164
|
|
|
* $ wp bulk-delete comments by-ip --address=127.0.0.1 --limit_to=500 |
|
165
|
|
|
* Success: Deleted 500 comments with selected condition |
|
166
|
|
|
* |
|
167
|
|
|
* # Permanently delete 500 comments with ip address 127.0.0.1. |
|
168
|
|
|
* $ wp bulk-delete comments by-ip --address=127.0.0.1 --limit_to=500 --force_delete=true |
|
169
|
|
|
* Success: Deleted 500 comments with selected condition |
|
170
|
|
|
* |
|
171
|
|
|
* @subcommand by-ip |
|
172
|
|
|
* |
|
173
|
|
|
* @param array $args Arguments to be supplied. |
|
174
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
175
|
|
|
* |
|
176
|
|
|
* @return void |
|
177
|
|
|
*/ |
|
178
|
|
|
public function by_ip( $args, $assoc_args ) { |
|
179
|
|
|
$module = new DeleteCommentsByIPModule(); |
|
180
|
|
|
|
|
181
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
182
|
|
|
|
|
183
|
|
|
\WP_CLI::success( $message ); |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths