Completed
Pull Request — dev/6.1.0 (#719)
by
unknown
07:35 queued 04:43
created

Renderer   D

Complexity

Total Complexity 59

Size/Duplication

Total Lines 669
Duplicated Lines 0 %

Test Coverage

Coverage 8.09%

Importance

Changes 14
Bugs 0 Features 0
Metric Value
eloc 397
c 14
b 0
f 0
dl 0
loc 669
ccs 11
cts 136
cp 0.0809
rs 4.08
wmc 59

27 Methods

Rating   Name   Duplication   Size   Complexity  
A render_post_type_as_radios() 0 20 2
A render_post_type_with_status() 0 30 5
A split_post_type_and_status() 0 18 3
A render_post_status() 0 16 3
A render_data_types_dropdown() 0 6 1
A render_submit_button() 0 2 1
A render_tags_dropdown() 0 18 2
A render_limit_settings() 0 5 2
A render_user_role_dropdown() 0 22 5
A render_sticky_posts_dropdown() 0 32 3
B render_cron_settings() 0 90 5
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_delete_settings() 0 10 1
A render_post_reassign_settings() 0 27 1
A render_post_type_checkboxes() 0 19 2
A render_numeric_operators_dropdown() 0 26 3
A render_exclude_sticky_settings() 0 12 2
A render_string_comparison_operators() 0 9 1
A render_string_operators_dropdown() 0 25 3
A render_category_dropdown() 0 18 2
A render_restrict_settings() 0 2 1
A render_sticky_action_settings() 0 12 1
A render_number_comparison_operators() 0 7 1
A render_taxonomy_dropdown() 0 23 4

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

454
									__( '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

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