1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\CLI\Commands; |
4
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Base\BaseCommand; |
6
|
|
|
use BulkWP\BulkDelete\Core\Users\Modules\DeleteUsersByUserMetaModule; |
7
|
|
|
use BulkWP\BulkDelete\Core\Users\Modules\DeleteUsersByUserRoleModule; |
8
|
|
|
|
9
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Delete Users CLI Command. |
13
|
|
|
* |
14
|
|
|
* @since 6.1.0 |
15
|
|
|
*/ |
16
|
|
|
class DeleteUsersCommand extends BaseCommand { |
17
|
|
|
/** |
18
|
|
|
* Get the command. |
19
|
|
|
* |
20
|
|
|
* @return string Command name. |
21
|
|
|
*/ |
22
|
|
|
public static function get_command() { |
23
|
|
|
return 'users'; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Delete user by user meta. |
28
|
|
|
* |
29
|
|
|
* ## OPTIONS |
30
|
|
|
* |
31
|
|
|
* --key=<key> |
32
|
|
|
* : User meta key. |
33
|
|
|
* |
34
|
|
|
* --value=<value> |
35
|
|
|
* : User meta value. |
36
|
|
|
* |
37
|
|
|
* [--compare=<compare>] |
38
|
|
|
* : Comparison operator. Use STARTS WITH, ENDS WITH, NOT LIKE operators enclosed in single quotes. |
39
|
|
|
* --- |
40
|
|
|
* default: = |
41
|
|
|
* options: |
42
|
|
|
* - = |
43
|
|
|
* - != |
44
|
|
|
* - < |
45
|
|
|
* - <= |
46
|
|
|
* - > |
47
|
|
|
* - >= |
48
|
|
|
* - LIKE |
49
|
|
|
* - NOT LIKE |
50
|
|
|
* - STARTS WITH |
51
|
|
|
* - ENDS WITH |
52
|
|
|
* --- |
53
|
|
|
* |
54
|
|
|
* [--registered_restrict=<registered_restrict>] |
55
|
|
|
* : Restricts users deletion with registration date filter. |
56
|
|
|
* --- |
57
|
|
|
* default: false |
58
|
|
|
* options: |
59
|
|
|
* - true |
60
|
|
|
* - false |
61
|
|
|
* --- |
62
|
|
|
* |
63
|
|
|
* [--op=<op>] |
64
|
|
|
* : Can be used only when --registered_restrict=true. Restricts users deletion with registered date older than(before) or in the last(after) filter. |
65
|
|
|
* --- |
66
|
|
|
* options: |
67
|
|
|
* - before |
68
|
|
|
* - after |
69
|
|
|
* --- |
70
|
|
|
* |
71
|
|
|
* [--registered_days=<registered_days>] |
72
|
|
|
* : Restricts users deletion with registration date filter. |
73
|
|
|
* |
74
|
|
|
* [--no_posts=<no_posts>] |
75
|
|
|
* : Restrict to users who don't have any posts. |
76
|
|
|
* --- |
77
|
|
|
* default: false |
78
|
|
|
* options: |
79
|
|
|
* - true |
80
|
|
|
* - false |
81
|
|
|
* --- |
82
|
|
|
* |
83
|
|
|
* [--no_post_post_types=<no_post_post_types>] |
84
|
|
|
* : Can be used only when --no_posts=true. Restrict to users who don't have any posts of the comma separated list of post types. You can use built in as well as custom post types. |
85
|
|
|
* --- |
86
|
|
|
* default: post |
87
|
|
|
* --- |
88
|
|
|
* |
89
|
|
|
* [--limit_to=<limit_to>] |
90
|
|
|
* : Limits the number of users to be deleted. |
91
|
|
|
* --- |
92
|
|
|
* default: 0 |
93
|
|
|
* --- |
94
|
|
|
* |
95
|
|
|
* [--post_reassign=<post_reassign>] |
96
|
|
|
* : Whether reassign the posts of users that are going to be deleted. |
97
|
|
|
* --- |
98
|
|
|
* default: false |
99
|
|
|
* options: |
100
|
|
|
* - true |
101
|
|
|
* - false |
102
|
|
|
* --- |
103
|
|
|
* |
104
|
|
|
* [--reassign_user_id=<reassign_user_id>] |
105
|
|
|
* : Can be used only when --post_reassign=true. Reassign the posts of users going to get deleted to this user id. |
106
|
|
|
* |
107
|
|
|
* ## EXAMPLES |
108
|
|
|
* |
109
|
|
|
* # Delete all users and their posts with user meta key status and value spam. |
110
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam |
111
|
|
|
* Success: Deleted 10 users with the selected user meta |
112
|
|
|
* |
113
|
|
|
* # Delete all users and their posts with user meta key status and value spam who are registered with in last 10 days. |
114
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam --registered_restrict=true --op=after --registered_days=10 |
115
|
|
|
* Success: Deleted 5 users with the selected user meta |
116
|
|
|
* |
117
|
|
|
* # Delete all users and their posts with user meta key status and value spam who are registered(more than 20 days old) older than 20 days. |
118
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam --registered_restrict=true --op=before --registered_days=20 |
119
|
|
|
* Success: Deleted 5 users with the selected user meta |
120
|
|
|
* |
121
|
|
|
* # Delete users with user meta key status and value spam, and reassign posts to another user. |
122
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam --post_reassign=true --reassign_user_id=243 |
123
|
|
|
* Success: Deleted 3 users with the selected user meta |
124
|
|
|
* |
125
|
|
|
* # Delete users with user meta key status and value spam where user does not have any post/product(custom post type) created. |
126
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam --no_posts=true --no_post_post_types=post,product |
127
|
|
|
* Success: Deleted 3 users with the selected user meta |
128
|
|
|
* |
129
|
|
|
* # Delete only 300 users with user meta key status and value spam. |
130
|
|
|
* $ wp bulk-delete users by-user-meta --key=status --value=spam --limit_to=300 |
131
|
|
|
* Success: Deleted 300 users with the selected user meta |
132
|
|
|
* |
133
|
|
|
* @subcommand by-user-meta |
134
|
|
|
* |
135
|
|
|
* @param array $args Arguments to be supplied. |
136
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
*/ |
140
|
|
|
public function by_user_meta( $args, $assoc_args ) { |
141
|
|
|
$module = new DeleteUsersByUserMetaModule(); |
142
|
|
|
|
143
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
144
|
|
|
|
145
|
|
|
\WP_CLI::success( $message ); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Delete user by user role. |
150
|
|
|
* |
151
|
|
|
* ## OPTIONS |
152
|
|
|
* |
153
|
|
|
* --roles=<roles> |
154
|
|
|
* : Comma separated list of user roles from which users should be deleted. |
155
|
|
|
* |
156
|
|
|
* [--registered_restrict=<registered_restrict>] |
157
|
|
|
* : Restricts users deletion with registration date filter. |
158
|
|
|
* --- |
159
|
|
|
* default: false |
160
|
|
|
* options: |
161
|
|
|
* - true |
162
|
|
|
* - false |
163
|
|
|
* --- |
164
|
|
|
* |
165
|
|
|
* [--op=<op>] |
166
|
|
|
* : Can be used only when --registered_restrict=true. Restricts users deletion with registered date older than(before) or in the last(after) filter. |
167
|
|
|
* --- |
168
|
|
|
* options: |
169
|
|
|
* - before |
170
|
|
|
* - after |
171
|
|
|
* --- |
172
|
|
|
* |
173
|
|
|
* [--registered_days=<registered_days>] |
174
|
|
|
* : Restricts users deletion with registration date filter. |
175
|
|
|
* --- |
176
|
|
|
* default: 0 |
177
|
|
|
* --- |
178
|
|
|
* |
179
|
|
|
* [--no_posts=<no_posts>] |
180
|
|
|
* : Restrict to users who don't have any posts. |
181
|
|
|
* --- |
182
|
|
|
* default: false |
183
|
|
|
* options: |
184
|
|
|
* - true |
185
|
|
|
* - false |
186
|
|
|
* --- |
187
|
|
|
* |
188
|
|
|
* [--no_post_post_types=<no_post_post_types>] |
189
|
|
|
* : Can be used only when --no_posts=true. Restrict to users who don't have any posts of the comma separated list of post types. You can use built in as well as custom post types. |
190
|
|
|
* --- |
191
|
|
|
* default: post |
192
|
|
|
* --- |
193
|
|
|
* |
194
|
|
|
* [--limit_to=<limit_to>] |
195
|
|
|
* : Limits the number of users to be deleted. |
196
|
|
|
* --- |
197
|
|
|
* default: 0 |
198
|
|
|
* --- |
199
|
|
|
* |
200
|
|
|
* [--post_reassign=<post_reassign>] |
201
|
|
|
* : Whether reassign the posts of users that are going to be deleted. |
202
|
|
|
* --- |
203
|
|
|
* default: false |
204
|
|
|
* options: |
205
|
|
|
* - true |
206
|
|
|
* - false |
207
|
|
|
* --- |
208
|
|
|
* |
209
|
|
|
* [--reassign_user_id=<reassign_user_id>] |
210
|
|
|
* : Can be used only when --post_reassign=true. Reassign the posts of users going to get deleted to this user id. |
211
|
|
|
* |
212
|
|
|
* ## EXAMPLES |
213
|
|
|
* |
214
|
|
|
* # Delete all users and their posts with subscriber role. |
215
|
|
|
* $ wp bulk-delete users by-user-role --roles=subscriber |
216
|
|
|
* Success: Deleted 10 users from the selected roles |
217
|
|
|
* |
218
|
|
|
* # Delete all users and their posts with subscriber or editor roles who are registered with in last 10 days. |
219
|
|
|
* $ wp bulk-delete users by-user-role --roles=subscriber,editor --registered_restrict=true --op=after --registered_days=10 |
220
|
|
|
* Success: Deleted 5 users from the selected roles |
221
|
|
|
* |
222
|
|
|
* # Delete all users and their posts with subscriber or editor roles who are registered(more than 20 days old) older than 20 days. |
223
|
|
|
* $ wp bulk-delete users by-user-role --roles=subscriber,editor --registered_restrict=true --op=before --registered_days=20 |
224
|
|
|
* Success: Deleted 5 users from the selected roles |
225
|
|
|
* |
226
|
|
|
* # Delete users(retaining their posts) with author or contributor roles and reassign posts to another user. |
227
|
|
|
* $ wp bulk-delete users by-user-role --roles=author,contributor --post_reassign=true --reassign_user_id=243 |
228
|
|
|
* Success: Deleted 3 users from the selected roles |
229
|
|
|
* |
230
|
|
|
* # Delete users with administrator role where user does not have any post/product(custom post type) created. |
231
|
|
|
* $ wp bulk-delete users by-user-role --roles=administrator --no_posts=true --no_post_post_types=post,product |
232
|
|
|
* Success: Deleted 3 users from the selected roles |
233
|
|
|
* |
234
|
|
|
* # Delete 300 users with editor or subscriber role. |
235
|
|
|
* $ wp bulk-delete users by-user-role --roles=editor,subscriber --limit_to=300 |
236
|
|
|
* Success: Deleted 300 users from the selected roles |
237
|
|
|
* |
238
|
|
|
* @subcommand by-user-role |
239
|
|
|
* |
240
|
|
|
* @param array $args Arguments to be supplied. |
241
|
|
|
* @param array $assoc_args Associative arguments to be supplied. |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
*/ |
245
|
|
|
public function by_user_role( $args, $assoc_args ) { |
246
|
|
|
$module = new DeleteUsersByUserRoleModule(); |
247
|
|
|
|
248
|
|
|
$message = $module->process_cli_request( $assoc_args ); |
249
|
|
|
|
250
|
|
|
\WP_CLI::success( $message ); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
|
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