Total Complexity | 62 |
Total Lines | 765 |
Duplicated Lines | 0 % |
Changes | 14 | ||
Bugs | 0 | Features | 0 |
Complex classes like Renderer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Renderer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | abstract class Renderer extends Fetcher { |
||
16 | use OperatorHelpers; |
||
17 | |||
18 | /** |
||
19 | * Slug for the form fields. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $field_slug; |
||
24 | |||
25 | /** |
||
26 | * Render post status including custom post status. |
||
27 | * |
||
28 | * @since 6.1.0 Added $class param. |
||
29 | * |
||
30 | * @param string $post_type The post type for which the post status should be displayed. |
||
31 | * @param string $class Class to be applied. |
||
32 | */ |
||
33 | protected function render_post_status( $post_type = 'post', $class = 'validate' ) { |
||
34 | $post_statuses = $this->get_post_statuses(); |
||
35 | $post_count = wp_count_posts( $post_type ); |
||
36 | |||
37 | foreach ( $post_statuses as $post_status ) : ?> |
||
38 | <tr> |
||
39 | <td> |
||
40 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>" |
||
41 | value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox" class="<?php echo esc_attr( $class ); ?>"> |
||
42 | |||
43 | <label for="smbd_<?php echo esc_attr( $post_status->name ); ?>"> |
||
44 | <?php echo esc_html( $post_status->label ), ' '; ?> |
||
45 | <?php if ( property_exists( $post_count, $post_status->name ) ) : ?> |
||
46 | (<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>) |
||
47 | <?php endif; ?> |
||
48 | </label> |
||
49 | </td> |
||
50 | </tr> |
||
51 | <?php endforeach; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Render Post Types as radio buttons. |
||
56 | */ |
||
57 | protected function render_post_type_as_radios() { |
||
58 | $post_types = $this->get_post_types(); |
||
59 | ?> |
||
60 | |||
61 | <?php foreach ( $post_types as $post_type ) : ?> |
||
62 | |||
63 | <tr> |
||
64 | <td scope="row"> |
||
65 | <input type="radio" name="<?php echo esc_attr( $this->field_slug ); ?>_post_type" |
||
66 | value="<?php echo esc_attr( $post_type->name ); ?>" |
||
67 | id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
68 | |||
69 | <label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
70 | <?php echo esc_html( $post_type->label ); ?> |
||
71 | </label> |
||
72 | </td> |
||
73 | </tr> |
||
74 | |||
75 | <?php endforeach; ?> |
||
76 | <?php |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Render Post type with status and post count checkboxes. |
||
81 | * |
||
82 | * @since 6.0.1 Added $multiple param. |
||
83 | * @since 6.1.0 Added $feature param. |
||
84 | * |
||
85 | * @param bool $multiple_select Whether multiple select should be supported. Default true. |
||
86 | * @param string $feature Fetches only post types that supports feature. Default empty. |
||
87 | */ |
||
88 | protected function render_post_type_with_status( $multiple_select = true, $feature = '' ) { |
||
89 | $post_types_by_status = $this->get_post_types_by_status( $feature ); |
||
90 | |||
91 | $name = 'smbd_' . $this->field_slug; |
||
92 | if ( $multiple_select ) { |
||
93 | $name .= '[]'; |
||
94 | } |
||
95 | ?> |
||
96 | |||
97 | <tr> |
||
98 | <td scope="row" colspan="2"> |
||
99 | <select data-placeholder="<?php esc_attr_e( 'Select Post Type', 'bulk-delete' ); ?>" |
||
100 | name="<?php echo esc_attr( $name ); ?>" class="enhanced-post-types-with-status" |
||
101 | <?php if ( $multiple_select ) : ?> |
||
102 | multiple |
||
103 | <?php endif; ?> |
||
104 | > |
||
105 | |||
106 | <?php foreach ( $post_types_by_status as $post_type => $all_status ) : ?> |
||
107 | <optgroup label="<?php echo esc_html( $post_type ); ?>"> |
||
108 | |||
109 | <?php foreach ( $all_status as $status_key => $status_value ) : ?> |
||
110 | <option value="<?php echo esc_attr( $status_key ); ?>"> |
||
111 | <?php echo esc_html( $status_value ); ?> |
||
112 | </option> |
||
113 | <?php endforeach; ?> |
||
114 | |||
115 | </optgroup> |
||
116 | <?php endforeach; ?> |
||
117 | |||
118 | </select> |
||
119 | </td> |
||
120 | </tr> |
||
121 | <?php |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Split post type and status. |
||
126 | * |
||
127 | * @param string $str Post type and status combination. |
||
128 | * |
||
129 | * @return array Post type and status as elements of array. |
||
130 | */ |
||
131 | protected function split_post_type_and_status( $str ) { |
||
132 | $type_status = array(); |
||
133 | |||
134 | if ( strpos( $str, '|' ) === false ) { |
||
135 | $str_arr = explode( '-', $str ); |
||
136 | } else { |
||
137 | $str_arr = explode( '|', $str ); |
||
138 | } |
||
139 | |||
140 | if ( count( $str_arr ) > 1 ) { |
||
141 | $type_status['status'] = end( $str_arr ); |
||
142 | $type_status['type'] = implode( '-', array_slice( $str_arr, 0, - 1 ) ); |
||
143 | } else { |
||
144 | $type_status['status'] = 'publish'; |
||
145 | $type_status['type'] = $str; |
||
146 | } |
||
147 | |||
148 | return $type_status; |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * Render post reassign settings. |
||
153 | */ |
||
154 | protected function render_post_reassign_settings() { |
||
155 | ?> |
||
156 | <tr> |
||
157 | <td scope="row" colspan="2"> |
||
158 | <label> |
||
159 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="false" type="radio" |
||
160 | checked="checked" class="post-reassign"> |
||
161 | <?php |
||
162 | $markup = __( 'Also delete all posts of the users', 'bulk-delete' ) . ' ' . '<a href="https://bulkwp.com/docs/deleting-posts-automatically-when-the-post-author-is-deleted" target="_blank">' . __( 'More details', 'bulk-delete' ) . '</a>'; |
||
163 | |||
164 | $content = 'Some custom post types like bbPress topics which have disabled the delete_with_user post type attribute will not be deleted.'; |
||
165 | echo ' ', bd_generate_help_tooltip( $markup, $content ); |
||
166 | ?> |
||
167 | </label> |
||
168 | |||
169 | <label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="true" type="radio" |
||
170 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" class="post-reassign"> <?php _e( 'Re-assign the posts to', 'bulk-delete' ); ?></label> |
||
171 | <?php |
||
172 | wp_dropdown_users( |
||
173 | array( |
||
174 | 'name' => 'smbd_' . esc_attr( $this->field_slug ) . '_reassign_user_id', |
||
175 | 'class' => 'reassign-user', |
||
176 | 'show_option_none' => __( 'Select User', 'bulk-delete' ), |
||
177 | ) |
||
178 | ); |
||
179 | ?> |
||
180 | </td> |
||
181 | </tr> |
||
182 | <?php |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Render user role dropdown. |
||
187 | * |
||
188 | * @param bool $show_users_with_no_roles Should users with no user roles be shown? Default false. |
||
189 | */ |
||
190 | protected function render_user_role_dropdown( $show_users_with_no_roles = false ) { |
||
191 | $roles = get_editable_roles(); |
||
192 | $users_count = count_users(); |
||
193 | ?> |
||
194 | |||
195 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="enhanced-role-dropdown" |
||
196 | multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>"> |
||
197 | |||
198 | <?php foreach ( $roles as $role => $role_details ) : ?> |
||
199 | <option value="<?php echo esc_attr( $role ); ?>"> |
||
200 | <?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role, $users_count ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
201 | </option> |
||
202 | <?php endforeach; ?> |
||
203 | |||
204 | <?php if ( $show_users_with_no_roles ) : ?> |
||
205 | <?php if ( isset( $users_count['avail_roles']['none'] ) && $users_count['avail_roles']['none'] > 0 ) : ?> |
||
206 | <option value="none"> |
||
207 | <?php echo __( 'No role', 'bulk-delete' ), ' (', absint( $users_count['avail_roles']['none'] ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
||
208 | </option> |
||
209 | <?php endif; ?> |
||
210 | <?php endif; ?> |
||
211 | </select> |
||
212 | |||
213 | <?php |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Render Post type dropdown. |
||
218 | */ |
||
219 | protected function render_post_type_dropdown() { |
||
220 | bd_render_post_type_dropdown( $this->field_slug ); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * Render Taxonomy dropdown. |
||
225 | */ |
||
226 | protected function render_taxonomy_dropdown() { |
||
227 | $builtin_taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' ); |
||
228 | $custom_taxonomies = get_taxonomies( array( '_builtin' => false ), 'objects' ); |
||
229 | ?> |
||
230 | <select class="enhanced-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy"> |
||
231 | <optgroup label="<?php esc_attr_e( 'Built-in Taxonomies', 'bulk-delete' ); ?>"> |
||
232 | <?php foreach ( $builtin_taxonomies as $taxonomy ) : ?> |
||
233 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
234 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
235 | </option> |
||
236 | <?php endforeach; ?> |
||
237 | </optgroup> |
||
238 | |||
239 | <?php if ( ! empty( $custom_taxonomies ) ): ?> |
||
240 | <optgroup label="<?php esc_attr_e( 'Custom Taxonomies', 'bulk-delete' ); ?>"> |
||
241 | <?php foreach ( $custom_taxonomies as $taxonomy ) : ?> |
||
242 | <option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
||
243 | <?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?> |
||
244 | </option> |
||
245 | <?php endforeach; ?> |
||
246 | </optgroup> |
||
247 | <?php endif; ?> |
||
248 | </select> |
||
249 | <?php |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * Render Category dropdown. |
||
254 | */ |
||
255 | protected function render_category_dropdown() { |
||
256 | $categories = $this->get_categories(); |
||
257 | ?> |
||
258 | |||
259 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>" |
||
260 | class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>" |
||
261 | data-taxonomy="category" multiple> |
||
262 | |||
263 | <option value="all"> |
||
264 | <?php _e( 'All Categories', 'bulk-delete' ); ?> |
||
265 | </option> |
||
266 | |||
267 | <?php foreach ( $categories as $category ) : ?> |
||
268 | <option value="<?php echo absint( $category->cat_ID ); ?>"> |
||
269 | <?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
270 | </option> |
||
271 | <?php endforeach; ?> |
||
272 | |||
273 | </select> |
||
274 | <?php |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * Render number based comparison operators dropdown. |
||
279 | */ |
||
280 | protected function render_number_comparison_operators() { |
||
281 | ?> |
||
282 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator"> |
||
283 | <option value="="><?php _e( 'equal to', 'bulk-delete' ); ?></option> |
||
284 | <option value="!="><?php _e( 'not equal to', 'bulk-delete' ); ?></option> |
||
285 | <option value="<"><?php _e( 'less than', 'bulk-delete' ); ?></option> |
||
286 | <option value=">"><?php _e( 'greater than', 'bulk-delete' ); ?></option> |
||
287 | </select> |
||
288 | <?php |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * Render data types dropdown. |
||
293 | */ |
||
294 | protected function render_data_types_dropdown() { |
||
300 | </select> |
||
301 | <?php |
||
302 | } |
||
303 | |||
304 | /** |
||
305 | * Render numeric comparison operators dropdown. |
||
306 | * |
||
307 | * @param string $class Class to be applied. |
||
308 | * @param array $operators List of Operators needed. |
||
309 | */ |
||
310 | protected function render_numeric_operators_dropdown( $class = 'numeric', $operators = array( 'all' ) ) { |
||
336 | <?php |
||
337 | } |
||
338 | |||
339 | /** |
||
340 | * Render string comparison operators dropdown. |
||
341 | * |
||
342 | * @param string $class Class to be applied. |
||
343 | * @param array $operators List of Operators needed. |
||
344 | */ |
||
345 | protected function render_string_operators_dropdown( $class = 'string', $operators = array( 'all' ) ) { |
||
346 | // STARTS_WITH and ENDS_WITH operators needs a handler as SQL does not support these operators in queries. |
||
347 | $all_string_operators = array( |
||
348 | '=' => 'equal to', |
||
349 | '!=' => 'not equal to', |
||
350 | 'IN' => 'in', |
||
351 | 'NOT IN' => 'not in', |
||
352 | 'LIKE' => 'contains', |
||
353 | 'NOT LIKE' => 'not contains', |
||
354 | 'EXISTS' => 'exists', |
||
355 | 'NOT EXISTS' => 'not exists', |
||
356 | 'STARTS_WITH' => 'starts with', |
||
357 | 'ENDS_WITH' => 'ends with', |
||
358 | ); |
||
359 | if ( in_array( 'all', $operators, true ) ) { |
||
360 | $operators = array_keys( $all_string_operators ); |
||
361 | } |
||
362 | ?> |
||
363 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo esc_attr( $class ); ?>"> |
||
364 | <?php |
||
365 | foreach ( $operators as $operator ) { |
||
366 | echo '<option value="' . $operator . '">' . __( $all_string_operators[ $operator ], 'bulk-delete' ) . '</option>'; |
||
367 | } |
||
368 | ?> |
||
369 | </select> |
||
370 | <?php |
||
371 | } |
||
372 | |||
373 | protected function render_meta_value_filter( $options = [] ) { |
||
440 | </td> |
||
441 | </tr> |
||
442 | |||
443 | <?php |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Render Operators dropdown. |
||
448 | * |
||
449 | * @since 6.1.0 |
||
450 | * |
||
451 | * @param array $operators List of operators. Can use placeholders as well. |
||
452 | * @param string $class HTML class. |
||
453 | * |
||
454 | * @see \BulkWP\BulkDelete\Core\Base\Mixin\OperatorHelpers::resolve_operator() for the list of placeholders |
||
455 | */ |
||
456 | protected function render_operators_dropdown( $operators, $class = 'operators' ) { |
||
457 | $operators = $this->resolve_operators( $operators ); |
||
458 | ?> |
||
459 | |||
460 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo sanitize_html_class( $class ); ?>"> |
||
461 | <?php foreach ( $operators as $operator ) : ?> |
||
462 | <option value="<?php echo esc_attr( $operator ); ?>"> |
||
463 | <?php echo esc_html( $this->get_operator_label( $operator ) ); ?> |
||
464 | </option> |
||
465 | <?php endforeach; ?> |
||
466 | </select> |
||
467 | |||
468 | <?php |
||
469 | } |
||
470 | |||
471 | /** |
||
472 | * Render Tags dropdown. |
||
473 | */ |
||
474 | protected function render_tags_dropdown() { |
||
492 | <?php |
||
493 | } |
||
494 | |||
495 | /** |
||
496 | * Get the class name for select2 dropdown based on the number of items present. |
||
497 | * |
||
498 | * @param int $count The number of items present. |
||
499 | * @param string $class_name Primary class name. |
||
500 | * |
||
501 | * @return string Class name. |
||
502 | */ |
||
503 | protected function enable_ajax_if_needed_to_dropdown_class_name( $count, $class_name ) { |
||
504 | if ( $count >= $this->get_enhanced_select_threshold() ) { |
||
505 | $class_name .= '-ajax'; |
||
506 | } |
||
507 | |||
508 | return $class_name; |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * Render Sticky Posts dropdown. |
||
513 | */ |
||
514 | protected function render_sticky_posts_dropdown() { |
||
515 | $sticky_posts = $this->get_sticky_posts(); |
||
516 | ?> |
||
517 | |||
518 | <table class="optiontable"> |
||
519 | <?php if ( count( $sticky_posts ) > 1 ) : ?> |
||
520 | <tr> |
||
521 | <td scope="row"> |
||
522 | <label> |
||
523 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="all"> |
||
524 | <?php echo __( 'All sticky posts', 'bulk-delete' ), ' (', count( $sticky_posts ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
||
525 | </label> |
||
526 | </td> |
||
527 | </tr> |
||
528 | <?php endif; ?> |
||
529 | |||
530 | <?php foreach ( $sticky_posts as $post ) : ?> |
||
531 | <?php $author = get_userdata( $post->post_author ); ?> |
||
532 | <tr> |
||
533 | <td scope="row"> |
||
534 | <label> |
||
535 | <input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>"> |
||
536 | <?php |
||
537 | echo esc_html( $post->post_title ), ' - ', |
||
538 | __( 'Published on', 'bulk-delete' ), ' ', get_the_date( get_option( 'date_format' ), $post->ID ), |
||
539 | __( ' by ', 'bulk-delete' ), esc_html( $author->display_name ); |
||
540 | ?> |
||
541 | </label> |
||
542 | </td> |
||
543 | </tr> |
||
544 | <?php endforeach; ?> |
||
545 | </table> |
||
546 | <?php |
||
547 | } |
||
548 | |||
549 | /** |
||
550 | * Renders exclude sticky posts checkbox. |
||
551 | */ |
||
552 | protected function render_exclude_sticky_settings() { |
||
553 | if ( $this->are_sticky_posts_present() ) : // phpcs:ignore?> |
||
554 | <tr> |
||
555 | <td scope="row"> |
||
556 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky" value="true" type="checkbox"> |
||
557 | </td> |
||
558 | <td> |
||
559 | <label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky"><?php _e( 'Exclude sticky posts', 'bulk-delete' ); ?></label> |
||
560 | </td> |
||
561 | </tr> |
||
562 | <?php endif; // phpcs:ignore?> |
||
563 | <?php |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * Render Post Types as checkboxes. |
||
568 | * |
||
569 | * @since 5.6.0 |
||
570 | * |
||
571 | * @param string $name Name of post type checkboxes. |
||
572 | */ |
||
573 | protected function render_post_type_checkboxes( $name ) { |
||
574 | $post_types = bd_get_post_types(); |
||
575 | ?> |
||
576 | |||
577 | <?php foreach ( $post_types as $post_type ) : ?> |
||
578 | |||
579 | <tr> |
||
580 | <td scope="row"> |
||
581 | <input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>" |
||
582 | id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked> |
||
583 | |||
584 | <label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
||
585 | <?php echo esc_html( $post_type->label ); ?> |
||
586 | </label> |
||
587 | </td> |
||
588 | </tr> |
||
589 | |||
590 | <?php endforeach; ?> |
||
591 | <?php |
||
592 | } |
||
593 | |||
594 | /** |
||
595 | * Render the "private post" setting fields. |
||
596 | */ |
||
597 | protected function render_private_post_settings() { |
||
598 | bd_render_private_post_settings( $this->field_slug ); |
||
599 | } |
||
600 | |||
601 | /** |
||
602 | * Render sticky settings. |
||
603 | */ |
||
604 | protected function render_sticky_action_settings() { |
||
605 | ?> |
||
606 | <tr> |
||
607 | <td scope="row" colspan="2"> |
||
608 | <label> |
||
609 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="unsticky" type="radio" checked> |
||
610 | <?php _e( 'Remove Sticky', 'bulk-delete' ); ?> |
||
611 | </label> |
||
612 | <label> |
||
613 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="delete" type="radio"> |
||
614 | <?php _e( 'Delete Post', 'bulk-delete' ); ?> |
||
615 | </label> |
||
616 | </td> |
||
617 | </tr> |
||
618 | <?php |
||
619 | } |
||
620 | |||
621 | /** |
||
622 | * Render filtering table header. |
||
623 | */ |
||
624 | protected function render_filtering_table_header() { |
||
625 | bd_render_filtering_table_header(); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * Render restrict settings. |
||
630 | */ |
||
631 | protected function render_restrict_settings() { |
||
632 | bd_render_restrict_settings( $this->field_slug, $this->item_type ); |
||
633 | } |
||
634 | |||
635 | /** |
||
636 | * Render delete settings. |
||
637 | * |
||
638 | * @since 6.1.0 Added $hide_trash param. |
||
639 | * |
||
640 | * @param bool $hide_trash Show/Hide Move to trash radio button. Default false. |
||
641 | */ |
||
642 | protected function render_delete_settings( $hide_trash = false ) { |
||
643 | bd_render_delete_settings( $this->field_slug, $hide_trash ); |
||
644 | /** |
||
645 | * This action is primarily for adding delete attachment settings. |
||
646 | * |
||
647 | * @since 6.0.0 |
||
648 | * |
||
649 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule The delete module. |
||
650 | */ |
||
651 | do_action( 'bd_render_attachment_settings', $this ); |
||
652 | } |
||
653 | |||
654 | /** |
||
655 | * Render limit settings. |
||
656 | * |
||
657 | * @param string $item_type Item Type to be displayed in label. |
||
658 | */ |
||
659 | protected function render_limit_settings( $item_type = '' ) { |
||
664 | } |
||
665 | |||
666 | /** |
||
667 | * Render cron settings based on whether scheduler is present or not. |
||
668 | * |
||
669 | * @since 6.1.0 Added $now_label param. |
||
670 | * |
||
671 | * @param string $now_label Now button label. Default is empty. If empty then `Delete now` will be used. |
||
672 | */ |
||
673 | protected function render_cron_settings( $now_label = '' ) { |
||
674 | if ( empty( $now_label ) ) { |
||
675 | $now_label = __( 'Delete now', 'bulk-delete' ); |
||
676 | } |
||
677 | |||
678 | $pro_class = ''; |
||
679 | |||
680 | $disabled_attr = 'disabled'; |
||
681 | if ( empty( $this->scheduler_url ) ) { |
||
682 | $disabled_attr = ''; |
||
683 | } |
||
684 | ?> |
||
685 | |||
686 | <tr> |
||
687 | <td scope="row" colspan="2"> |
||
688 | <label> |
||
689 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio" |
||
690 | checked="checked" class="schedule-deletion"> |
||
691 | <?php echo esc_html( $now_label ); ?> |
||
692 | </label> |
||
693 | |||
694 | <label> |
||
695 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio" |
||
696 | class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>> |
||
697 | <?php _e( 'Schedule', 'bulk-delete' ); ?> |
||
698 | </label> |
||
699 | |||
700 | <input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" |
||
701 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now" |
||
702 | type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?> |
||
703 | |||
704 | <select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" |
||
705 | id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>> |
||
706 | |||
707 | <option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option> |
||
708 | <?php |
||
709 | /** |
||
710 | * List of cron schedules. |
||
711 | * |
||
712 | * @since 6.0.0 |
||
713 | * |
||
714 | * @param array $cron_schedules List of cron schedules. |
||
715 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
716 | */ |
||
717 | $cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this ); |
||
718 | ?> |
||
719 | |||
720 | <?php foreach ( $cron_schedules as $key => $value ) : ?> |
||
721 | <option |
||
722 | value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option> |
||
723 | <?php endforeach; ?> |
||
724 | </select> |
||
725 | |||
726 | <?php if ( ! empty( $this->scheduler_url ) ) : ?> |
||
727 | <?php |
||
728 | $pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro'; |
||
729 | |||
730 | /** |
||
731 | * HTML class of the span that displays the 'Pro only feature' message. |
||
732 | * |
||
733 | * @since 6.0.0 |
||
734 | * |
||
735 | * @param string $pro_class HTML class. |
||
736 | * @param string $field_slug Field Slug of module. |
||
737 | * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module Module. |
||
738 | */ |
||
739 | $pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this ) |
||
740 | ?> |
||
741 | |||
742 | <span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red"> |
||
743 | <?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a |
||
744 | href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a> |
||
745 | </span> |
||
746 | <?php endif; ?> |
||
747 | </td> |
||
748 | </tr> |
||
749 | |||
750 | <tr |
||
751 | <?php if ( ! empty( $pro_class ) ) : ?> |
||
752 | class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;" |
||
753 | <?php endif; ?> |
||
754 | > |
||
755 | |||
756 | <td scope="row" colspan="2"> |
||
757 | <?php |
||
758 | _e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' ); |
||
759 | |||
760 | $markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . ' ' . |
||
761 | '<a href="https://bulkwp.com/docs/add-a-new-cron-schedule/?utm_campaign=Docs&utm_medium=wpadmin&utm_source=tooltip&utm_content=cron-schedule" target="_blank" rel="noopener">' . __( 'Find out how', 'bulk-delete' ) . '</a>'; |
||
762 | |||
763 | $content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' ); |
||
764 | echo ' ', bd_generate_help_tooltip( $markup, $content ); |
||
765 | ?> |
||
766 | </td> |
||
767 | </tr> |
||
768 | <?php |
||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Render submit button. |
||
773 | * |
||
774 | * @since 6.1.0 Added $label param. |
||
775 | * |
||
776 | * @param string $label The label for the button. Default empty. |
||
777 | */ |
||
778 | protected function render_submit_button( $label = '' ) { |
||
780 | } |
||
781 | } |
||
782 |