Completed
Push — 717-fix/add-tests-for-posts-de... ( 41a87a...780d20 )
by Sudar
09:45 queued 06:22
created

Renderer::render_operators_dropdown()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 12
c 0
b 0
f 0
nc 2
nop 2
dl 0
loc 11
ccs 0
cts 4
cp 0
crap 6
rs 9.8666
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
	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 40
	protected function split_post_type_and_status( $str ) {
132 40
		$type_status = array();
133
134 40
		if ( strpos( $str, '|' ) === false ) {
135 32
			$str_arr = explode( '-', $str );
136
		} else {
137 8
			$str_arr = explode( '|', $str );
138
		}
139
140 40
		if ( count( $str_arr ) > 1 ) {
141 17
			$type_status['status'] = end( $str_arr );
142 17
			$type_status['type']   = implode( '-', array_slice( $str_arr, 0, - 1 ) );
143
		} else {
144 23
			$type_status['status'] = 'publish';
145 23
			$type_status['type']   = $str;
146
		}
147
148 40
		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' ) . '&nbsp' . '<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 '&nbsp', 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() {
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="char"><?php _e( 'Character', 'bulk-delete' ); ?></option>
299
			<option value="date"><?php _e( 'Date', 'bulk-delete' ); ?></option>
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' ) ) {
311
		$all_numeric_operators = array(
312
			'='           => 'equal to',
313
			'!='          => 'not equal to',
314
			'<'           => 'less than',
315
			'<='          => 'less than or equal to',
316
			'>'           => 'greater than',
317
			'>='          => 'greater than or equal to',
318
			'IN'          => 'in',
319
			'NOT IN'      => 'not in',
320
			'BETWEEN'     => 'between',
321
			'NOT BETWEEN' => 'not between',
322
			'EXISTS'      => 'exists',
323
			'NOT EXISTS'  => 'not exists',
324
		);
325
		if ( in_array( 'all', $operators, true ) ) {
326
			$operators = array_keys( $all_numeric_operators );
327
		}
328
		?>
329
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class= "<?php echo esc_attr( $class ); ?>">
330
		<?php
331
		foreach ( $operators as $operator ) {
332
			echo '<option value="' . $operator . '">' . __( $all_numeric_operators[ $operator ], 'bulk-delete' ) . '</option>';
333
		}
334
		?>
335
		</select>
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 = [] ) {
374
		$defaults = [
375
			'class'             => 'value-filters',
376
			'label'             => __( 'Meta Value', 'bulk-delete' ),
377
			'numeric_operators' => [ 'equals', 'numeric', 'ins', 'betweens', 'EXISTS' ],
378
			'string_operators'  => [ 'equals', 'ins', 'likes', 'string-start-end', 'EXISTS' ],
379
			'date_operators'    => [ 'equals', 'numeric', 'EXISTS' ],
380
		];
381
382
		$options = wp_parse_args( $options, $defaults );
383
		?>
384
385
		<tr class="<?php echo esc_attr( $options['class'] ); ?>">
386
			<td>
387
				<?php echo esc_html( $options['label'] ); ?>
388
				<?php $this->render_data_types_dropdown(); ?>
389
				<?php $this->render_operators_dropdown( $options['numeric_operators'], 'meta-operators-numeric' ); ?>
390
				<?php $this->render_operators_dropdown( $options['string_operators'], 'meta-operators-char' ); ?>
391
				<?php $this->render_operators_dropdown( $options['date_operators'], 'meta-operators-date' ); ?>
392
393
				<input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_value"
394
						id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_value" class="date-picker">
395
396
				<span class="date-fields">
397
					<?php _e( 'Or', 'bulk-delete' ); ?>
398
399
					<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_relative_date" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_relative_date" class="relative-date-fields">
400
						<option value=""><?php _e( 'Select Relative date', 'bulk-delete' ); ?></option>
401
						<option value="yesterday"><?php _e( 'Yesterday', 'bulk-delete' ); ?></option>
402
						<option value="today"><?php _e( 'Today', 'bulk-delete' ); ?></option>
403
						<option value="tomorrow"><?php _e( 'Tomorrow', 'bulk-delete' ); ?></option>
404
						<option value="custom"><?php _e( 'Custom', 'bulk-delete' ); ?></option>
405
					</select>
406
407
					<?php echo apply_filters( 'bd_help_tooltip', '', __( 'You can select a date or enter a date which is relative to today.', 'bulk-delete' ) ); ?>
408
				</span>
409
410
				<span class="custom-date-fields">
411
					<input type="number" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_unit" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_unit" style="width: 5%;">
412
					<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_type" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_type">
413
						<option value="day"><?php _e( 'Day', 'bulk-delete' ); ?></option>
414
						<option value="week"><?php _e( 'Week', 'bulk-delete' ); ?></option>
415
						<option value="month"><?php _e( 'Month', 'bulk-delete' ); ?></option>
416
						<option value="year"><?php _e( 'Year', 'bulk-delete' ); ?></option>
417
					</select>
418
				</span>
419
			</td>
420
		</tr>
421
422
		<tr class="date-format-fields">
423
			<td>
424
				<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_format">
425
					<?php _e( 'Meta value date format', 'bulk-delete' ); ?>
426
				</label>
427
428
				<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_format" placeholder="%Y-%m-%d">
429
430
				<?php echo apply_filters( 'bd_help_tooltip', '', __( "If you leave date format blank, then '%Y-%m-%d', will be assumed.", 'bulk-delete' ) ); ?>
431
				<p>
432
					<?php
433
					printf(
434
						/* translators: 1 Mysql Format specifier url.  */
435
						__( 'If you are storing the date in a format other than <em>YYYY-MM-DD</em> then enter the date format using <a href="%s" target="_blank" rel="noopener noreferrer">Mysql format specifiers</a>.  If you are storing the date as Unix Timestamp, then enter ‘Unix Timestamp’ as the format specifier.', 'bulk-delete' ),
436
						'https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format'
437
					);
438
					?>
439
				</p>
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() {
475
		$tags = $this->get_tags();
476
		?>
477
478
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>"
479
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>"
480
				data-taxonomy="post_tag" multiple>
481
482
			<option value="all">
483
				<?php _e( 'All Tags', 'bulk-delete' ); ?>
484
			</option>
485
486
			<?php foreach ( $tags as $tag ) : ?>
487
				<option value="<?php echo absint( $tag->term_id ); ?>">
488
					<?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
489
				</option>
490
			<?php endforeach; ?>
491
		</select>
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 ),
0 ignored issues
show
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

538
									__( 'Published on', 'bulk-delete' ), ' ', get_the_date( /** @scrutinizer ignore-type */ get_option( 'date_format' ), $post->ID ),
Loading history...
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

538
									__( 'Published on', 'bulk-delete' ), ' ', /** @scrutinizer ignore-type */ get_the_date( get_option( 'date_format' ), $post->ID ),
Loading history...
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 = '' ) {
660
		if ( empty( $item_type ) ) {
661
			$item_type = $this->item_type;
662
		}
663
		bd_render_limit_settings( $this->field_slug, $item_type );
664
	}
665
666
	/**
667
	 * Render cron settings based on whether scheduler is present or not.
668
	 */
669
	protected function render_cron_settings() {
670
		$pro_class = '';
671
672
		$disabled_attr = 'disabled';
673
		if ( empty( $this->scheduler_url ) ) {
674
			$disabled_attr = '';
675
		}
676
		?>
677
678
		<tr>
679
			<td scope="row" colspan="2">
680
				<label>
681
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio"
682
					checked="checked" class="schedule-deletion">
683
					<?php _e( 'Delete now', 'bulk-delete' ); ?>
684
				</label>
685
686
				<label>
687
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio"
688
					class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>>
689
					<?php _e( 'Schedule', 'bulk-delete' ); ?>
690
				</label>
691
692
				<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start"
693
					id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now"
694
					type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?>
695
696
				<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq"
697
						id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>>
698
699
					<option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option>
700
					<?php
701
					/**
702
					 * List of cron schedules.
703
					 *
704
					 * @since 6.0.0
705
					 *
706
					 * @param array                                   $cron_schedules List of cron schedules.
707
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module         Module.
708
					 */
709
					$cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this );
710
					?>
711
712
					<?php foreach ( $cron_schedules as $key => $value ) : ?>
713
						<option
714
							value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option>
715
					<?php endforeach; ?>
716
				</select>
717
718
				<?php if ( ! empty( $this->scheduler_url ) ) : ?>
719
					<?php
720
					$pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro';
721
722
					/**
723
					 * HTML class of the span that displays the 'Pro only feature' message.
724
					 *
725
					 * @since 6.0.0
726
					 *
727
					 * @param string                                  $pro_class  HTML class.
728
					 * @param string                                  $field_slug Field Slug of module.
729
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module     Module.
730
					 */
731
					$pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this )
732
					?>
733
734
					<span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red">
735
						<?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a
736
							href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a>
737
					</span>
738
				<?php endif; ?>
739
			</td>
740
		</tr>
741
742
		<tr
743
		<?php if ( ! empty( $pro_class ) ) : ?>
744
			class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;"
745
		<?php endif; ?>
746
		>
747
748
			<td scope="row" colspan="2">
749
				<?php
750
				_e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' );
751
752
				$markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . '&nbsp' .
753
					'<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>';
754
755
				$content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' );
756
				echo '&nbsp', bd_generate_help_tooltip( $markup, $content );
757
				?>
758
			</td>
759
		</tr>
760
		<?php
761
	}
762
763
	/**
764
	 * Render submit button.
765
	 */
766
	protected function render_submit_button() {
767
		bd_render_submit_button( $this->action );
768
	}
769
}
770