Passed
Pull Request — dev/6.1.0 (#678)
by
unknown
07:49 queued 18s
created

DeletePostsCommand::by_status()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
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\DeletePostsByStatusModule;
9
10
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
11
12
/**
13
 * Delete Posts CLI Command.
14
 *
15
 * @since 6.1.0
16
 */
17
class DeletePostsCommand extends BaseCommand {
18
	/**
19
	 * Get the command.
20
	 *
21
	 * @return string Command name.
22
	 */
23
	public static function get_command() {
24
		return 'posts';
25
	}
26
27
	/**
28
	 * Delete post by status.
29
	 *
30
	 * ## OPTIONS
31
	 *
32
	 * [--post_status=<post_status>]
33
	 * : Comma seperated list of post status from which posts should be deleted. You can also use any custom post status.
34
	 * ---
35
	 * default: publish
36
	 * ---
37
	 *
38
	 * [--limit_to=<limit_to>]
39
	 * : Limits the number of posts to be deleted.
40
	 * ---
41
	 * default: 0
42
	 * ---
43
	 *
44
	 * [--restrict=<restrict>]
45
	 * : Restricts posts deletion with post date filter.
46
	 * ---
47
	 * default: false
48
	 * ---
49
	 *
50
	 * [--force_delete=<force_delete>]
51
	 * : Should posts be permanently deleted. Set to false to move them to trash.
52
	 * ---
53
	 * default: false
54
	 * ---
55
	 *
56
	 * [--<field>=<value>]
57
	 * : Additional associative args for the deletion.
58
	 *
59
	 *  ## EXAMPLES
60
	 *
61
	 *     # Delete all published posts.
62
	 *     $ wp bulk-delete posts by-status
63
	 *     Success: Deleted 1 post from the selected post status
64
	 *
65
	 *     # Delete all draft posts.
66
	 *     $ wp bulk-delete posts by-status --post_status=draft
67
	 *     Success: Deleted 1 post from the selected post status
68
	 *
69
	 *     # Delete all published and draft posts.
70
	 *     $ wp bulk-delete posts by-status --post_status=draft,publish
71
	 *     Success: Deleted 1 post from the selected post status
72
	 *
73
	 * @subcommand by-status
74
	 *
75
	 * @param array $args       Arguments to be supplied.
76
	 * @param array $assoc_args Associative arguments to be supplied.
77
	 *
78
	 * @return void
79
	 */
80
	public function by_status( $args, $assoc_args ) {
81
		$module = new DeletePostsByStatusModule();
82
83
		$message = $module->process_cli_request( $assoc_args );
84
85
		\WP_CLI::success( $message );
0 ignored issues
show
Bug introduced by
The type WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
86
	}
87
88
	/**
89
	 * Delete posts by comments.
90
	 *
91
	 * ## OPTIONS
92
	 *
93
	 * --count_value=<count_value>
94
	 * : Comments count based on which posts should be deleted. A valid comment count will be greater than or equal to zero.
95
	 *
96
	 * [--operator=<operator>]
97
	 * : Comment count comparision operator.
98
	 * ---
99
	 * default: =
100
	 * options:
101
	 *   - =
102
	 *   - !=
103
	 *   - <
104
	 *   - >
105
	 * ---
106
	 *
107
	 * [--selected_post_type=<selected_post_type>]
108
	 * : Post type and status delimited with |
109
	 * ---
110
	 * default: post|publish
111
	 * ---
112
	 *
113
	 * [--limit_to=<limit_to>]
114
	 * : Limits the number of posts to be deleted.
115
	 * ---
116
	 * default: 0
117
	 * ---
118
	 *
119
	 * [--restrict=<restrict>]
120
	 * : Restricts posts deletion with post date filter.
121
	 * ---
122
	 * default: false
123
	 * ---
124
	 *
125
	 * [--force_delete=<force_delete>]
126
	 * : Should posts be permanently deleted. Set to false to move them to trash.
127
	 * ---
128
	 * default: false
129
	 * ---
130
	 *
131
	 * [--<field>=<value>]
132
	 * : Additional associative args for the deletion.
133
	 *
134
	 *  ## EXAMPLES
135
	 *
136
	 *     # Delete all published posts with 2 comments.
137
	 *     $ wp bulk-delete posts by-comment --count_value=2
138
	 *     Success: Deleted 1 post with the selected comments count
139
	 *
140
	 *     # Delete all published products(custom post type) with less than 5 comments.
141
	 *     $ wp bulk-delete posts by-comment --count_value=5 --operator=< --selected_post_type=product|publish
142
	 *     Success: Deleted 10 post with the selected comments count
143
	 *
144
	 *     # Delete all private posts having more than 3 comments.
145
	 *     $ wp bulk-delete posts by-comment --count_value=3 --operator=> --selected_post_type=post|private
146
	 *     Success: Deleted 20 post with the selected comments count
147
	 *
148
	 * @subcommand by-comment
149
	 *
150
	 * @param array $args       Arguments to be supplied.
151
	 * @param array $assoc_args Associative arguments to be supplied.
152
	 *
153
	 * @return void
154
	 */
155
	public function by_comment( $args, $assoc_args ) {
156
		$module = new DeletePostsByCommentsModule();
157
158
		$message = $module->process_cli_request( $assoc_args );
159
160
		\WP_CLI::success( $message );
161
	}
162
163
	/**
164
	 * Delete posts by type.
165
	 *
166
	 * ## OPTIONS
167
	 *
168
	 * --selected_types=<selected_types>
169
	 * : Comma seperated list of post type and status delimited with '|'. You can also use any custom post type or status.
170
	 *
171
	 * [--limit_to=<limit_to>]
172
	 * : Limits the number of posts to be deleted.
173
	 * ---
174
	 * default: 0
175
	 * ---
176
	 *
177
	 * [--restrict=<restrict>]
178
	 * : Restricts posts deletion with post date filter.
179
	 * ---
180
	 * default: false
181
	 * ---
182
	 *
183
	 * [--force_delete=<force_delete>]
184
	 * : Should posts be permanently deleted. Set to false to move them to trash.
185
	 * ---
186
	 * default: false
187
	 * ---
188
	 *
189
	 * [--<field>=<value>]
190
	 * : Additional associative args for the deletion.
191
	 *
192
	 *  ## EXAMPLES
193
	 *
194
	 *     # Delete all published posts.
195
	 *     $ wp bulk-delete posts by-post-type --selected_types=post|publish
196
	 *     Success: Deleted 1 post from the selected post type and post status
197
	 *
198
	 *     # Delete all published products(custom post type).
199
	 *     $ wp bulk-delete posts by-post-type --selected_types=product|publish
200
	 *     Success: Deleted 10 post from the selected post type and post status
201
	 *
202
	 *     # Delete all private posts and products(custom post type).
203
	 *     $ wp bulk-delete posts by-post-type --selected_types=post|private,product|private
204
	 *     Success: Deleted 20 post from the selected post type and post status
205
	 *
206
	 * @subcommand by-post-type
207
	 *
208
	 * @param array $args       Arguments to be supplied.
209
	 * @param array $assoc_args Associative arguments to be supplied.
210
	 *
211
	 * @return void
212
	 */
213
	public function by_post_type( $args, $assoc_args ) {
214
		$module = new DeletePostsByPostTypeModule();
215
216
		$message = $module->process_cli_request( $assoc_args );
217
218
		\WP_CLI::success( $message );
219
	}
220
}
221