Passed
Pull Request — dev/6.1.0 (#648)
by Sudar
02:49
created

Renderer   D

Complexity

Total Complexity 58

Size/Duplication

Total Lines 653
Duplicated Lines 0 %

Test Coverage

Coverage 8.4%

Importance

Changes 12
Bugs 0 Features 0
Metric Value
eloc 388
dl 0
loc 653
ccs 11
cts 131
cp 0.084
rs 4.5599
c 12
b 0
f 0
wmc 58

27 Methods

Rating   Name   Duplication   Size   Complexity  
A render_post_type_as_radios() 0 20 2
A render_post_status() 0 16 3
A render_exclude_sticky_settings() 0 12 2
A render_tags_dropdown() 0 18 2
A render_sticky_posts_dropdown() 0 32 3
A enable_ajax_if_needed_to_dropdown_class_name() 0 6 2
A render_post_type_dropdown() 0 2 1
A render_private_post_settings() 0 2 1
A render_filtering_table_header() 0 2 1
A render_post_reassign_settings() 0 18 1
A split_post_type_and_status() 0 18 3
A render_category_dropdown() 0 18 2
A render_restrict_settings() 0 2 1
A render_submit_button() 0 2 1
A render_limit_settings() 0 5 2
A render_user_role_dropdown() 0 22 5
B render_cron_settings() 0 90 5
A render_post_type_with_status() 0 30 5
A render_delete_settings() 0 10 1
A render_post_type_checkboxes() 0 19 2
A render_numeric_operators_dropdown() 0 26 3
A render_string_operators_dropdown() 0 25 3
A render_sticky_action_settings() 0 12 1
A render_taxonomy_dropdown() 0 20 3
A render_data_types_dropdown() 0 6 1
A render_string_comparison_operators() 0 9 1
A render_number_comparison_operators() 0 7 1

How to fix   Complexity   

Complex Class

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
2
3
namespace BulkWP\BulkDelete\Core\Base\Mixin;
4
5 1
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7
/**
8
 * Container of all Render methods.
9
 *
10
 * Ideally this should be a Trait. Since Bulk Delete still supports PHP 5.3, this is implemented as a class.
11
 * Once the minimum requirement is increased to PHP 5.3, this will be changed into a Trait.
12
 *
13
 * @since 6.0.0
14
 */
15
abstract class Renderer extends Fetcher {
16
	/**
17
	 * Slug for the form fields.
18
	 *
19
	 * @var string
20
	 */
21
	protected $field_slug;
22
23
	/**
24
	 * Render post status including custom post status.
25
	 *
26
	 * @param string $post_type The post type for which the post status should be displayed.
27
	 */
28
	protected function render_post_status( $post_type = 'post' ) {
29
		$post_statuses = $this->get_post_statuses();
30
		$post_count    = wp_count_posts( $post_type );
31
32
		foreach ( $post_statuses as $post_status ) : ?>
33
			<tr>
34
				<td>
35
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" id="smbd_<?php echo esc_attr( $post_status->name ); ?>"
36
						value="<?php echo esc_attr( $post_status->name ); ?>" type="checkbox">
37
38
					<label for="smbd_<?php echo esc_attr( $post_status->name ); ?>">
39
						<?php echo esc_html( $post_status->label ), ' '; ?>
40
						<?php if ( property_exists( $post_count, $post_status->name ) ) : ?>
41
							(<?php echo absint( $post_count->{ $post_status->name } ) . ' ', __( 'Posts', 'bulk-delete' ); ?>)
42
						<?php endif; ?>
43
					</label>
44
				</td>
45
			</tr>
46
		<?php endforeach;
47
	}
48
49
	/**
50
	 * Render Post Types as radio buttons.
51
	 */
52
	protected function render_post_type_as_radios() {
53
		$post_types = $this->get_post_types();
54
		?>
55
56
		<?php foreach ( $post_types as $post_type ) : ?>
57
58
			<tr>
59
				<td scope="row">
60
					<input type="radio" name="<?php echo esc_attr( $this->field_slug ); ?>_post_type"
61
						value="<?php echo esc_attr( $post_type->name ); ?>"
62
						id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
63
64
					<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
65
						<?php echo esc_html( $post_type->label ); ?>
66
					</label>
67
				</td>
68
			</tr>
69
70
		<?php endforeach; ?>
71
		<?php
72
	}
73
74
	/**
75
	 * Render Post type with status and post count checkboxes.
76
	 *
77
	 * @since 6.0.1 Added $multiple param.
78
	 * @since 6.1.0 Added $feature  param.
79
	 *
80
	 * @param bool   $multiple_select Whether multiple select should be supported. Default true.
81
	 * @param string $feature         Fetches only post types that supports feature. Default empty.
82
	 */
83
	protected function render_post_type_with_status( $multiple_select = true, $feature = '' ) {
84
		$post_types_by_status = $this->get_post_types_by_status( $feature );
85
86
		$name = 'smbd_' . $this->field_slug;
87
		if ( $multiple_select ) {
88
			$name .= '[]';
89
		}
90
		?>
91
92
		<tr>
93
			<td scope="row" colspan="2">
94
				<select data-placeholder="<?php esc_attr_e( 'Select Post Type', 'bulk-delete' ); ?>"
95
					name="<?php echo esc_attr( $name ); ?>" class="enhanced-post-types-with-status"
96
					<?php if ( $multiple_select ) : ?>
97
						multiple
98
					<?php endif; ?>
99
				>
100
101
				<?php foreach ( $post_types_by_status as $post_type => $all_status ) : ?>
102
					<optgroup label="<?php echo esc_html( $post_type ); ?>">
103
104
					<?php foreach ( $all_status as $status_key => $status_value ) : ?>
105
						<option value="<?php echo esc_attr( $status_key ); ?>">
106
							<?php echo esc_html( $status_value ); ?>
107
						</option>
108
					<?php endforeach; ?>
109
110
					</optgroup>
111
				<?php endforeach; ?>
112
113
				</select>
114
			</td>
115
		</tr>
116
		<?php
117
	}
118
119
	/**
120
	 * Split post type and status.
121
	 *
122
	 * @param string $str Post type and status combination.
123
	 *
124
	 * @return array Post type and status as elements of array.
125
	 */
126 25
	protected function split_post_type_and_status( $str ) {
127 25
		$type_status = array();
128
129 25
		if ( strpos( $str, '|' ) === false ) {
130 17
			$str_arr = explode( '-', $str );
131
		} else {
132 8
			$str_arr = explode( '|', $str );
133
		}
134
135 25
		if ( count( $str_arr ) > 1 ) {
136 17
			$type_status['status'] = end( $str_arr );
137 17
			$type_status['type']   = implode( '-', array_slice( $str_arr, 0, - 1 ) );
138
		} else {
139 8
			$type_status['status'] = 'publish';
140 8
			$type_status['type']   = $str;
141
		}
142
143 25
		return $type_status;
144
	}
145
146
	/**
147
	 * Render post reassign settings.
148
	 */
149
	protected function render_post_reassign_settings() {
150
		?>
151
		<tr>
152
			<td scope="row" colspan="2">
153
				<label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="false" type="radio"
154
					checked="checked" class="post-reassign"> <?php _e( 'Also delete all posts of the users', 'bulk-delete' ); ?></label>
155
				<label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="true" type="radio"
156
					id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" class="post-reassign"> <?php _e( 'Re-assign the posts to', 'bulk-delete' ); ?></label>
157
				<?php
158
				wp_dropdown_users(
159
					array(
160
						'name'             => 'smbd_' . esc_attr( $this->field_slug ) . '_reassign_user_id',
161
						'class'            => 'reassign-user',
162
						'show_option_none' => __( 'Select User', 'bulk-delete' ),
163
					)
164
				);
165
				?>
166
			</td>
167
		</tr>
168
		<?php
169
	}
170
171
	/**
172
	 * Render user role dropdown.
173
	 *
174
	 * @param bool $show_users_with_no_roles Should users with no user roles be shown? Default false.
175
	 */
176
	protected function render_user_role_dropdown( $show_users_with_no_roles = false ) {
177
		$roles       = get_editable_roles();
178
		$users_count = count_users();
179
		?>
180
181
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="enhanced-role-dropdown"
182
				multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>">
183
184
			<?php foreach ( $roles as $role => $role_details ) : ?>
185
				<option value="<?php echo esc_attr( $role ); ?>">
186
					<?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role, $users_count ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?>
187
				</option>
188
			<?php endforeach; ?>
189
190
			<?php if ( $show_users_with_no_roles ) : ?>
191
				<?php if ( isset( $users_count['avail_roles']['none'] ) && $users_count['avail_roles']['none'] > 0 ) : ?>
192
					<option value="none">
193
						<?php echo __( 'No role', 'bulk-delete' ), ' (', absint( $users_count['avail_roles']['none'] ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?>
194
					</option>
195
				<?php endif; ?>
196
			<?php endif; ?>
197
		</select>
198
199
		<?php
200
	}
201
202
	/**
203
	 * Render Post type dropdown.
204
	 */
205
	protected function render_post_type_dropdown() {
206
		bd_render_post_type_dropdown( $this->field_slug );
207
	}
208
209
	/**
210
	 * Render Taxonomy dropdown.
211
	 */
212
	protected function render_taxonomy_dropdown() {
213
		$builtin_taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' );
214
		$custom_taxonomies  = get_taxonomies( array( '_builtin' => false ), 'objects' );
215
		?>
216
			<select class="enhanced-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy">
217
				<optgroup label="<?php esc_attr_e( 'Built-in Taxonomies', 'bulk-delete' ); ?>">
218
					<?php foreach ( $builtin_taxonomies as $taxonomy ) : ?>
219
						<option value="<?php echo esc_attr( $taxonomy->name ); ?>">
220
							<?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?>
221
						</option>
222
					<?php endforeach; ?>
223
				</optgroup>
224
225
				<optgroup label="<?php esc_attr_e( 'Custom Taxonomies', 'bulk-delete' ); ?>">
226
					<?php foreach ( $custom_taxonomies as $taxonomy ) : ?>
227
						<option value="<?php echo esc_attr( $taxonomy->name ); ?>">
228
							<?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?>
229
						</option>
230
					<?php endforeach; ?>
231
				</optgroup>
232
			</select>
233
		<?php
234
	}
235
236
	/**
237
	 * Render Category dropdown.
238
	 */
239
	protected function render_category_dropdown() {
240
		$categories = $this->get_categories();
241
		?>
242
243
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>"
244
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>"
245
				data-taxonomy="category" multiple>
246
247
			<option value="all">
248
				<?php _e( 'All Categories', 'bulk-delete' ); ?>
249
			</option>
250
251
			<?php foreach ( $categories as $category ) : ?>
252
				<option value="<?php echo absint( $category->cat_ID ); ?>">
253
					<?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
254
				</option>
255
			<?php endforeach; ?>
256
257
		</select>
258
		<?php
259
	}
260
261
	/**
262
	 * Render String based comparison operators dropdown.
263
	 */
264
	protected function render_string_comparison_operators() {
265
		?>
266
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator">
267
			<option value="equal_to"><?php _e( 'equal to', 'bulk-delete' ); ?></option>
268
			<option value="not_equal_to"><?php _e( 'not equal to', 'bulk-delete' ); ?></option>
269
			<option value="starts_with"><?php _e( 'starts with', 'bulk-delete' ); ?></option>
270
			<option value="ends_with"><?php _e( 'ends with', 'bulk-delete' ); ?></option>
271
			<option value="contains"><?php _e( 'contains', 'bulk-delete' ); ?></option>
272
			<option value="not_contains"><?php _e( 'not contains', 'bulk-delete' ); ?></option>
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() {
295
		?>
296
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_type" class="meta-type">
297
			<option value="numeric"><?php _e( 'Number', 'bulk-delete' ); ?></option>
298
			<option value="string"><?php _e( 'Character', 'bulk-delete' ); ?></option>
299
			<option value="date"><?php _e( 'Date', 'bulk-delete' ); ?></option>
300
		</select>
301
		<?php
302
	}
303
	/**
304
	 * Render numeric comparison operators dropdown.
305
	 *
306
	 * @param string $class     Class to be applied.
307
	 * @param array  $operators List of Operators needed.
308
	 */
309
	protected function render_numeric_operators_dropdown( $class = 'numeric', $operators = array( 'all' ) ) {
310
		$all_numeric_operators = array(
311
			'='           => 'equal to',
312
			'!='          => 'not equal to',
313
			'<'           => 'less than',
314
			'<='          => 'less than or equal to',
315
			'>'           => 'greater than',
316
			'>='          => 'greater than or equal to',
317
			'IN'          => 'in',
318
			'NOT IN'      => 'not in',
319
			'BETWEEN'     => 'between',
320
			'NOT BETWEEN' => 'not between',
321
			'EXISTS'      => 'exists',
322
			'NOT EXISTS'  => 'not exists',
323
		);
324
		if ( in_array( 'all', $operators, true ) ) {
325
			$operators = array_keys( $all_numeric_operators );
326
		}
327
		?>
328
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class= "<?php echo esc_attr( $class ); ?>">
329
		<?php
330
		foreach ( $operators as $operator ) {
331
			echo '<option value="' . $operator . '">' . __( $all_numeric_operators[ $operator ], 'bulk-delete' ) . '</option>';
332
		}
333
		?>
334
		</select>
335
		<?php
336
	}
337
	/**
338
	 * Render string comparison operators dropdown.
339
	 *
340
	 * @param string $class     Class to be applied.
341
	 * @param array  $operators List of Operators needed.
342
	 */
343
	protected function render_string_operators_dropdown( $class = 'string', $operators = array( 'all' ) ) {
344
		// STARTS_WITH and ENDS_WITH operators needs a handler as SQL does not support these operators in queries.
345
		$all_string_operators = array(
346
			'='           => 'equal to',
347
			'!='          => 'not equal to',
348
			'IN'          => 'in',
349
			'NOT IN'      => 'not in',
350
			'LIKE'        => 'contains',
351
			'NOT LIKE'    => 'not contains',
352
			'EXISTS'      => 'exists',
353
			'NOT EXISTS'  => 'not exists',
354
			'STARTS_WITH' => 'starts with',
355
			'ENDS_WITH'   => 'ends with',
356
		);
357
		if ( in_array( 'all', $operators, true ) ) {
358
			$operators = array_keys( $all_string_operators );
359
		}
360
		?>
361
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo esc_attr( $class ); ?>">
362
		<?php
363
		foreach ( $operators as $operator ) {
364
			echo '<option value="' . $operator . '">' . __( $all_string_operators[ $operator ], 'bulk-delete' ) . '</option>';
365
		}
366
		?>
367
		</select>
368
		<?php
369
	}
370
371
	/**
372
	 * Render Tags dropdown.
373
	 */
374
	protected function render_tags_dropdown() {
375
		$tags = $this->get_tags();
376
		?>
377
378
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>"
379
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>"
380
				data-taxonomy="post_tag" multiple>
381
382
			<option value="all">
383
				<?php _e( 'All Tags', 'bulk-delete' ); ?>
384
			</option>
385
386
			<?php foreach ( $tags as $tag ) : ?>
387
				<option value="<?php echo absint( $tag->term_id ); ?>">
388
					<?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
389
				</option>
390
			<?php endforeach; ?>
391
		</select>
392
		<?php
393
	}
394
395
	/**
396
	 * Get the class name for select2 dropdown based on the number of items present.
397
	 *
398
	 * @param int    $count      The number of items present.
399
	 * @param string $class_name Primary class name.
400
	 *
401
	 * @return string Class name.
402
	 */
403
	protected function enable_ajax_if_needed_to_dropdown_class_name( $count, $class_name ) {
404
		if ( $count >= $this->get_enhanced_select_threshold() ) {
405
			$class_name .= '-ajax';
406
		}
407
408
		return $class_name;
409
	}
410
411
	/**
412
	 * Render Sticky Posts dropdown.
413
	 */
414
	protected function render_sticky_posts_dropdown() {
415
		$sticky_posts = $this->get_sticky_posts();
416
		?>
417
418
		<table class="optiontable">
419
			<?php if ( count( $sticky_posts ) > 1 ) : ?>
420
				<tr>
421
					<td scope="row">
422
						<label>
423
							<input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="all">
424
							<?php echo __( 'All sticky posts', 'bulk-delete' ), ' (', count( $sticky_posts ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
425
						</label>
426
					</td>
427
				</tr>
428
			<?php endif; ?>
429
430
			<?php foreach ( $sticky_posts as $post ) : ?>
431
				<?php $author = get_userdata( $post->post_author ); ?>
432
				<tr>
433
					<td scope="row">
434
						<label>
435
							<input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>">
436
							<?php
437
								echo esc_html( $post->post_title ), ' - ',
438
									__( 'Published on', 'bulk-delete' ), ' ', get_the_date( get_option( 'date_format' ), $post->ID ),
0 ignored issues
show
Bug introduced by
Are you sure get_the_date(get_option(...te_format'), $post->ID) of type false|string can be used in echo? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

438
									__( 'Published on', 'bulk-delete' ), ' ', /** @scrutinizer ignore-type */ get_the_date( get_option( 'date_format' ), $post->ID ),
Loading history...
Bug introduced by
It seems like get_option('date_format') can also be of type false; however, parameter $d of get_the_date() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

438
									__( 'Published on', 'bulk-delete' ), ' ', get_the_date( /** @scrutinizer ignore-type */ get_option( 'date_format' ), $post->ID ),
Loading history...
439
									__( ' by ', 'bulk-delete' ), esc_html( $author->display_name );
440
							?>
441
						</label>
442
					</td>
443
				</tr>
444
			<?php endforeach; ?>
445
		</table>
446
		<?php
447
	}
448
449
	/**
450
	 * Renders exclude sticky posts checkbox.
451
	 */
452
	protected function render_exclude_sticky_settings() {
453
		if ( $this->are_sticky_posts_present() ) : // phpcs:ignore?>
454
		<tr>
455
			<td scope="row">
456
				<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">
457
			</td>
458
			<td>
459
				<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky"><?php _e( 'Exclude sticky posts', 'bulk-delete' ); ?></label>
460
			</td>
461
		</tr>
462
		<?php endif; // phpcs:ignore?>
463
		<?php
464
	}
465
466
	/**
467
	 * Render Post Types as checkboxes.
468
	 *
469
	 * @since 5.6.0
470
	 *
471
	 * @param string $name Name of post type checkboxes.
472
	 */
473
	protected function render_post_type_checkboxes( $name ) {
474
		$post_types = bd_get_post_types();
475
		?>
476
477
		<?php foreach ( $post_types as $post_type ) : ?>
478
479
		<tr>
480
			<td scope="row">
481
				<input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>"
482
					id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked>
483
484
				<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
485
					<?php echo esc_html( $post_type->label ); ?>
486
				</label>
487
			</td>
488
		</tr>
489
490
		<?php endforeach; ?>
491
		<?php
492
	}
493
494
	/**
495
	 * Render the "private post" setting fields.
496
	 */
497
	protected function render_private_post_settings() {
498
		bd_render_private_post_settings( $this->field_slug );
499
	}
500
501
	/**
502
	 * Render sticky settings.
503
	 */
504
	protected function render_sticky_action_settings() {
505
		?>
506
		<tr>
507
			<td scope="row" colspan="2">
508
				<label>
509
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="unsticky" type="radio" checked>
510
					<?php _e( 'Remove Sticky', 'bulk-delete' ); ?>
511
				</label>
512
				<label>
513
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="delete" type="radio">
514
					<?php _e( 'Delete Post', 'bulk-delete' ); ?>
515
				</label>
516
			</td>
517
		</tr>
518
		<?php
519
	}
520
521
	/**
522
	 * Render filtering table header.
523
	 */
524
	protected function render_filtering_table_header() {
525
		bd_render_filtering_table_header();
526
	}
527
528
	/**
529
	 * Render restrict settings.
530
	 */
531
	protected function render_restrict_settings() {
532
		bd_render_restrict_settings( $this->field_slug, $this->item_type );
533
	}
534
535
	/**
536
	 * Render delete settings.
537
	 *
538
	 * @since 6.1.0 Added $hide_trash  param.
539
	 *
540
	 * @param bool $hide_trash Show/Hide Move to trash radio button. Default false.
541
	 */
542
	protected function render_delete_settings( $hide_trash = false ) {
543
		bd_render_delete_settings( $this->field_slug, $hide_trash );
544
		/**
545
		 * This action is primarily for adding delete attachment settings.
546
		 *
547
		 * @since 6.0.0
548
		 *
549
		 * @param \BulkWP\BulkDelete\Core\Base\BaseModule The delete module.
550
		 */
551
		do_action( 'bd_render_attachment_settings', $this );
552
	}
553
554
	/**
555
	 * Render limit settings.
556
	 *
557
	 * @param string $item_type Item Type to be displayed in label.
558
	 */
559
	protected function render_limit_settings( $item_type = '' ) {
560
		if ( empty( $item_type ) ) {
561
			$item_type = $this->item_type;
562
		}
563
		bd_render_limit_settings( $this->field_slug, $item_type );
564
	}
565
566
	/**
567
	 * Render cron settings based on whether scheduler is present or not.
568
	 */
569
	protected function render_cron_settings() {
570
		$pro_class = '';
571
572
		$disabled_attr = 'disabled';
573
		if ( empty( $this->scheduler_url ) ) {
574
			$disabled_attr = '';
575
		}
576
		?>
577
578
		<tr>
579
			<td scope="row" colspan="2">
580
				<label>
581
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio"
582
					checked="checked" class="schedule-deletion">
583
					<?php _e( 'Delete now', 'bulk-delete' ); ?>
584
				</label>
585
586
				<label>
587
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio"
588
					class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>>
589
					<?php _e( 'Schedule', 'bulk-delete' ); ?>
590
				</label>
591
592
				<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start"
593
					id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now"
594
					type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?>
595
596
				<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq"
597
						id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>>
598
599
					<option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option>
600
					<?php
601
					/**
602
					 * List of cron schedules.
603
					 *
604
					 * @since 6.0.0
605
					 *
606
					 * @param array                                   $cron_schedules List of cron schedules.
607
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module         Module.
608
					 */
609
					$cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this );
610
					?>
611
612
					<?php foreach ( $cron_schedules as $key => $value ) : ?>
613
						<option
614
							value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option>
615
					<?php endforeach; ?>
616
				</select>
617
618
				<?php if ( ! empty( $this->scheduler_url ) ) : ?>
619
					<?php
620
					$pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro';
621
622
					/**
623
					 * HTML class of the span that displays the 'Pro only feature' message.
624
					 *
625
					 * @since 6.0.0
626
					 *
627
					 * @param string                                  $pro_class  HTML class.
628
					 * @param string                                  $field_slug Field Slug of module.
629
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module     Module.
630
					 */
631
					$pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this )
632
					?>
633
634
					<span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red">
635
						<?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a
636
							href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a>
637
					</span>
638
				<?php endif; ?>
639
			</td>
640
		</tr>
641
642
		<tr
643
		<?php if ( ! empty( $pro_class ) ) : ?>
644
			class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;"
645
		<?php endif; ?>
646
		>
647
648
			<td scope="row" colspan="2">
649
				<?php
650
				_e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' );
651
652
				$markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . '&nbsp' .
653
					'<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>';
654
655
				$content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' );
656
				echo '&nbsp', bd_generate_help_tooltip( $markup, $content );
657
				?>
658
			</td>
659
		</tr>
660
		<?php
661
	}
662
663
	/**
664
	 * Render submit button.
665
	 */
666
	protected function render_submit_button() {
667
		bd_render_submit_button( $this->action );
668
	}
669
}
670