|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Utility functions for displaying form. |
|
4
|
|
|
* |
|
5
|
|
|
* @since 5.5 |
|
6
|
|
|
* |
|
7
|
|
|
* @author Sudar |
|
8
|
|
|
* |
|
9
|
|
|
* @package BulkDelete\Ui |
|
10
|
|
|
*/ |
|
11
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Render filtering table header. |
|
15
|
|
|
* |
|
16
|
|
|
* @since 5.5 |
|
17
|
|
|
*/ |
|
18
|
|
|
function bd_render_filtering_table_header() { |
|
19
|
|
|
?> |
|
20
|
|
|
<tr> |
|
21
|
|
|
<td colspan="2"> |
|
22
|
|
|
<h4><?php _e( 'Choose your filtering options', 'bulk-delete' ); ?></h4> |
|
23
|
|
|
</td> |
|
24
|
|
|
</tr> |
|
25
|
|
|
<?php |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Render "restrict by created date" dropdown. |
|
30
|
|
|
* |
|
31
|
|
|
* @since 5.5 |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $slug The slug to be used in field names. |
|
34
|
|
|
* @param string $item (optional) Item for which form is displayed. Default is 'posts'. |
|
35
|
|
|
*/ |
|
36
|
|
|
function bd_render_restrict_settings( $slug, $item = 'posts' ) { |
|
37
|
|
|
?> |
|
38
|
|
|
<tr> |
|
39
|
|
|
<td scope="row"> |
|
40
|
|
|
<input name="smbd_<?php echo $slug; ?>_restrict" id="smbd_<?php echo $slug; ?>_restrict" value="true" type="checkbox"> |
|
41
|
|
|
</td> |
|
42
|
|
|
<td> |
|
43
|
|
|
<?php printf( __( 'Only restrict to %s which are ', 'bulk-delete' ), $item );?> |
|
44
|
|
|
<select name="smbd_<?php echo $slug; ?>_op" id="smbd_<?php echo $slug; ?>_op" disabled> |
|
45
|
|
|
<option value="before"><?php _e( 'older than', 'bulk-delete' );?></option> |
|
46
|
|
|
<option value="after"><?php _e( 'posted within last', 'bulk-delete' );?></option> |
|
47
|
|
|
</select> |
|
48
|
|
|
<input type="number" name="smbd_<?php echo $slug; ?>_days" id="smbd_<?php echo $slug; ?>_days" class="screen-per-page" disabled value="0" min="0"><?php _e( 'days', 'bulk-delete' );?> |
|
49
|
|
|
</td> |
|
50
|
|
|
</tr> |
|
51
|
|
|
<?php |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Render "force delete" setting fields. |
|
56
|
|
|
* |
|
57
|
|
|
* @since 5.5 |
|
58
|
|
|
* |
|
59
|
|
|
* @param string $slug The slug to be used in field names. |
|
60
|
|
|
*/ |
|
61
|
|
|
function bd_render_delete_settings( $slug ) { |
|
62
|
|
|
?> |
|
63
|
|
|
<tr> |
|
64
|
|
|
<td scope="row" colspan="2" class="<?php if( $slug == 'sticky_post' ){ ?>sticky_force_delete<?php }?>"> |
|
65
|
|
|
<input name="smbd_<?php echo $slug; ?>_force_delete" value="false" type="radio" checked> <?php _e( 'Move to Trash', 'bulk-delete' ); ?> |
|
66
|
|
|
<input name="smbd_<?php echo $slug; ?>_force_delete" value="true" type="radio"> <?php _e( 'Delete permanently', 'bulk-delete' ); ?> |
|
67
|
|
|
</td> |
|
68
|
|
|
</tr> |
|
69
|
|
|
<?php |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Render "sticky option" setting fields. |
|
74
|
|
|
* |
|
75
|
|
|
* @since 6.0 |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $slug The slug to be used in field names. |
|
78
|
|
|
*/ |
|
79
|
|
|
function bd_render_sticky_settings( $slug ) { |
|
80
|
|
|
?> |
|
81
|
|
|
<tr> |
|
82
|
|
|
<td scope="row" colspan="2"> |
|
83
|
|
|
<input name="smbd_<?php echo $slug; ?>_sticky_option" value="hide" type="radio" checked> <?php _e( 'Remove Sticky', 'bulk-delete' ); ?> |
|
84
|
|
|
<input name="smbd_<?php echo $slug; ?>_sticky_option" value="show" type="radio"> <?php _e( 'Delete Post', 'bulk-delete' ); ?> |
|
85
|
|
|
</td> |
|
86
|
|
|
</tr> |
|
87
|
|
|
<?php |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Render the "private post" setting fields. |
|
92
|
|
|
* |
|
93
|
|
|
* @since 5.5 |
|
94
|
|
|
* |
|
95
|
|
|
* @param string $slug The slug to be used in field names. |
|
96
|
|
|
*/ |
|
97
|
|
|
function bd_render_private_post_settings( $slug ) { |
|
98
|
|
|
?> |
|
99
|
|
|
<tr> |
|
100
|
|
|
<td scope="row" colspan="2"> |
|
101
|
|
|
<input name="smbd_<?php echo $slug; ?>_private" value="false" type="radio" checked> <?php _e( 'Public posts', 'bulk-delete' ); ?> |
|
102
|
|
|
<input name="smbd_<?php echo $slug; ?>_private" value="true" type="radio"> <?php _e( 'Private Posts', 'bulk-delete' ); ?> |
|
103
|
|
|
</td> |
|
104
|
|
|
</tr> |
|
105
|
|
|
<?php |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Render the "limit" setting fields. |
|
110
|
|
|
* |
|
111
|
|
|
* @since 5.5 |
|
112
|
|
|
* |
|
113
|
|
|
* @param string $slug The slug to be used in field names. |
|
114
|
|
|
* @param string $item (Optional) Item type. Possible values are 'posts', 'pages', 'users' |
|
115
|
|
|
*/ |
|
116
|
|
|
function bd_render_limit_settings( $slug, $item = 'posts' ) { |
|
117
|
|
|
?> |
|
118
|
|
|
<tr> |
|
119
|
|
|
<td scope="row"> |
|
120
|
|
|
<input name="smbd_<?php echo $slug; ?>_limit" id="smbd_<?php echo $slug; ?>_limit" value="true" type="checkbox"> |
|
121
|
|
|
</td> |
|
122
|
|
|
<td> |
|
123
|
|
|
<?php _e( 'Only delete first ', 'bulk-delete' );?> |
|
124
|
|
|
<input type="number" name="smbd_<?php echo $slug; ?>_limit_to" id="smbd_<?php echo $slug; ?>_limit_to" class="screen-per-page" disabled value="0" min="0"> <?php echo $item;?>. |
|
125
|
|
|
<?php printf( __( 'Use this option if there are more than 1000 %s and the script times out.', 'bulk-delete' ), $item ); ?> |
|
126
|
|
|
</td> |
|
127
|
|
|
</tr> |
|
128
|
|
|
<?php |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Render cron setting fields. |
|
133
|
|
|
* |
|
134
|
|
|
* @since 5.5 |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $slug The slug to be used in field names. |
|
137
|
|
|
* @param string $addon_url Url for the pro addon. |
|
138
|
|
|
*/ |
|
139
|
|
|
function bd_render_cron_settings( $slug, $addon_url ) { |
|
140
|
|
|
$pro_class = 'bd-' . str_replace( '_', '-', $slug ) . '-pro'; |
|
141
|
|
|
?> |
|
142
|
|
|
<tr> |
|
143
|
|
|
<td scope="row" colspan="2"> |
|
144
|
|
|
<input name="smbd_<?php echo $slug; ?>_cron" value="false" type="radio" checked="checked"> <?php _e( 'Delete now', 'bulk-delete' ); ?> |
|
145
|
|
|
<input name="smbd_<?php echo $slug; ?>_cron" value="true" type="radio" id="smbd_<?php echo $slug; ?>_cron" disabled > <?php _e( 'Schedule', 'bulk-delete' ); ?> |
|
146
|
|
|
<input name="smbd_<?php echo $slug; ?>_cron_start" id="smbd_<?php echo $slug; ?>_cron_start" value="now" type="text" disabled><?php _e( 'repeat ', 'bulk-delete' );?> |
|
147
|
|
|
<select name="smbd_<?php echo $slug; ?>_cron_freq" id="smbd_<?php echo $slug; ?>_cron_freq" disabled> |
|
148
|
|
|
<option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
|
149
|
|
|
<?php |
|
150
|
|
|
$schedules = wp_get_schedules(); |
|
151
|
|
|
foreach ( $schedules as $key => $value ) { |
|
152
|
|
|
?> |
|
153
|
|
|
<option value="<?php echo $key; ?>"><?php echo $value['display']; ?></option> |
|
154
|
|
|
<?php } ?> |
|
155
|
|
|
</select> |
|
156
|
|
|
<span class="<?php echo sanitize_html_class( apply_filters( 'bd_pro_class', $pro_class, $slug ) ); ?>" style="color:red"><?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a href="<?php echo $addon_url; ?>">Buy now</a></span> |
|
157
|
|
|
</td> |
|
158
|
|
|
</tr> |
|
159
|
|
|
|
|
160
|
|
|
<tr> |
|
161
|
|
|
<td scope="row" colspan="2"> |
|
162
|
|
|
<?php _e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time', 'bulk-delete' );?> |
|
163
|
|
|
</td> |
|
164
|
|
|
</tr> |
|
165
|
|
|
<?php |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Render the submit button. |
|
170
|
|
|
* |
|
171
|
|
|
* @since 5.5 |
|
172
|
|
|
* |
|
173
|
|
|
* @param string $action The action attribute of the submit button. |
|
174
|
|
|
*/ |
|
175
|
|
|
function bd_render_submit_button( $action ) { |
|
176
|
|
|
?> |
|
177
|
|
|
<p class="submit"> |
|
178
|
|
|
<button type="submit" name="bd_action" value="<?php echo esc_attr( $action ); ?>" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ); ?>»</button> |
|
179
|
|
|
</p> |
|
180
|
|
|
<?php |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Render the post type dropdown. |
|
185
|
|
|
* |
|
186
|
|
|
* @since 5.5 |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $slug The slug to be used in field names. |
|
189
|
|
|
*/ |
|
190
|
|
|
function bd_render_post_type_dropdown( $slug ) { |
|
191
|
|
|
$types = bd_get_post_types(); |
|
192
|
|
|
?> |
|
193
|
|
|
<tr> |
|
194
|
|
|
<td scope="row" > |
|
195
|
|
|
<select class="select2" name="smbd_<?php echo esc_attr( $slug ); ?>_post_type"> |
|
196
|
|
|
<?php foreach ( $types as $type ) : ?> |
|
197
|
|
|
<option value="<?php echo esc_attr( $type->name ); ?>"> |
|
198
|
|
|
<?php echo esc_html( $type->labels->singular_name . ' (' . $type->name . ')' ); ?> |
|
199
|
|
|
</option> |
|
200
|
|
|
<?php endforeach; ?> |
|
201
|
|
|
</select> |
|
202
|
|
|
</td> |
|
203
|
|
|
</tr> |
|
204
|
|
|
<?php |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Render the user role dropdown. |
|
209
|
|
|
* |
|
210
|
|
|
* @since 5.5 |
|
211
|
|
|
* |
|
212
|
|
|
* @param string $slug The slug to be used in field names. |
|
213
|
|
|
*/ |
|
214
|
|
|
function bd_render_user_role_dropdown( $slug ) { |
|
215
|
|
|
$users_count = count_users(); |
|
216
|
|
|
?> |
|
217
|
|
|
<tr> |
|
218
|
|
|
<td> |
|
219
|
|
|
<select class="select2" name="smbd_<?php echo esc_attr( $slug ); ?>_post_type"> |
|
220
|
|
|
<?php foreach ( $users_count['avail_roles'] as $role => $count ) {?> |
|
221
|
|
|
<option value="<?php echo $role; ?>"> |
|
222
|
|
|
<?php echo $role; ?> (<?php echo $count . ' '; _e( 'Users', 'bulk-delete' ); ?>) |
|
223
|
|
|
</option> |
|
224
|
|
|
<?php }?> |
|
225
|
|
|
</select> |
|
226
|
|
|
</td> |
|
227
|
|
|
</tr> |
|
228
|
|
|
<?php |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
/** |
|
232
|
|
|
* Get the list of post type objects that will be used in filters. |
|
233
|
|
|
* |
|
234
|
|
|
* @since 5.6.0 |
|
235
|
|
|
* |
|
236
|
|
|
* @return \WP_Post_Type[] List of post type objects. |
|
237
|
|
|
*/ |
|
238
|
|
|
function bd_get_post_types() { |
|
239
|
|
|
$custom_types = get_post_types( array( '_builtin' => false ), 'objects' ); |
|
240
|
|
|
|
|
241
|
|
|
$builtin_types = array( |
|
242
|
|
|
'post' => get_post_type_object( 'post' ), |
|
243
|
|
|
'page' => get_post_type_object( 'page' ), |
|
244
|
|
|
); |
|
245
|
|
|
|
|
246
|
|
|
return array_merge( $builtin_types, $custom_types ); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
/** |
|
250
|
|
|
* Render the post status filter. |
|
251
|
|
|
* |
|
252
|
|
|
* @since 5.6.0 |
|
253
|
|
|
* |
|
254
|
|
|
* @param string $slug The slug to be used in field names. |
|
255
|
|
|
* @param string $selected Default selected status. |
|
256
|
|
|
*/ |
|
257
|
|
|
function bd_render_post_status_filter( $slug, $selected = 'publish' ) { |
|
258
|
|
|
$post_statuses = bd_get_post_statuses(); |
|
259
|
|
|
|
|
260
|
|
|
foreach ( $post_statuses as $key => $value ) { |
|
261
|
|
|
?> |
|
262
|
|
|
<tr> |
|
263
|
|
|
<td> |
|
264
|
|
|
<label> |
|
265
|
|
|
<input name="smbd_<?php echo esc_attr( $slug ); ?>_post_status[]" type="checkbox" |
|
266
|
|
|
value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $selected ); ?>> |
|
267
|
|
|
|
|
268
|
|
|
<?php echo __( 'All', 'bulk-delete' ), ' ', esc_html( $value->label ), ' ', __( 'Posts', 'bulk-delete' ); ?> |
|
269
|
|
|
</label> |
|
270
|
|
|
</td> |
|
271
|
|
|
</tr> |
|
272
|
|
|
<?php |
|
273
|
|
|
} |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Get the list of post statuses. |
|
278
|
|
|
* |
|
279
|
|
|
* This includes all custom post status, but excludes built-in private posts. |
|
280
|
|
|
* |
|
281
|
|
|
* @since 5.6.0 |
|
282
|
|
|
* |
|
283
|
|
|
* @return array List of post status objects. |
|
284
|
|
|
*/ |
|
285
|
|
|
function bd_get_post_statuses() { |
|
286
|
|
|
$post_statuses = get_post_stati( array(), 'object' ); |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* List of post statuses that should be excluded from post status filter. |
|
290
|
|
|
* |
|
291
|
|
|
* @since 5.6.0 |
|
292
|
|
|
* |
|
293
|
|
|
* @param array $post_statuses List of post statuses. |
|
294
|
|
|
*/ |
|
295
|
|
|
$exclude_post_statuses = apply_filters( 'bd_exclude_post_statuses', array( 'inherit', 'trash', 'auto-draft' ) ); |
|
296
|
|
|
|
|
297
|
|
|
foreach ( $exclude_post_statuses as $key ) { |
|
298
|
|
|
unset( $post_statuses[ $key ] ); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* List of post statuses that are displayed in the post status filter. |
|
303
|
|
|
* |
|
304
|
|
|
* @since 5.6.0 |
|
305
|
|
|
* |
|
306
|
|
|
* @param array $post_statuses List of post statuses. |
|
307
|
|
|
*/ |
|
308
|
|
|
return apply_filters( 'bd_post_statuses', $post_statuses ); |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
/** |
|
312
|
|
|
* Generate help tooltip and append it to existing markup. |
|
313
|
|
|
* |
|
314
|
|
|
* @param string $markup Existing markup. |
|
315
|
|
|
* @param string $content Tooltip content. |
|
316
|
|
|
* |
|
317
|
|
|
* @return string Markup with tooltip markup appended to it. |
|
318
|
|
|
*/ |
|
319
|
|
|
function bd_generate_help_tooltip( $markup, $content ) { |
|
320
|
|
|
if ( empty( $content ) ) { |
|
321
|
|
|
return $markup; |
|
322
|
|
|
} |
|
323
|
|
|
|
|
324
|
|
|
$tooltip = '<span alt="f223" class="bd-help dashicons dashicons-editor-help" title="' . $content . '"></span>'; |
|
325
|
|
|
|
|
326
|
|
|
return $markup . $tooltip; |
|
327
|
|
|
} |
|
328
|
|
|
|