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
|
|
|
* Get the list of post type objects that will be used in filters. |
185
|
|
|
* |
186
|
|
|
* @since 5.6.0 |
187
|
|
|
* |
188
|
|
|
* @return \WP_Post_Type[] List of post type objects. |
189
|
|
|
*/ |
190
|
|
|
function bd_get_post_types() { |
191
|
|
|
$custom_types = get_post_types( array( '_builtin' => false ), 'objects' ); |
192
|
|
|
|
193
|
|
|
$builtin_types = array( |
194
|
|
|
'post' => get_post_type_object( 'post' ), |
195
|
|
|
'page' => get_post_type_object( 'page' ), |
196
|
|
|
); |
197
|
|
|
|
198
|
|
|
return array_merge( $builtin_types, $custom_types ); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* Render Post type dropdown. |
203
|
|
|
* |
204
|
|
|
* @param string $field_slug Field slug. |
205
|
|
|
*/ |
206
|
|
|
function bd_render_post_type_dropdown( $field_slug ) { |
207
|
|
|
$types = bd_get_post_types(); |
208
|
|
|
?> |
209
|
|
|
<tr> |
210
|
|
|
<td scope="row" > |
211
|
|
|
<select class="select2" name="smbd_<?php echo esc_attr( $field_slug ); ?>_post_type"> |
212
|
|
|
<?php foreach ( $types as $type ) : ?> |
213
|
|
|
<option value="<?php echo esc_attr( $type->name ); ?>"> |
214
|
|
|
<?php echo esc_html( $type->labels->singular_name . ' (' . $type->name . ')' ); ?> |
215
|
|
|
</option> |
216
|
|
|
<?php endforeach; ?> |
217
|
|
|
</select> |
218
|
|
|
</td> |
219
|
|
|
</tr> |
220
|
|
|
<?php |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* Render the post status filter. |
225
|
|
|
* |
226
|
|
|
* @since 5.6.0 |
227
|
|
|
* |
228
|
|
|
* @param string $slug The slug to be used in field names. |
229
|
|
|
* @param string $selected Default selected status. |
230
|
|
|
*/ |
231
|
|
|
function bd_render_post_status_filter( $slug, $selected = 'publish' ) { |
232
|
|
|
$post_statuses = bd_get_post_statuses(); |
233
|
|
|
|
234
|
|
|
foreach ( $post_statuses as $key => $value ) { |
235
|
|
|
?> |
236
|
|
|
<tr> |
237
|
|
|
<td> |
238
|
|
|
<label> |
239
|
|
|
<input name="smbd_<?php echo esc_attr( $slug ); ?>_post_status[]" type="checkbox" |
240
|
|
|
value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $selected ); ?>> |
241
|
|
|
|
242
|
|
|
<?php echo __( 'All', 'bulk-delete' ), ' ', esc_html( $value->label ), ' ', __( 'Posts', 'bulk-delete' ); ?> |
243
|
|
|
</label> |
244
|
|
|
</td> |
245
|
|
|
</tr> |
246
|
|
|
<?php |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get the list of post statuses. |
252
|
|
|
* |
253
|
|
|
* This includes all custom post status, but excludes built-in private posts. |
254
|
|
|
* |
255
|
|
|
* @since 5.6.0 |
256
|
|
|
* |
257
|
|
|
* @return array List of post status objects. |
258
|
|
|
*/ |
259
|
|
|
function bd_get_post_statuses() { |
260
|
|
|
$post_statuses = get_post_stati( array(), 'object' ); |
261
|
|
|
|
262
|
|
|
$exclude_post_statuses = bd_get_excluded_post_statuses(); |
263
|
|
|
foreach ( $exclude_post_statuses as $key ) { |
264
|
|
|
unset( $post_statuses[ $key ] ); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* List of post statuses that are displayed in the post status filter. |
269
|
|
|
* |
270
|
|
|
* @since 5.6.0 |
271
|
|
|
* |
272
|
|
|
* @param array $post_statuses List of post statuses. |
273
|
|
|
*/ |
274
|
|
|
return apply_filters( 'bd_post_statuses', $post_statuses ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Get the list of excluded post statuses. |
279
|
|
|
* |
280
|
|
|
* @since 6.0.0 |
281
|
|
|
* |
282
|
|
|
* @return array List of excluded post statuses. |
283
|
|
|
*/ |
284
|
|
|
function bd_get_excluded_post_statuses() { |
285
|
|
|
/** |
286
|
|
|
* List of post statuses that should be excluded from post status filter. |
287
|
|
|
* |
288
|
|
|
* @since 5.6.0 |
289
|
|
|
* |
290
|
|
|
* @param array $post_statuses List of post statuses to exclude. |
291
|
|
|
*/ |
292
|
|
|
return apply_filters( |
293
|
|
|
'bd_excluded_post_statuses', |
294
|
|
|
array( |
295
|
|
|
'inherit', |
296
|
|
|
'trash', |
297
|
|
|
'auto-draft', |
298
|
|
|
'request-pending', |
299
|
|
|
'request-confirmed', |
300
|
|
|
'request-failed', |
301
|
|
|
'request-completed', |
302
|
|
|
) |
303
|
|
|
); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Generate help tooltip and append it to existing markup. |
308
|
|
|
* |
309
|
|
|
* @param string $markup Existing markup. |
310
|
|
|
* @param string $content Tooltip content. |
311
|
|
|
* |
312
|
|
|
* @return string Markup with tooltip markup appended to it. |
313
|
|
|
*/ |
314
|
|
|
function bd_generate_help_tooltip( $markup, $content ) { |
315
|
|
|
if ( empty( $content ) ) { |
316
|
|
|
return $markup; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
$tooltip = '<span alt="f223" class="bd-help dashicons dashicons-editor-help" title="' . $content . '"></span>'; |
320
|
|
|
|
321
|
|
|
return $markup . $tooltip; |
322
|
|
|
} |
323
|
|
|
|