1
|
|
|
<?php |
2
|
|
|
namespace BulkWP\BulkDelete\Core\Metas\Modules; |
3
|
|
|
|
4
|
|
|
use BulkWP\BulkDelete\Core\Metas\MetasModule; |
5
|
|
|
|
6
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Delete User Meta. |
10
|
|
|
* |
11
|
|
|
* @since 6.0.0 |
12
|
|
|
*/ |
13
|
|
|
class DeleteUserMetaModule extends MetasModule { |
14
|
|
|
protected function initialize() { |
15
|
|
|
$this->field_slug = 'user_comment'; |
16
|
|
|
$this->meta_box_slug = 'bd-user-meta'; |
17
|
|
|
$this->action = 'delete_user_comment'; |
18
|
|
|
$this->cron_hook = 'do-bulk-delete-user-meta'; |
19
|
|
|
$this->messages = array( |
20
|
|
|
'box_label' => __( 'Bulk Delete User Meta', 'bulk-delete' ), |
21
|
|
|
'scheduled' => __( 'User meta fields from the users with the selected criteria are scheduled for deletion.', 'bulk-delete' ), |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Render the Modules. |
27
|
|
|
* |
28
|
|
|
* @return void |
29
|
|
|
*/ |
30
|
|
|
public function render() { |
31
|
|
|
?> |
32
|
|
|
<!-- User Meta box start--> |
33
|
|
|
<fieldset class="options"> |
34
|
|
|
<h4><?php _e( 'Select the user role whose user meta fields you want to delete', 'bulk-delete' ); ?></h4> |
35
|
|
|
<table class="optiontable"> |
36
|
|
|
<?php |
37
|
|
|
$users_count = count_users(); |
38
|
|
|
foreach ( $users_count['avail_roles'] as $role => $count ) { |
39
|
|
|
?> |
40
|
|
|
<tr> |
41
|
|
|
<td> |
42
|
|
|
<input name="smbd_um_role" value = "<?php echo $role; ?>" type = "radio" <?php checked( $role, 'administrator' ); ?>> |
43
|
|
|
<label for="smbd_um_role"><?php echo $role; ?> (<?php echo $count . ' '; _e( 'Users', 'bulk-delete' ); ?>)</label> |
44
|
|
|
</td> |
45
|
|
|
</tr> |
46
|
|
|
<?php |
47
|
|
|
} |
48
|
|
|
?> |
49
|
|
|
</table> |
50
|
|
|
|
51
|
|
|
<h4><?php _e( 'Choose your user meta field settings', 'bulk-delete' ); ?></h4> |
52
|
|
|
<table class="optiontable"> |
53
|
|
|
<tr> |
54
|
|
|
<td> |
55
|
|
|
<input name="smbd_um_use_value" value="false" type="radio" checked> |
56
|
|
|
<label for="smbd_um_use_value"><?php echo __( 'Delete based on user meta key name only', 'bulk-delete' ); ?></label> |
57
|
|
|
</td> |
58
|
|
|
</tr> |
59
|
|
|
|
60
|
|
|
<tr> |
61
|
|
|
<td> |
62
|
|
|
<input name="smbd_um_use_value" id="smbd_um_use_value" value="true" type="radio" disabled> |
63
|
|
|
<label for="smbd_um_use_value"><?php echo __( 'Delete based on user meta key name and value', 'bulk-delete' ); ?></label> |
64
|
|
|
<span class="bd-um-pro" style="color:red; vertical-align: middle;"> |
65
|
|
|
<?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href = "http://bulkwp.com/addons/bulk-delete-user-meta/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-m-u" target="_blank">Buy now</a> |
66
|
|
|
</span> |
67
|
|
|
</td> |
68
|
|
|
</tr> |
69
|
|
|
|
70
|
|
|
<tr> |
71
|
|
|
<td> |
72
|
|
|
<label for="smbd_um_key"><?php _e( 'User Meta Key ', 'bulk-delete' ); ?></label> |
73
|
|
|
<input name="smbd_um_key" id="smbd_um_key" placeholder="<?php _e( 'Meta Key', 'bulk-delete' ); ?>"> |
74
|
|
|
</td> |
75
|
|
|
</tr> |
76
|
|
|
</table> |
77
|
|
|
<?php |
78
|
|
|
/** |
79
|
|
|
* Add more fields to the delete user meta field form. |
80
|
|
|
* This hook can be used to add more fields to the delete user meta field form. |
81
|
|
|
* |
82
|
|
|
* @since 5.4 |
83
|
|
|
*/ |
84
|
|
|
do_action( 'bd_delete_user_meta_form' ); |
85
|
|
|
?> |
86
|
|
|
<table class="optiontable"> |
87
|
|
|
<tr> |
88
|
|
|
<td> |
89
|
|
|
<h4><?php _e( 'Choose your deletion options', 'bulk-delete' ); ?></h4> |
90
|
|
|
</td> |
91
|
|
|
</tr> |
92
|
|
|
|
93
|
|
|
<tr> |
94
|
|
|
<td> |
95
|
|
|
<input name="smbd_um_limit" id="smbd_um_limit" value = "true" type = "checkbox"> |
96
|
|
|
<?php _e( 'Only delete user meta field from first ', 'bulk-delete' );?> |
97
|
|
|
<input type ="textbox" name="smbd_um_limit_to" id="smbd_um_limit_to" disabled value ="0" maxlength="4" size="4"><?php _e( 'users.', 'bulk-delete' );?> |
98
|
|
|
<?php _e( 'Use this option if there are more than 1000 users and the script times out.', 'bulk-delete' ) ?> |
99
|
|
|
</td> |
100
|
|
|
</tr> |
101
|
|
|
|
102
|
|
|
<tr> |
103
|
|
|
<td> |
104
|
|
|
<input name="smbd_um_cron" value = "false" type = "radio" checked="checked"> <?php _e( 'Delete now', 'bulk-delete' ); ?> |
105
|
|
|
<input name="smbd_um_cron" value = "true" type = "radio" id = "smbd_um_cron" disabled > <?php _e( 'Schedule', 'bulk-delete' ); ?> |
106
|
|
|
<input name="smbd_um_cron_start" id = "smbd_um_cron_start" value = "now" type = "text" disabled><?php _e( 'repeat ', 'bulk-delete' );?> |
107
|
|
|
<select name="smbd_um_cron_freq" id = "smbd_um_cron_freq" disabled> |
108
|
|
|
<option value = "-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
109
|
|
|
<?php |
110
|
|
|
$schedules = wp_get_schedules(); |
111
|
|
|
foreach ( $schedules as $key => $value ) { |
112
|
|
|
?> |
113
|
|
|
<option value = "<?php echo $key; ?>"><?php echo $value['display']; ?></option> |
114
|
|
|
<?php |
115
|
|
|
} |
116
|
|
|
?> |
117
|
|
|
</select> |
118
|
|
|
<span class="bd-um-pro" style="color:red"> |
119
|
|
|
<?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href = "http://bulkwp.com/addons/bulk-delete-user-meta/?utm_source=wpadmin&utm_campaign=BulkDelete&utm_medium=buynow&utm_content=bd-m-u">Buy now</a> |
120
|
|
|
</span> |
121
|
|
|
</td> |
122
|
|
|
</tr> |
123
|
|
|
|
124
|
|
|
<tr> |
125
|
|
|
<td> |
126
|
|
|
<?php _e( 'Enter time in Y-m-d H:i:s format or enter now to use current time', 'bulk-delete' );?> |
127
|
|
|
</td> |
128
|
|
|
</tr> |
129
|
|
|
|
130
|
|
|
</table> |
131
|
|
|
</fieldset> |
132
|
|
|
|
133
|
|
|
<p> |
134
|
|
|
<button type="submit" name="bd_action" value="delete_meta_user" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ) ?>»</button> |
135
|
|
|
</p> |
136
|
|
|
<!-- User Meta box end--> |
137
|
|
|
<?php |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
protected function convert_user_input_to_options( $request, $options ) { |
141
|
|
|
$options['post_type'] = esc_sql( bd_array_get( $request, 'smbd_' . $this->field_slug . '_post_type', 'post' ) ); |
142
|
|
|
|
143
|
|
|
$options['use_value'] = bd_array_get_bool( $request, 'smbd_' . $this->field_slug . '_use_value', false ); |
144
|
|
|
$options['meta_key'] = esc_sql( bd_array_get( $request, 'smbd_' . $this->field_slug . '_meta_key', '' ) ); |
145
|
|
|
|
146
|
|
|
return $options; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function delete( $options ) { |
150
|
|
|
$args = array( |
151
|
|
|
'post_type' => $options['post_type'], |
152
|
|
|
); |
153
|
|
|
|
154
|
|
|
if ( $options['limit_to'] > 0 ) { |
155
|
|
|
$args['number'] = $options['limit_to']; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$op = $options['date_op']; |
159
|
|
|
$days = $options['days']; |
160
|
|
|
|
161
|
|
|
if ( $options['restrict'] ) { |
162
|
|
|
$args['date_query'] = array( |
163
|
|
|
array( |
164
|
|
|
'column' => 'comment_date', |
165
|
|
|
$op => "{$days} day ago", |
166
|
|
|
), |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
if ( $options['use_value'] ) { |
171
|
|
|
$args['meta_query'] = apply_filters( 'bd_delete_comment_meta_query', array(), $options ); |
172
|
|
|
} else { |
173
|
|
|
$args['meta_key'] = $options['meta_key']; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$meta_deleted = 0; |
177
|
|
|
$comments = get_comments( $args ); |
178
|
|
|
|
179
|
|
|
foreach ( $comments as $comment ) { |
180
|
|
|
if ( delete_comment_meta( $comment->comment_ID, $options['meta_key'] ) ) { |
181
|
|
|
$meta_deleted ++; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
return $meta_deleted; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function filter_js_array( $js_array ) { |
189
|
|
|
$js_array['dt_iterators'][] = '_' . $this->field_slug; |
190
|
|
|
$js_array['validators'][ $this->action ] = 'noValidation'; |
191
|
|
|
|
192
|
|
|
$js_array['pre_action_msg'][ $this->action ] = 'deleteCMWarning'; |
193
|
|
|
$js_array['msg']['deleteCMWarning'] = __( 'Are you sure you want to delete all the comment meta fields that match the selected filters?', 'bulk-delete' ); |
194
|
|
|
|
195
|
|
|
return $js_array; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
protected function get_success_message( $items_deleted ) { |
199
|
|
|
/* translators: 1 Number of posts deleted */ |
200
|
|
|
return _n( 'Deleted comment meta field from %d comment', 'Deleted comment meta field from %d comments', $items_deleted, 'bulk-delete' ); |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
|