1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BulkWP\BulkDelete\Core\Users\Modules; |
4
|
|
|
|
5
|
|
|
use BulkWP\BulkDelete\Core\Users\UsersModule; |
6
|
|
|
|
7
|
1 |
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Bulk Delete Users by User Meta. |
11
|
|
|
* |
12
|
|
|
* @since 5.5 |
13
|
|
|
* @since 6.0.0 Renamed to DeleteUsersByUserMetaModule. |
14
|
|
|
*/ |
15
|
|
|
class DeleteUsersByUserMetaModule extends UsersModule { |
16
|
|
|
/** |
17
|
|
|
* Initialize and setup variables. |
18
|
|
|
* |
19
|
|
|
* @since 5.5 |
20
|
|
|
*/ |
21
|
52 |
|
protected function initialize() { |
22
|
52 |
|
$this->item_type = 'users'; |
23
|
52 |
|
$this->field_slug = 'u_meta'; |
24
|
52 |
|
$this->meta_box_slug = 'bd_users_by_meta'; |
25
|
52 |
|
$this->action = 'delete_users_by_meta'; |
26
|
52 |
|
$this->cron_hook = 'do-bulk-delete-users-by-meta'; |
27
|
52 |
|
$this->scheduler_url = 'https://bulkwp.com/addons/scheduler-for-deleting-users-by-meta/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-u-ma'; |
28
|
52 |
|
$this->messages = array( |
29
|
52 |
|
'box_label' => __( 'By User Meta', 'bulk-delete' ), |
30
|
52 |
|
'scheduled' => __( 'Users from with the selected user meta are scheduled for deletion.', 'bulk-delete' ), |
31
|
52 |
|
'cron_label' => __( 'Delete Users by User Meta', 'bulk-delete' ), |
32
|
52 |
|
'confirm_deletion' => __( 'Are you sure you want to delete all the users from the selected user meta?', 'bulk-delete' ), |
33
|
52 |
|
'confirm_scheduled' => __( 'Are you sure you want to schedule deletion for all the users from the selected user meta?', 'bulk-delete' ), |
34
|
|
|
/* translators: 1 Number of users deleted */ |
35
|
52 |
|
'deleted_one' => __( 'Deleted %d user with the selected user meta', 'bulk-delete' ), |
36
|
|
|
/* translators: 1 Number of users deleted */ |
37
|
52 |
|
'deleted_multiple' => __( 'Deleted %d users with the selected user meta', 'bulk-delete' ), |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Render delete users box. |
43
|
|
|
* |
44
|
|
|
* @since 5.5 |
45
|
|
|
*/ |
46
|
|
|
public function render() { |
47
|
|
|
?> |
48
|
|
|
<!-- Users Start--> |
49
|
|
|
<h4><?php _e( 'Select the user meta from which you want to delete users', 'bulk-delete' ); ?></h4> |
50
|
|
|
|
51
|
|
|
<fieldset class="options"> |
52
|
|
|
<table class="optiontable"> |
53
|
|
|
<select name="smbd_u_meta_key" class="enhanced-dropdown"> |
54
|
|
|
<?php |
55
|
|
|
$meta_keys = $this->get_unique_user_meta_keys(); |
56
|
|
|
foreach ( $meta_keys as $meta_key ) { |
57
|
|
|
printf( '<option value="%s">%s</option>', esc_attr( $meta_key ), esc_html( $meta_key ) ); |
58
|
|
|
} |
59
|
|
|
?> |
60
|
|
|
</select> |
61
|
|
|
|
62
|
|
|
<select name="smbd_u_meta_compare"> |
63
|
|
|
<option value="=">Equals to</option> |
64
|
|
|
<option value="!=">Not Equals to</option> |
65
|
|
|
<option value=">">Greater than</option> |
66
|
|
|
<option value=">=">Greater than or equals to</option> |
67
|
|
|
<option value="<">Less than</option> |
68
|
|
|
<option value="<=">Less than or equals to</option> |
69
|
|
|
<option value="LIKE">Contains</option> |
70
|
|
|
<option value="NOT LIKE">Not Contains</option> |
71
|
|
|
<option value="STARTS WITH">Starts with</option> |
72
|
|
|
<option value="ENDS WITH">Ends with</option> |
73
|
|
|
</select> |
74
|
|
|
<input type="text" name="smbd_u_meta_value" id="smbd_u_meta_value" placeholder="<?php _e( 'Meta Value', 'bulk-delete' ); ?>"> |
75
|
|
|
|
76
|
|
|
</table> |
77
|
|
|
|
78
|
|
|
<p> |
79
|
|
|
<?php _e( 'If you want to check for null values, then leave the value column blank', 'bulk-delete' ); ?> |
80
|
|
|
</p> |
81
|
|
|
|
82
|
|
|
<table class="optiontable"> |
83
|
|
|
<?php |
84
|
|
|
$this->render_filtering_table_header(); |
85
|
|
|
$this->render_user_login_restrict_settings(); |
86
|
|
|
$this->render_user_with_no_posts_settings(); |
87
|
|
|
$this->render_limit_settings(); |
88
|
|
|
$this->render_post_reassign_settings(); |
89
|
|
|
$this->render_cron_settings(); |
90
|
|
|
?> |
91
|
|
|
</table> |
92
|
|
|
</fieldset> |
93
|
|
|
<!-- Users end--> |
94
|
|
|
|
95
|
|
|
<?php |
96
|
|
|
$this->render_submit_button(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Process user input and create metabox options. |
101
|
|
|
* |
102
|
|
|
* @param array $request Request array. |
103
|
|
|
* @param array $options User options. |
104
|
|
|
* |
105
|
|
|
* @return array User options. |
106
|
|
|
*/ |
107
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
108
|
|
|
$options['meta_key'] = bd_array_get( $request, 'smbd_u_meta_key' ); |
109
|
|
|
$options['meta_compare'] = bd_array_get( $request, 'smbd_u_meta_compare', '=' ); |
110
|
|
|
$options['meta_value'] = bd_array_get( $request, 'smbd_u_meta_value' ); |
111
|
|
|
|
112
|
|
|
switch ( strtolower( trim( $options['meta_compare'] ) ) ) { |
113
|
|
|
case 'starts with': |
114
|
|
|
$options['meta_compare'] = 'REGEXP'; |
115
|
|
|
$options['meta_value'] = '^' . $options['meta_value']; |
116
|
|
|
break; |
117
|
|
|
case 'ends with': |
118
|
|
|
$options['meta_compare'] = 'REGEXP'; |
119
|
|
|
$options['meta_value'] = $options['meta_value'] . '$'; |
120
|
|
|
break; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return $options; |
124
|
|
|
} |
125
|
|
|
|
126
|
52 |
|
protected function build_query( $options ) { |
127
|
|
|
$query = array( |
128
|
|
|
'meta_query' => array( |
129
|
|
|
array( |
130
|
52 |
|
'key' => $options['meta_key'], |
131
|
52 |
|
'value' => $options['meta_value'], |
132
|
52 |
|
'compare' => $options['meta_compare'], |
133
|
|
|
), |
134
|
|
|
), |
135
|
|
|
); |
136
|
|
|
|
137
|
52 |
|
if ( $options['limit_to'] > 0 ) { |
138
|
16 |
|
$query['number'] = $options['limit_to']; |
139
|
|
|
} |
140
|
|
|
|
141
|
52 |
|
$date_query = $this->get_date_query( $options ); |
142
|
|
|
|
143
|
52 |
|
if ( ! empty( $date_query ) ) { |
144
|
21 |
|
$query['date_query'] = $date_query; |
145
|
|
|
} |
146
|
|
|
|
147
|
52 |
|
return $query; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
protected function append_to_js_array( $js_array ) { |
151
|
|
|
$js_array['validators'][ $this->action ] = 'noValidation'; |
152
|
|
|
|
153
|
|
|
return $js_array; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
// phpcs:ignore Squiz.Commenting.FunctionComment.Missing |
157
|
|
|
protected function prepare_cli_input( $input ) { |
158
|
|
|
// Handle multiple post types for no posts filter. |
159
|
|
|
$input['no_post_post_types'] = explode( ',', $input['no_post_post_types'] ); |
160
|
|
|
|
161
|
|
|
return parent::prepare_cli_input( $input ); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|