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
|
|
|
* Get the list of post type objects that will be used in filters. |
209
|
|
|
* |
210
|
|
|
* @since 5.6.0 |
211
|
|
|
* |
212
|
|
|
* @return \WP_Post_Type[] List of post type objects. |
213
|
|
|
*/ |
214
|
|
|
function bd_get_post_types() { |
215
|
|
|
$custom_types = get_post_types( array( '_builtin' => false ), 'objects' ); |
216
|
|
|
|
217
|
|
|
$builtin_types = array( |
218
|
|
|
'post' => get_post_type_object( 'post' ), |
219
|
|
|
'page' => get_post_type_object( 'page' ), |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
return array_merge( $builtin_types, $custom_types ); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Render the post status filter. |
227
|
|
|
* |
228
|
|
|
* @since 5.6.0 |
229
|
|
|
* |
230
|
|
|
* @param string $slug The slug to be used in field names. |
231
|
|
|
* @param string $selected Default selected status. |
232
|
|
|
*/ |
233
|
|
|
function bd_render_post_status_filter( $slug, $selected = 'publish' ) { |
234
|
|
|
$post_statuses = bd_get_post_statuses(); |
235
|
|
|
|
236
|
|
|
foreach ( $post_statuses as $key => $value ) { |
237
|
|
|
?> |
238
|
|
|
<tr> |
239
|
|
|
<td> |
240
|
|
|
<label> |
241
|
|
|
<input name="smbd_<?php echo esc_attr( $slug ); ?>_post_status[]" type="checkbox" |
242
|
|
|
value="<?php echo esc_attr( $key ); ?>" <?php checked( $key, $selected ); ?>> |
243
|
|
|
|
244
|
|
|
<?php echo __( 'All', 'bulk-delete' ), ' ', esc_html( $value->label ), ' ', __( 'Posts', 'bulk-delete' ); ?> |
245
|
|
|
</label> |
246
|
|
|
</td> |
247
|
|
|
</tr> |
248
|
|
|
<?php |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get the list of post statuses. |
254
|
|
|
* |
255
|
|
|
* This includes all custom post status, but excludes built-in private posts. |
256
|
|
|
* |
257
|
|
|
* @since 5.6.0 |
258
|
|
|
* |
259
|
|
|
* @return array List of post status objects. |
260
|
|
|
*/ |
261
|
|
|
function bd_get_post_statuses() { |
262
|
|
|
$post_statuses = get_post_stati( array(), 'object' ); |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* List of post statuses that should be excluded from post status filter. |
266
|
|
|
* |
267
|
|
|
* @since 5.6.0 |
268
|
|
|
* |
269
|
|
|
* @param array $post_statuses List of post statuses. |
270
|
|
|
*/ |
271
|
|
|
$exclude_post_statuses = apply_filters( 'bd_exclude_post_statuses', array( 'inherit', 'trash', 'auto-draft' ) ); |
272
|
|
|
|
273
|
|
|
foreach ( $exclude_post_statuses as $key ) { |
274
|
|
|
unset( $post_statuses[ $key ] ); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* List of post statuses that are displayed in the post status filter. |
279
|
|
|
* |
280
|
|
|
* @since 5.6.0 |
281
|
|
|
* |
282
|
|
|
* @param array $post_statuses List of post statuses. |
283
|
|
|
*/ |
284
|
|
|
return apply_filters( 'bd_post_statuses', $post_statuses ); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Generate help tooltip and append it to existing markup. |
289
|
|
|
* |
290
|
|
|
* @param string $markup Existing markup. |
291
|
|
|
* @param string $content Tooltip content. |
292
|
|
|
* |
293
|
|
|
* @return string Markup with tooltip markup appended to it. |
294
|
|
|
*/ |
295
|
|
|
function bd_generate_help_tooltip( $markup, $content ) { |
296
|
|
|
if ( empty( $content ) ) { |
297
|
|
|
return $markup; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$tooltip = '<span alt="f223" class="bd-help dashicons dashicons-editor-help" title="' . $content . '"></span>'; |
301
|
|
|
|
302
|
|
|
return $markup . $tooltip; |
303
|
|
|
} |
304
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.