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"> |
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 the "private post" setting fields. |
74
|
|
|
* |
75
|
|
|
* @since 5.5 |
76
|
|
|
* |
77
|
|
|
* @param string $slug The slug to be used in field names. |
78
|
|
|
*/ |
79
|
|
|
function bd_render_private_post_settings( $slug ) { |
80
|
|
|
?> |
81
|
|
|
<tr> |
82
|
|
|
<td scope="row" colspan="2"> |
83
|
|
|
<input name="smbd_<?php echo $slug; ?>_private" value="false" type="radio" checked> <?php _e( 'Public posts', 'bulk-delete' ); ?> |
84
|
|
|
<input name="smbd_<?php echo $slug; ?>_private" value="true" type="radio"> <?php _e( 'Private Posts', 'bulk-delete' ); ?> |
85
|
|
|
</td> |
86
|
|
|
</tr> |
87
|
|
|
<?php |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Render the "limit" setting fields. |
92
|
|
|
* |
93
|
|
|
* @since 5.5 |
94
|
|
|
* |
95
|
|
|
* @param string $slug The slug to be used in field names. |
96
|
|
|
* @param string $item (Optional) Item type. Possible values are 'posts', 'pages', 'users' |
97
|
|
|
*/ |
98
|
|
|
function bd_render_limit_settings( $slug, $item = 'posts' ) { |
99
|
|
|
?> |
100
|
|
|
<tr> |
101
|
|
|
<td scope="row"> |
102
|
|
|
<input name="smbd_<?php echo $slug; ?>_limit" id="smbd_<?php echo $slug; ?>_limit" value="true" type="checkbox"> |
103
|
|
|
</td> |
104
|
|
|
<td> |
105
|
|
|
<?php _e( 'Only delete first ', 'bulk-delete' );?> |
106
|
|
|
<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;?>. |
107
|
|
|
<?php printf( __( 'Use this option if there are more than 1000 %s and the script timesout.', 'bulk-delete' ), $item ); ?> |
108
|
|
|
</td> |
109
|
|
|
</tr> |
110
|
|
|
<?php |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Render cron setting fields. |
115
|
|
|
* |
116
|
|
|
* @since 5.5 |
117
|
|
|
* |
118
|
|
|
* @param string $slug The slug to be used in field names. |
119
|
|
|
* @param string $addon_url Url for the pro addon. |
120
|
|
|
*/ |
121
|
|
|
function bd_render_cron_settings( $slug, $addon_url ) { |
122
|
|
|
$pro_class = 'bd-' . str_replace( '_', '-', $slug ) . '-pro'; |
123
|
|
|
?> |
124
|
|
|
<tr> |
125
|
|
|
<td scope="row" colspan="2"> |
126
|
|
|
<input name="smbd_<?php echo $slug; ?>_cron" value="false" type="radio" checked="checked"> <?php _e( 'Delete now', 'bulk-delete' ); ?> |
127
|
|
|
<input name="smbd_<?php echo $slug; ?>_cron" value="true" type="radio" id="smbd_<?php echo $slug; ?>_cron" disabled > <?php _e( 'Schedule', 'bulk-delete' ); ?> |
128
|
|
|
<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' );?> |
129
|
|
|
<select name="smbd_<?php echo $slug; ?>_cron_freq" id="smbd_<?php echo $slug; ?>_cron_freq" disabled> |
130
|
|
|
<option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
131
|
|
|
<?php |
132
|
|
|
$schedules = wp_get_schedules(); |
133
|
|
|
foreach ( $schedules as $key => $value ) { |
134
|
|
|
?> |
135
|
|
|
<option value="<?php echo $key; ?>"><?php echo $value['display']; ?></option> |
136
|
|
|
<?php } ?> |
137
|
|
|
</select> |
138
|
|
|
<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> |
139
|
|
|
</td> |
140
|
|
|
</tr> |
141
|
|
|
|
142
|
|
|
<tr> |
143
|
|
|
<td scope="row" colspan="2"> |
144
|
|
|
<?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' );?> |
145
|
|
|
</td> |
146
|
|
|
</tr> |
147
|
|
|
<?php |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Render the submit button. |
152
|
|
|
* |
153
|
|
|
* @since 5.5 |
154
|
|
|
* |
155
|
|
|
* @param string $action The action attribute of the submit button. |
156
|
|
|
*/ |
157
|
|
|
function bd_render_submit_button( $action ) { |
158
|
|
|
?> |
159
|
|
|
<p class="submit"> |
160
|
|
|
<button type="submit" name="bd_action" value="<?php echo esc_attr( $action ); ?>" class="button-primary"><?php _e( 'Bulk Delete ', 'bulk-delete' ); ?>»</button> |
161
|
|
|
</p> |
162
|
|
|
<?php |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Render the post type dropdown. |
167
|
|
|
* |
168
|
|
|
* @since 5.5 |
169
|
|
|
* |
170
|
|
|
* @param string $slug The slug to be used in field names. |
171
|
|
|
*/ |
172
|
|
|
function bd_render_post_type_dropdown( $slug ) { |
173
|
|
|
$types = bd_get_post_types(); |
174
|
|
|
?> |
175
|
|
|
<tr> |
176
|
|
|
<td scope="row" > |
177
|
|
|
<select class="select2" name="smbd_<?php echo $slug; ?>_post_type"> |
178
|
|
|
<?php foreach ( $types as $type ) { ?> |
179
|
|
|
<option value="<?php echo esc_attr( $type ); ?>"><?php echo esc_html( $type ); ?></option> |
180
|
|
|
<?php } ?> |
181
|
|
|
</select> |
182
|
|
|
</td> |
183
|
|
|
</tr> |
184
|
|
|
<?php |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Get the list of post type names that will be used in filters. |
189
|
|
|
* |
190
|
|
|
* @since 5.6.0 |
191
|
|
|
* |
192
|
|
|
* @return array List of post types. |
193
|
|
|
*/ |
194
|
|
|
function bd_get_post_types() { |
195
|
|
|
$post_types = get_post_types( array( '_builtin' => false ), 'names' ); |
196
|
|
|
|
197
|
|
|
array_unshift( $post_types, 'page' ); |
198
|
|
|
array_unshift( $post_types, 'post' ); |
199
|
|
|
|
200
|
|
|
return $post_types; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Get the list of post type objects that will be used in filters. |
205
|
|
|
* |
206
|
|
|
* @since 5.6.0 |
207
|
|
|
* |
208
|
|
|
* @return \WP_Post_Type[] List of post type objects. |
209
|
|
|
*/ |
210
|
|
|
function bd_get_post_type_objects() { |
211
|
|
|
$types = get_post_types( array( '_builtin' => false ), 'objects' ); |
212
|
|
|
|
213
|
|
|
$types['post'] = get_post_type_object( 'post' ); |
214
|
|
|
$types['page'] = get_post_type_object( 'page' ); |
215
|
|
|
|
216
|
|
|
return $types; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Render the post status filter. |
221
|
|
|
* |
222
|
|
|
* @since 5.6.0 |
223
|
|
|
* |
224
|
|
|
* @param string $slug The slug to be used in field names. |
225
|
|
|
* @param string $selected Default selected status. |
226
|
|
|
*/ |
227
|
|
|
function bd_render_post_status_filter( $slug, $selected = 'publish' ) { |
228
|
|
|
$post_statuses = bd_get_post_statuses(); |
229
|
|
|
|
230
|
|
|
foreach ( $post_statuses as $key => $value ) { |
231
|
|
|
?> |
232
|
|
|
<tr> |
233
|
|
|
<td> |
234
|
|
|
<label> |
235
|
|
|
<input name="smbd_<?php echo esc_attr( $slug ); ?>_post_status[]" type="checkbox" |
236
|
|
|
value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $selected ); ?>> |
237
|
|
|
|
238
|
|
|
<?php echo __( 'All', 'bulk-delete' ), ' ', esc_html( $value->label ), ' ', __( 'Posts', 'bulk-delete' ); ?> |
239
|
|
|
</label> |
240
|
|
|
</td> |
241
|
|
|
</tr> |
242
|
|
|
<?php |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Get the list of post statuses. |
248
|
|
|
* |
249
|
|
|
* This includes all custom post status, but excludes built-in private posts. |
250
|
|
|
* |
251
|
|
|
* @since 5.6.0 |
252
|
|
|
* |
253
|
|
|
* @return array List of post status objects. |
254
|
|
|
*/ |
255
|
|
|
function bd_get_post_statuses() { |
256
|
|
|
$post_statuses = get_post_stati( array(), 'object' ); |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* List of post statuses that should be excluded from post status filter. |
260
|
|
|
* |
261
|
|
|
* @since 5.6.0 |
262
|
|
|
* |
263
|
|
|
* @param array $post_statuses List of post statuses. |
264
|
|
|
*/ |
265
|
|
|
$exclude_post_statuses = apply_filters( 'bd_exclude_post_statuses', array( 'inherit', 'trash', 'auto-draft' ) ); |
|
|
|
|
266
|
|
|
|
267
|
|
|
foreach ( $exclude_post_statuses as $key ) { |
268
|
|
|
unset( $post_statuses[ $key ] ); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* List of post statuses that are displayed in the post status filter. |
273
|
|
|
* |
274
|
|
|
* @since 5.6.0 |
275
|
|
|
* |
276
|
|
|
* @param array $post_statuses List of post statuses. |
277
|
|
|
*/ |
278
|
|
|
return apply_filters( 'bd_post_statuses', $post_statuses ); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* Generate help tooltip and append it to existing markup. |
283
|
|
|
* |
284
|
|
|
* @param string $markup Existing markup. |
285
|
|
|
* @param string $content Tooltip content. |
286
|
|
|
* |
287
|
|
|
* @return string Markup with tooltip markup appended to it. |
288
|
|
|
*/ |
289
|
|
|
function bd_generate_help_tooltip( $markup, $content ) { |
290
|
|
|
if ( empty( $content ) ) { |
291
|
|
|
return $markup; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
$tooltip = '<span alt="f223" class="bd-help dashicons dashicons-editor-help" title="' . $content . '"></span>'; |
295
|
|
|
|
296
|
|
|
return $markup . $tooltip; |
297
|
|
|
} |
298
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.