Passed
Push — 677-feature/add-wp-cli-support ( d30ec9...64c504 )
by
unknown
05:28
created

DeletePostsCommand::by_comment()   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 0
Metric Value
cc 1
eloc 3
c 0
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\DeletePostsByStatusModule;
7
use BulkWP\BulkDelete\Core\Posts\Modules\DeletePostsByCommentsModule;
8
9
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
10
11
/**
12
 * Delete Posts CLI Command.
13
 *
14
 * @since 6.1.0
15
 */
16
class DeletePostsCommand extends BaseCommand {
17
	/**
18
	 * Get the command.
19
	 *
20
	 * @return string Command name.
21
	 */
22
	public static function get_command() {
23
		return 'posts';
24
	}
25
26
	/**
27
	 * Delete post by status.
28
	 *
29
	 * ## OPTIONS
30
	 *
31
	 * [--post_status=<post_status>]
32
	 * : Comma seperated list of post status from which posts should be deleted. You can also use any custom post status.
33
	 * ---
34
	 * default: publish
35
	 * ---
36
	 *
37
	 * [--limit_to=<limit_to>]
38
	 * : Limits the number of posts to be deleted.
39
	 * ---
40
	 * default: 0
41
	 * ---
42
	 *
43
	 * [--restrict=<restrict>]
44
	 * : Restricts posts deletion with post date filter.
45
	 * ---
46
	 * default: false
47
	 * ---
48
	 *
49
	 * [--force_delete=<force_delete>]
50
	 * : Should posts be permanently deleted. Set to false to move them to trash.
51
	 * ---
52
	 * default: false
53
	 * ---
54
	 *
55
	 * [--<field>=<value>]
56
	 * : Additional associative args for the deletion.
57
	 *
58
	 *  ## EXAMPLES
59
	 *
60
	 *     # Delete all published posts.
61
	 *     $ wp bulk-delete posts by-status
62
	 *     Success: Deleted 1 post from the selected post status
63
	 *
64
	 *     # Delete all draft posts.
65
	 *     $ wp bulk-delete posts by-status --post_status=draft
66
	 *     Success: Deleted 1 post from the selected post status
67
	 *
68
	 *     # Delete all published and draft posts.
69
	 *     $ wp bulk-delete posts by-status --post_status=draft,publish
70
	 *     Success: Deleted 1 post from the selected post status
71
	 *
72
	 * @subcommand by-status
73
	 *
74
	 * @param array $args       Arguments to be supplied.
75
	 * @param array $assoc_args Associative arguments to be supplied.
76
	 *
77
	 * @return void
78
	 */
79
	public function by_status( $args, $assoc_args ) {
80
		$module = new DeletePostsByStatusModule();
81
82
		$message = $module->process_cli_request( $assoc_args );
83
84
		\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...
85
	}
86
87
	/**
88
	 * Delete posts by comments.
89
	 *
90
	 * ## OPTIONS
91
	 *
92
	 * --count_value=<count_value>
93
	 * : Comments count based on which posts should be deleted. A valid comment count will be greater than or equal to zero.
94
	 *
95
	 * [--operator=<operator>]
96
	 * : Comment count comparision operator.
97
	 * ---
98
	 * default: =
99
	 * options:
100
	 *   - =
101
	 *   - !=
102
	 *   - <
103
	 *   - >
104
	 * ---
105
	 *
106
	 * [--selected_post_type=<selected_post_type>]
107
	 * : Post type and status delimited with |
108
	 * ---
109
	 * default: post|publish
110
	 * ---
111
	 *
112
	 * [--limit_to=<limit_to>]
113
	 * : Limits the number of posts to be deleted.
114
	 * ---
115
	 * default: 0
116
	 * ---
117
	 *
118
	 * [--restrict=<restrict>]
119
	 * : Restricts posts deletion with post date filter.
120
	 * ---
121
	 * default: false
122
	 * ---
123
	 *
124
	 * [--force_delete=<force_delete>]
125
	 * : Should posts be permanently deleted. Set to false to move them to trash.
126
	 * ---
127
	 * default: false
128
	 * ---
129
	 *
130
	 * [--<field>=<value>]
131
	 * : Additional associative args for the deletion.
132
	 *
133
	 *  ## EXAMPLES
134
	 *
135
	 *     # Delete all published posts with 2 comments.
136
	 *     $ wp bulk-delete posts by-comment --count_value=2
137
	 *     Success: Deleted 1 post with the selected comments count
138
	 *
139
	 *     # Delete all published products(custom post type) with less than 5 comments.
140
	 *     $ wp bulk-delete posts by-comment --count_value=5 --operator=< --selected_post_type=product|publish
141
	 *     Success: Deleted 10 post with the selected comments count
142
	 *
143
	 *     # Delete all private posts having more than 3 comments.
144
	 *     $ wp bulk-delete posts by-comment --count_value=3 --operator=> --selected_post_type=post|private
145
	 *     Success: Deleted 20 post with the selected comments count
146
	 *
147
	 * @subcommand by-comment
148
	 *
149
	 * @param array $args       Arguments to be supplied.
150
	 * @param array $assoc_args Associative arguments to be supplied.
151
	 *
152
	 * @return void
153
	 */
154
	public function by_comment( $args, $assoc_args ) {
155
		$module = new DeletePostsByCommentsModule();
156
157
		$message = $module->process_cli_request( $assoc_args );
158
159
		\WP_CLI::success( $message );
160
	}
161
}
162