|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\CLI\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Base\BaseCommand; |
|
6
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByCommentsModule; |
|
7
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByPostTypeModule; |
|
8
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByRevisionModule; |
|
9
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByStatusModule; |
|
10
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByStickyPostModule; |
|
11
|
|
|
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByTaxonomyModule; |
|
12
|
|
|
|
|
13
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Delete Posts CLI Command. |
|
17
|
|
|
* |
|
18
|
|
|
* @since 6.1.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
class DeletePostsCommand extends BaseCommand { |
|
21
|
|
|
/** |
|
22
|
|
|
* Get the command. |
|
23
|
|
|
* |
|
24
|
|
|
* @return string Command name. |
|
25
|
|
|
*/ |
|
26
|
|
|
public static function get_command() { |
|
27
|
|
|
return 'posts'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Delete post by status. |
|
32
|
|
|
* |
|
33
|
|
|
* ## OPTIONS |
|
34
|
|
|
* |
|
35
|
|
|
* [--post_status=<post_status>] |
|
36
|
|
|
* : Comma seperated list of post status from which posts should be deleted. You can also use any custom post status. |
|
37
|
|
|
* --- |
|
38
|
|
|
* default: publish |
|
39
|
|
|
* --- |
|
40
|
|
|
* |
|
41
|
|
|
* [--limit_to=<limit_to>] |
|
42
|
|
|
* : Limits the number of posts to be deleted. |
|
43
|
|
|
* --- |
|
44
|
|
|
* default: 0 |
|
45
|
|
|
* --- |
|
46
|
|
|
* |
|
47
|
|
|
* [--restrict=<restrict>] |
|
48
|
|
|
* : Restricts posts deletion with post date filter. |
|
49
|
|
|
* --- |
|
50
|
|
|
* default: false |
|
51
|
|
|
* options: |
|
52
|
|
|
* - true |
|
53
|
|
|
* - false |
|
54
|
|
|
* --- |
|
55
|
|
|
* |
|
56
|
|
|
* [--force_delete=<force_delete>] |
|
57
|
|
|
* : Should posts be permanently deleted. Set to false to move them to trash. |
|
58
|
|
|
* --- |
|
59
|
|
|
* default: false |
|
60
|
|
|
* options: |
|
61
|
|
|
* - true |
|
62
|
|
|
* - false |
|
63
|
|
|
* --- |
|
64
|
|
|
* |
|
65
|
|
|
* [--<field>=<value>] |
|
66
|
|
|
* : Additional associative args for the deletion. |
|
67
|
|
|
* |
|
68
|
|
|
* ## EXAMPLES |
|
69
|
|
|
* |
|
70
|
|
|
* # Delete all published posts. |
|
71
|
|
|
* $ wp bulk-delete posts by-status |
|
72
|
|
|
* Success: Deleted 1 post from the selected post status |
|
73
|
|
|
* |
|
74
|
|
|
* # Delete all draft posts. |
|
75
|
|
|
* $ wp bulk-delete posts by-status --post_status=draft |
|
76
|
|
|
* Success: Deleted 1 post from the selected post status |
|
77
|
|
|
* |
|
78
|
|
|
* # Delete all published and draft posts. |
|
79
|
|
|
* $ wp bulk-delete posts by-status --post_status=draft,publish |
|
80
|
|
|
* Success: Deleted 1 post from the selected post status |
|
81
|
|
|
* |
|
82
|
|
|
* @subcommand by-status |
|
83
|
|
|
* |
|
84
|
|
|
* @param array $args Arguments to be supplied. |
|
85
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function by_status( $args, $assoc_args ) { |
|
90
|
|
|
$module = new DeletePostsByStatusModule(); |
|
91
|
|
|
|
|
92
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
93
|
|
|
|
|
94
|
|
|
\WP_CLI::success( $message ); |
|
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Delete posts by comments. |
|
99
|
|
|
* |
|
100
|
|
|
* ## OPTIONS |
|
101
|
|
|
* |
|
102
|
|
|
* --count_value=<count_value> |
|
103
|
|
|
* : Comments count based on which posts should be deleted. A valid comment count will be greater than or equal to zero. |
|
104
|
|
|
* |
|
105
|
|
|
* [--operator=<operator>] |
|
106
|
|
|
* : Comment count comparision operator. |
|
107
|
|
|
* --- |
|
108
|
|
|
* default: = |
|
109
|
|
|
* options: |
|
110
|
|
|
* - = |
|
111
|
|
|
* - != |
|
112
|
|
|
* - < |
|
113
|
|
|
* - > |
|
114
|
|
|
* --- |
|
115
|
|
|
* |
|
116
|
|
|
* [--selected_post_type=<selected_post_type>] |
|
117
|
|
|
* : Post type and status delimited with | |
|
118
|
|
|
* --- |
|
119
|
|
|
* default: post|publish |
|
120
|
|
|
* --- |
|
121
|
|
|
* |
|
122
|
|
|
* [--limit_to=<limit_to>] |
|
123
|
|
|
* : Limits the number of posts to be deleted. |
|
124
|
|
|
* --- |
|
125
|
|
|
* default: 0 |
|
126
|
|
|
* --- |
|
127
|
|
|
* |
|
128
|
|
|
* [--restrict=<restrict>] |
|
129
|
|
|
* : Restricts posts deletion with post date filter. |
|
130
|
|
|
* --- |
|
131
|
|
|
* default: false |
|
132
|
|
|
* options: |
|
133
|
|
|
* - true |
|
134
|
|
|
* - false |
|
135
|
|
|
* --- |
|
136
|
|
|
* |
|
137
|
|
|
* [--force_delete=<force_delete>] |
|
138
|
|
|
* : Should posts be permanently deleted. Set to false to move them to trash. |
|
139
|
|
|
* --- |
|
140
|
|
|
* default: false |
|
141
|
|
|
* options: |
|
142
|
|
|
* - true |
|
143
|
|
|
* - false |
|
144
|
|
|
* --- |
|
145
|
|
|
* |
|
146
|
|
|
* [--<field>=<value>] |
|
147
|
|
|
* : Additional associative args for the deletion. |
|
148
|
|
|
* |
|
149
|
|
|
* ## EXAMPLES |
|
150
|
|
|
* |
|
151
|
|
|
* # Delete all published posts with 2 comments. |
|
152
|
|
|
* $ wp bulk-delete posts by-comment --count_value=2 |
|
153
|
|
|
* Success: Deleted 1 post with the selected comments count |
|
154
|
|
|
* |
|
155
|
|
|
* # Delete all published products(custom post type) with less than 5 comments. |
|
156
|
|
|
* $ wp bulk-delete posts by-comment --count_value=5 --operator=< --selected_post_type=product|publish |
|
157
|
|
|
* Success: Deleted 10 post with the selected comments count |
|
158
|
|
|
* |
|
159
|
|
|
* # Delete all private posts having more than 3 comments. |
|
160
|
|
|
* $ wp bulk-delete posts by-comment --count_value=3 --operator=> --selected_post_type=post|private |
|
161
|
|
|
* Success: Deleted 20 post with the selected comments count |
|
162
|
|
|
* |
|
163
|
|
|
* @subcommand by-comment |
|
164
|
|
|
* |
|
165
|
|
|
* @param array $args Arguments to be supplied. |
|
166
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
167
|
|
|
* |
|
168
|
|
|
* @return void |
|
169
|
|
|
*/ |
|
170
|
|
|
public function by_comment( $args, $assoc_args ) { |
|
171
|
|
|
$module = new DeletePostsByCommentsModule(); |
|
172
|
|
|
|
|
173
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
174
|
|
|
|
|
175
|
|
|
\WP_CLI::success( $message ); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Delete posts by type. |
|
180
|
|
|
* |
|
181
|
|
|
* ## OPTIONS |
|
182
|
|
|
* |
|
183
|
|
|
* --selected_types=<selected_types> |
|
184
|
|
|
* : Comma seperated list of post type and status delimited with '|'. You can also use any custom post type or status. |
|
185
|
|
|
* |
|
186
|
|
|
* [--limit_to=<limit_to>] |
|
187
|
|
|
* : Limits the number of posts to be deleted. |
|
188
|
|
|
* --- |
|
189
|
|
|
* default: 0 |
|
190
|
|
|
* --- |
|
191
|
|
|
* |
|
192
|
|
|
* [--restrict=<restrict>] |
|
193
|
|
|
* : Restricts posts deletion with post date filter. |
|
194
|
|
|
* --- |
|
195
|
|
|
* default: false |
|
196
|
|
|
* options: |
|
197
|
|
|
* - true |
|
198
|
|
|
* - false |
|
199
|
|
|
* --- |
|
200
|
|
|
* |
|
201
|
|
|
* [--force_delete=<force_delete>] |
|
202
|
|
|
* : Should posts be permanently deleted. Set to false to move them to trash. |
|
203
|
|
|
* --- |
|
204
|
|
|
* default: false |
|
205
|
|
|
* options: |
|
206
|
|
|
* - true |
|
207
|
|
|
* - false |
|
208
|
|
|
* --- |
|
209
|
|
|
* |
|
210
|
|
|
* [--<field>=<value>] |
|
211
|
|
|
* : Additional associative args for the deletion. |
|
212
|
|
|
* |
|
213
|
|
|
* ## EXAMPLES |
|
214
|
|
|
* |
|
215
|
|
|
* # Delete all published posts. |
|
216
|
|
|
* $ wp bulk-delete posts by-post-type --selected_types=post|publish |
|
217
|
|
|
* Success: Deleted 1 post from the selected post type and post status |
|
218
|
|
|
* |
|
219
|
|
|
* # Delete all published products(custom post type). |
|
220
|
|
|
* $ wp bulk-delete posts by-post-type --selected_types=product|publish |
|
221
|
|
|
* Success: Deleted 10 posts from the selected post type and post status |
|
222
|
|
|
* |
|
223
|
|
|
* # Delete all private posts and products(custom post type). |
|
224
|
|
|
* $ wp bulk-delete posts by-post-type --selected_types='post|private,product|private' |
|
225
|
|
|
* Success: Deleted 20 posts from the selected post type and post status |
|
226
|
|
|
* |
|
227
|
|
|
* @subcommand by-post-type |
|
228
|
|
|
* |
|
229
|
|
|
* @param array $args Arguments to be supplied. |
|
230
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
231
|
|
|
* |
|
232
|
|
|
* @return void |
|
233
|
|
|
*/ |
|
234
|
|
|
public function by_post_type( $args, $assoc_args ) { |
|
235
|
|
|
$module = new DeletePostsByPostTypeModule(); |
|
236
|
|
|
|
|
237
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
238
|
|
|
|
|
239
|
|
|
\WP_CLI::success( $message ); |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
/** |
|
243
|
|
|
* Delete post revisions. |
|
244
|
|
|
* |
|
245
|
|
|
* ## OPTIONS |
|
246
|
|
|
* |
|
247
|
|
|
* [--revisions=<revisions>] |
|
248
|
|
|
* : Optional parameter which can take only 'revisions' as its value. |
|
249
|
|
|
* --- |
|
250
|
|
|
* default: revisions |
|
251
|
|
|
* --- |
|
252
|
|
|
* |
|
253
|
|
|
* [--limit_to=<limit_to>] |
|
254
|
|
|
* : Limits the number of posts to be deleted. |
|
255
|
|
|
* --- |
|
256
|
|
|
* default: 0 |
|
257
|
|
|
* --- |
|
258
|
|
|
* |
|
259
|
|
|
* [--restrict=<restrict>] |
|
260
|
|
|
* : Restricts posts deletion with post date filter. |
|
261
|
|
|
* --- |
|
262
|
|
|
* default: false |
|
263
|
|
|
* options: |
|
264
|
|
|
* - true |
|
265
|
|
|
* - false |
|
266
|
|
|
* --- |
|
267
|
|
|
* |
|
268
|
|
|
* [--<field>=<value>] |
|
269
|
|
|
* : Additional associative args for the deletion. |
|
270
|
|
|
* |
|
271
|
|
|
* ## EXAMPLES |
|
272
|
|
|
* |
|
273
|
|
|
* # Delete all revisions. |
|
274
|
|
|
* $ wp bulk-delete posts by-revision |
|
275
|
|
|
* Success: Deleted 10 post revisions |
|
276
|
|
|
* |
|
277
|
|
|
* # Delete all revisions. |
|
278
|
|
|
* $ wp bulk-delete posts by-revision --revisions=revisions |
|
279
|
|
|
* Success: Deleted 1 post revision |
|
280
|
|
|
* |
|
281
|
|
|
* @subcommand by-revision |
|
282
|
|
|
* |
|
283
|
|
|
* @param array $args Arguments to be supplied. |
|
284
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
285
|
|
|
* |
|
286
|
|
|
* @return void |
|
287
|
|
|
*/ |
|
288
|
|
|
public function by_revision( $args, $assoc_args ) { |
|
289
|
|
|
$module = new DeletePostsByRevisionModule(); |
|
290
|
|
|
|
|
291
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
292
|
|
|
|
|
293
|
|
|
\WP_CLI::success( $message ); |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
/** |
|
297
|
|
|
* Remove sticky or delete sticky posts. |
|
298
|
|
|
* |
|
299
|
|
|
* ## OPTIONS |
|
300
|
|
|
* |
|
301
|
|
|
* [--sticky_action=<sticky_action>] |
|
302
|
|
|
* : Determines whether post has to be made unsticky or deleted. |
|
303
|
|
|
* --- |
|
304
|
|
|
* default: unsticky |
|
305
|
|
|
* options: |
|
306
|
|
|
* - unsticky |
|
307
|
|
|
* - delete |
|
308
|
|
|
* --- |
|
309
|
|
|
* |
|
310
|
|
|
* --selected_posts=<selected_posts> |
|
311
|
|
|
* : Comma separated list of post ids or 'all' for selecting all sticky posts. |
|
312
|
|
|
* --- |
|
313
|
|
|
* |
|
314
|
|
|
* [--force_delete=<force_delete>] |
|
315
|
|
|
* : Should posts be permanently deleted. Set to false to move them to trash. |
|
316
|
|
|
* --- |
|
317
|
|
|
* default: false |
|
318
|
|
|
* options: |
|
319
|
|
|
* - true |
|
320
|
|
|
* - false |
|
321
|
|
|
* --- |
|
322
|
|
|
* |
|
323
|
|
|
* ## EXAMPLES |
|
324
|
|
|
* |
|
325
|
|
|
* # Remove sticky for all sticky posts. |
|
326
|
|
|
* $ wp bulk-delete posts by-sticky --selected_posts=all |
|
327
|
|
|
* Success: 10 sticky posts were made into normal posts |
|
328
|
|
|
* |
|
329
|
|
|
* # Delete selected sticky posts. |
|
330
|
|
|
* $ wp bulk-delete posts by-sticky --selected_posts=1,2,3 --sticky_action=delete --force_delete=true |
|
331
|
|
|
* Success: Deleted 3 sticky posts |
|
332
|
|
|
* |
|
333
|
|
|
* # Move to trash all sticky posts. |
|
334
|
|
|
* $ wp bulk-delete posts by-sticky --selected_posts=all --sticky_action=delete |
|
335
|
|
|
* Success: Deleted 5 sticky posts |
|
336
|
|
|
* |
|
337
|
|
|
* @subcommand by-sticky |
|
338
|
|
|
* |
|
339
|
|
|
* @param array $args Arguments to be supplied. |
|
340
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
341
|
|
|
* |
|
342
|
|
|
* @return void |
|
343
|
|
|
*/ |
|
344
|
|
|
public function by_sticky( $args, $assoc_args ) { |
|
345
|
|
|
$module = new DeletePostsByStickyPostModule(); |
|
346
|
|
|
|
|
347
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
348
|
|
|
|
|
349
|
|
|
\WP_CLI::success( $message ); |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
/** |
|
353
|
|
|
* Delete post by taxonomy. |
|
354
|
|
|
* |
|
355
|
|
|
* ## OPTIONS |
|
356
|
|
|
* |
|
357
|
|
|
* [--post_type=<post_type>] |
|
358
|
|
|
* : Select a post type from which posts should be deleted. You can also use any custom post type. |
|
359
|
|
|
* --- |
|
360
|
|
|
* default: post |
|
361
|
|
|
* --- |
|
362
|
|
|
* |
|
363
|
|
|
* --taxonomy=<taxonomy> |
|
364
|
|
|
* : Select a taxonomy from which posts should be deleted. You can also use any custom taxonomy. |
|
365
|
|
|
* |
|
366
|
|
|
* --terms=<terms> |
|
367
|
|
|
* : Comma separated list of terms from which posts should be deleted. |
|
368
|
|
|
* |
|
369
|
|
|
* [--limit_to=<limit_to>] |
|
370
|
|
|
* : Limits the number of posts to be deleted. |
|
371
|
|
|
* --- |
|
372
|
|
|
* default: 0 |
|
373
|
|
|
* --- |
|
374
|
|
|
* |
|
375
|
|
|
* [--restrict=<restrict>] |
|
376
|
|
|
* : Restricts posts deletion with post date filter. |
|
377
|
|
|
* --- |
|
378
|
|
|
* default: false |
|
379
|
|
|
* options: |
|
380
|
|
|
* - true |
|
381
|
|
|
* - false |
|
382
|
|
|
* --- |
|
383
|
|
|
* |
|
384
|
|
|
* [--force_delete=<force_delete>] |
|
385
|
|
|
* : Should posts be permanently deleted. Set to false to move them to trash. |
|
386
|
|
|
* --- |
|
387
|
|
|
* default: false |
|
388
|
|
|
* options: |
|
389
|
|
|
* - true |
|
390
|
|
|
* - false |
|
391
|
|
|
* --- |
|
392
|
|
|
* |
|
393
|
|
|
* [--<field>=<value>] |
|
394
|
|
|
* : Additional associative args for the deletion. |
|
395
|
|
|
* |
|
396
|
|
|
* ## EXAMPLES |
|
397
|
|
|
* |
|
398
|
|
|
* # Delete all posts belong to category fruit. |
|
399
|
|
|
* $ wp bulk-delete posts by-taxonomy --taxonomy=category --terms=fruit |
|
400
|
|
|
* Success: Deleted 10 posts from the selected taxonomy |
|
401
|
|
|
* |
|
402
|
|
|
* # Delete all products(custom post type) with product tag(custom taxonomy) skybag. |
|
403
|
|
|
* $ wp bulk-delete posts by-taxonomy --post_type=product --taxonomy=product_tag --terms=skybag |
|
404
|
|
|
* Success: Deleted 20 posts from the selected taxonomy |
|
405
|
|
|
* |
|
406
|
|
|
* # Delete all posts belong to biography or story tags. |
|
407
|
|
|
* $ wp bulk-delete posts by-taxonomy --taxonomy=post_tag --terms=biography,story |
|
408
|
|
|
* Success: Deleted 30 posts from the selected taxonomy |
|
409
|
|
|
* |
|
410
|
|
|
* @subcommand by-taxonomy |
|
411
|
|
|
* |
|
412
|
|
|
* @param array $args Arguments to be supplied. |
|
413
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
|
414
|
|
|
* |
|
415
|
|
|
* @return void |
|
416
|
|
|
*/ |
|
417
|
|
|
public function by_taxonomy( $args, $assoc_args ) { |
|
418
|
|
|
$module = new DeletePostsByTaxonomyModule(); |
|
419
|
|
|
|
|
420
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
|
421
|
|
|
|
|
422
|
|
|
\WP_CLI::success( $message ); |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
|
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