Completed
Push — fix/706-generic-operators-logi... ( b58368 )
by Sudar
10:21
created

Renderer::render_limit_settings()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 10
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><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="false" type="radio"
159
					checked="checked" class="post-reassign"> <?php _e( 'Also delete all posts of the users', 'bulk-delete' ); ?></label>
160
				<label><input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" value="true" type="radio"
161
					id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_reassign" class="post-reassign"> <?php _e( 'Re-assign the posts to', 'bulk-delete' ); ?></label>
162
				<?php
163
				wp_dropdown_users(
164
					array(
165
						'name'             => 'smbd_' . esc_attr( $this->field_slug ) . '_reassign_user_id',
166
						'class'            => 'reassign-user',
167
						'show_option_none' => __( 'Select User', 'bulk-delete' ),
168
					)
169
				);
170
				?>
171
			</td>
172
		</tr>
173
		<?php
174
	}
175
176
	/**
177
	 * Render user role dropdown.
178
	 *
179
	 * @param bool $show_users_with_no_roles Should users with no user roles be shown? Default false.
180
	 */
181
	protected function render_user_role_dropdown( $show_users_with_no_roles = false ) {
182
		$roles       = get_editable_roles();
183
		$users_count = count_users();
184
		?>
185
186
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="enhanced-role-dropdown"
187
				multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>">
188
189
			<?php foreach ( $roles as $role => $role_details ) : ?>
190
				<option value="<?php echo esc_attr( $role ); ?>">
191
					<?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role, $users_count ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?>
192
				</option>
193
			<?php endforeach; ?>
194
195
			<?php if ( $show_users_with_no_roles ) : ?>
196
				<?php if ( isset( $users_count['avail_roles']['none'] ) && $users_count['avail_roles']['none'] > 0 ) : ?>
197
					<option value="none">
198
						<?php echo __( 'No role', 'bulk-delete' ), ' (', absint( $users_count['avail_roles']['none'] ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?>
199
					</option>
200
				<?php endif; ?>
201
			<?php endif; ?>
202
		</select>
203
204
		<?php
205
	}
206
207
	/**
208
	 * Render Post type dropdown.
209
	 */
210
	protected function render_post_type_dropdown() {
211
		bd_render_post_type_dropdown( $this->field_slug );
212
	}
213
214
	/**
215
	 * Render Taxonomy dropdown.
216
	 */
217
	protected function render_taxonomy_dropdown() {
218
		$builtin_taxonomies = get_taxonomies( array( '_builtin' => true ), 'objects' );
219
		$custom_taxonomies  = get_taxonomies( array( '_builtin' => false ), 'objects' );
220
		?>
221
			<select class="enhanced-dropdown" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy">
222
				<optgroup label="<?php esc_attr_e( 'Built-in Taxonomies', 'bulk-delete' ); ?>">
223
					<?php foreach ( $builtin_taxonomies as $taxonomy ) : ?>
224
						<option value="<?php echo esc_attr( $taxonomy->name ); ?>">
225
							<?php echo esc_html( $taxonomy->label . ' (' . $taxonomy->name . ')' ); ?>
226
						</option>
227
					<?php endforeach; ?>
228
				</optgroup>
229
230
				<?php if ( ! empty( $custom_taxonomies ) ): ?>
231
					<optgroup label="<?php esc_attr_e( 'Custom Taxonomies', 'bulk-delete' ); ?>">
232
						<?php foreach ( $custom_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
				<?php endif; ?>
239
			</select>
240
		<?php
241
	}
242
243
	/**
244
	 * Render Category dropdown.
245
	 */
246
	protected function render_category_dropdown() {
247
		$categories = $this->get_categories();
248
		?>
249
250
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>"
251
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>"
252
				data-taxonomy="category" multiple>
253
254
			<option value="all">
255
				<?php _e( 'All Categories', 'bulk-delete' ); ?>
256
			</option>
257
258
			<?php foreach ( $categories as $category ) : ?>
259
				<option value="<?php echo absint( $category->cat_ID ); ?>">
260
					<?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
261
				</option>
262
			<?php endforeach; ?>
263
264
		</select>
265
		<?php
266
	}
267
268
	/**
269
	 * Render String based comparison operators dropdown.
270
	 */
271
	protected function render_string_comparison_operators() {
272
		?>
273
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator">
274
			<option value="equal_to"><?php _e( 'equal to', 'bulk-delete' ); ?></option>
275
			<option value="not_equal_to"><?php _e( 'not equal to', 'bulk-delete' ); ?></option>
276
			<option value="starts_with"><?php _e( 'starts with', 'bulk-delete' ); ?></option>
277
			<option value="ends_with"><?php _e( 'ends with', 'bulk-delete' ); ?></option>
278
			<option value="contains"><?php _e( 'contains', 'bulk-delete' ); ?></option>
279
			<option value="not_contains"><?php _e( 'not contains', 'bulk-delete' ); ?></option>
280
		</select>
281
		<?php
282
	}
283
284
	/**
285
	 * Render number based comparison operators dropdown.
286
	 */
287
	protected function render_number_comparison_operators() {
288
		?>
289
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator">
290
			<option value="="><?php _e( 'equal to', 'bulk-delete' ); ?></option>
291
			<option value="!="><?php _e( 'not equal to', 'bulk-delete' ); ?></option>
292
			<option value="<"><?php _e( 'less than', 'bulk-delete' ); ?></option>
293
			<option value=">"><?php _e( 'greater than', 'bulk-delete' ); ?></option>
294
		</select>
295
		<?php
296
	}
297
298
	/**
299
	 * Render data types dropdown.
300
	 */
301
	protected function render_data_types_dropdown() {
302
		?>
303
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_type" class="meta-type">
304
			<option value="numeric"><?php _e( 'Number', 'bulk-delete' ); ?></option>
305
			<option value="char"><?php _e( 'Character', 'bulk-delete' ); ?></option>
306
			<option value="date"><?php _e( 'Date', 'bulk-delete' ); ?></option>
307
		</select>
308
		<?php
309
	}
310
311
	/**
312
	 * Render numeric comparison operators dropdown.
313
	 *
314
	 * @param string $class     Class to be applied.
315
	 * @param array  $operators List of Operators needed.
316
	 */
317
	protected function render_numeric_operators_dropdown( $class = 'numeric', $operators = array( 'all' ) ) {
318
		$all_numeric_operators = array(
319
			'='           => 'equal to',
320
			'!='          => 'not equal to',
321
			'<'           => 'less than',
322
			'<='          => 'less than or equal to',
323
			'>'           => 'greater than',
324
			'>='          => 'greater than or equal to',
325
			'IN'          => 'in',
326
			'NOT IN'      => 'not in',
327
			'BETWEEN'     => 'between',
328
			'NOT BETWEEN' => 'not between',
329
			'EXISTS'      => 'exists',
330
			'NOT EXISTS'  => 'not exists',
331
		);
332
		if ( in_array( 'all', $operators, true ) ) {
333
			$operators = array_keys( $all_numeric_operators );
334
		}
335
		?>
336
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class= "<?php echo esc_attr( $class ); ?>">
337
		<?php
338
		foreach ( $operators as $operator ) {
339
			echo '<option value="' . $operator . '">' . __( $all_numeric_operators[ $operator ], 'bulk-delete' ) . '</option>';
340
		}
341
		?>
342
		</select>
343
		<?php
344
	}
345
346
	/**
347
	 * Render string comparison operators dropdown.
348
	 *
349
	 * @param string $class     Class to be applied.
350
	 * @param array  $operators List of Operators needed.
351
	 */
352
	protected function render_string_operators_dropdown( $class = 'string', $operators = array( 'all' ) ) {
353
		// STARTS_WITH and ENDS_WITH operators needs a handler as SQL does not support these operators in queries.
354
		$all_string_operators = array(
355
			'='           => 'equal to',
356
			'!='          => 'not equal to',
357
			'IN'          => 'in',
358
			'NOT IN'      => 'not in',
359
			'LIKE'        => 'contains',
360
			'NOT LIKE'    => 'not contains',
361
			'EXISTS'      => 'exists',
362
			'NOT EXISTS'  => 'not exists',
363
			'STARTS_WITH' => 'starts with',
364
			'ENDS_WITH'   => 'ends with',
365
		);
366
		if ( in_array( 'all', $operators, true ) ) {
367
			$operators = array_keys( $all_string_operators );
368
		}
369
		?>
370
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo esc_attr( $class ); ?>">
371
		<?php
372
		foreach ( $operators as $operator ) {
373
			echo '<option value="' . $operator . '">' . __( $all_string_operators[ $operator ], 'bulk-delete' ) . '</option>';
374
		}
375
		?>
376
		</select>
377
		<?php
378
	}
379
380
	protected function render_meta_value_filter( $options = [] ) {
381
		$defaults = [
382
			'class'             => 'value-filters',
383
			'label'             => __( 'Meta Value', 'bulk-delete' ),
384
			'numeric_operators' => [ 'equals', 'numeric', 'ins', 'betweens', 'EXISTS' ],
385
			'string_operators'  => [ 'equals', 'ins', 'likes', 'string-start-end', 'EXISTS' ],
386
			'date_operators'    => [ 'equals', 'numeric', 'EXISTS' ],
387
		];
388
389
		$options = wp_parse_args( $options, $defaults );
390
		?>
391
392
		<tr class="<?php echo esc_attr( $options['class'] ); ?>">
393
			<td>
394
				<?php echo esc_html( $options['label'] ); ?>
395
				<?php $this->render_data_types_dropdown(); ?>
396
				<?php $this->render_operators_dropdown( $options['numeric_operators'], 'meta-operators-numeric' ); ?>
397
				<?php $this->render_operators_dropdown( $options['string_operators'], 'meta-operators-char' ); ?>
398
				<?php $this->render_operators_dropdown( $options['date_operators'], 'meta-operators-date' ); ?>
399
400
				<input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_value"
401
						id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_value" class="date-picker">
402
403
				<span class="date-fields">
404
					<?php _e( 'Or', 'bulk-delete' ); ?>
405
406
					<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">
407
						<option value=""><?php _e( 'Select Relative date', 'bulk-delete' ); ?></option>
408
						<option value="yesterday"><?php _e( 'Yesterday', 'bulk-delete' ); ?></option>
409
						<option value="today"><?php _e( 'Today', 'bulk-delete' ); ?></option>
410
						<option value="tomorrow"><?php _e( 'Tomorrow', 'bulk-delete' ); ?></option>
411
						<option value="custom"><?php _e( 'Custom', 'bulk-delete' ); ?></option>
412
					</select>
413
414
					<?php echo apply_filters( 'bd_help_tooltip', '', __( 'You can select a date or enter a date which is relative to today.', 'bulk-delete' ) ); ?>
415
				</span>
416
417
				<span class="custom-date-fields">
418
					<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%;">
419
					<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_type" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_type">
420
						<option value="day"><?php _e( 'Day', 'bulk-delete' ); ?></option>
421
						<option value="week"><?php _e( 'Week', 'bulk-delete' ); ?></option>
422
						<option value="month"><?php _e( 'Month', 'bulk-delete' ); ?></option>
423
						<option value="year"><?php _e( 'Year', 'bulk-delete' ); ?></option>
424
					</select>
425
				</span>
426
			</td>
427
		</tr>
428
429
		<tr class="date-format-fields">
430
			<td>
431
				<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_format">
432
					<?php _e( 'Meta value date format', 'bulk-delete' ); ?>
433
				</label>
434
435
				<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_date_format" placeholder="%Y-%m-%d">
436
437
				<?php echo apply_filters( 'bd_help_tooltip', '', __( "If you leave date format blank, then '%Y-%m-%d', will be assumed.", 'bulk-delete' ) ); ?>
438
				<p>
439
					<?php
440
					printf(
441
						/* translators: 1 Mysql Format specifier url.  */
442
						__( '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>.', 'bulk-delete' ),
443
						'https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format'
444
					);
445
					?>
446
				</p>
447
			</td>
448
		</tr>
449
450
		<?php
451
	}
452
453
	/**
454
	 * Render Operators dropdown.
455
	 *
456
	 * @since 6.1.0
457
	 *
458
	 * @param array  $operators List of operators. Can use placeholders as well.
459
	 * @param string $class     HTML class.
460
	 *
461
	 * @see   \BulkWP\BulkDelete\Core\Base\Mixin\OperatorHelpers::resolve_operator() for the list of placeholders
462
	 */
463
	protected function render_operators_dropdown( $operators, $class = 'operators' ) {
464
		$operators = $this->resolve_operators( $operators );
465
		?>
466
467
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator" class="<?php echo sanitize_html_class( $class ); ?>">
468
			<?php foreach ( $operators as $operator ) : ?>
469
				<option value="<?php echo esc_attr( $operator ); ?>">
470
					<?php echo esc_html( $this->get_operator_label( $operator ) ); ?>
471
				</option>
472
			<?php endforeach; ?>
473
		</select>
474
475
		<?php
476
	}
477
478
	/**
479
	 * Render Tags dropdown.
480
	 */
481
	protected function render_tags_dropdown() {
482
		$tags = $this->get_tags();
483
		?>
484
485
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>"
486
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>"
487
				data-taxonomy="post_tag" multiple>
488
489
			<option value="all">
490
				<?php _e( 'All Tags', 'bulk-delete' ); ?>
491
			</option>
492
493
			<?php foreach ( $tags as $tag ) : ?>
494
				<option value="<?php echo absint( $tag->term_id ); ?>">
495
					<?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
496
				</option>
497
			<?php endforeach; ?>
498
		</select>
499
		<?php
500
	}
501
502
	/**
503
	 * Get the class name for select2 dropdown based on the number of items present.
504
	 *
505
	 * @param int    $count      The number of items present.
506
	 * @param string $class_name Primary class name.
507
	 *
508
	 * @return string Class name.
509
	 */
510
	protected function enable_ajax_if_needed_to_dropdown_class_name( $count, $class_name ) {
511
		if ( $count >= $this->get_enhanced_select_threshold() ) {
512
			$class_name .= '-ajax';
513
		}
514
515
		return $class_name;
516
	}
517
518
	/**
519
	 * Render Sticky Posts dropdown.
520
	 */
521
	protected function render_sticky_posts_dropdown() {
522
		$sticky_posts = $this->get_sticky_posts();
523
		?>
524
525
		<table class="optiontable">
526
			<?php if ( count( $sticky_posts ) > 1 ) : ?>
527
				<tr>
528
					<td scope="row">
529
						<label>
530
							<input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="all">
531
							<?php echo __( 'All sticky posts', 'bulk-delete' ), ' (', count( $sticky_posts ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
532
						</label>
533
					</td>
534
				</tr>
535
			<?php endif; ?>
536
537
			<?php foreach ( $sticky_posts as $post ) : ?>
538
				<?php $author = get_userdata( $post->post_author ); ?>
539
				<tr>
540
					<td scope="row">
541
						<label>
542
							<input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>">
543
							<?php
544
								echo esc_html( $post->post_title ), ' - ',
545
									__( '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

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

545
									__( 'Published on', 'bulk-delete' ), ' ', /** @scrutinizer ignore-type */ get_the_date( get_option( 'date_format' ), $post->ID ),
Loading history...
546
									__( ' by ', 'bulk-delete' ), esc_html( $author->display_name );
547
							?>
548
						</label>
549
					</td>
550
				</tr>
551
			<?php endforeach; ?>
552
		</table>
553
		<?php
554
	}
555
556
	/**
557
	 * Renders exclude sticky posts checkbox.
558
	 */
559
	protected function render_exclude_sticky_settings() {
560
		if ( $this->are_sticky_posts_present() ) : // phpcs:ignore?>
561
		<tr>
562
			<td scope="row">
563
				<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">
564
			</td>
565
			<td>
566
				<label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_exclude_sticky"><?php _e( 'Exclude sticky posts', 'bulk-delete' ); ?></label>
567
			</td>
568
		</tr>
569
		<?php endif; // phpcs:ignore?>
570
		<?php
571
	}
572
573
	/**
574
	 * Render Post Types as checkboxes.
575
	 *
576
	 * @since 5.6.0
577
	 *
578
	 * @param string $name Name of post type checkboxes.
579
	 */
580
	protected function render_post_type_checkboxes( $name ) {
581
		$post_types = bd_get_post_types();
582
		?>
583
584
		<?php foreach ( $post_types as $post_type ) : ?>
585
586
		<tr>
587
			<td scope="row">
588
				<input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>"
589
					id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked>
590
591
				<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
592
					<?php echo esc_html( $post_type->label ); ?>
593
				</label>
594
			</td>
595
		</tr>
596
597
		<?php endforeach; ?>
598
		<?php
599
	}
600
601
	/**
602
	 * Render the "private post" setting fields.
603
	 */
604
	protected function render_private_post_settings() {
605
		bd_render_private_post_settings( $this->field_slug );
606
	}
607
608
	/**
609
	 * Render sticky settings.
610
	 */
611
	protected function render_sticky_action_settings() {
612
		?>
613
		<tr>
614
			<td scope="row" colspan="2">
615
				<label>
616
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="unsticky" type="radio" checked>
617
					<?php _e( 'Remove Sticky', 'bulk-delete' ); ?>
618
				</label>
619
				<label>
620
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_sticky_action" value="delete" type="radio">
621
					<?php _e( 'Delete Post', 'bulk-delete' ); ?>
622
				</label>
623
			</td>
624
		</tr>
625
		<?php
626
	}
627
628
	/**
629
	 * Render filtering table header.
630
	 */
631
	protected function render_filtering_table_header() {
632
		bd_render_filtering_table_header();
633
	}
634
635
	/**
636
	 * Render restrict settings.
637
	 */
638
	protected function render_restrict_settings() {
639
		bd_render_restrict_settings( $this->field_slug, $this->item_type );
640
	}
641
642
	/**
643
	 * Render delete settings.
644
	 *
645
	 * @since 6.1.0 Added $hide_trash  param.
646
	 *
647
	 * @param bool $hide_trash Show/Hide Move to trash radio button. Default false.
648
	 */
649
	protected function render_delete_settings( $hide_trash = false ) {
650
		bd_render_delete_settings( $this->field_slug, $hide_trash );
651
		/**
652
		 * This action is primarily for adding delete attachment settings.
653
		 *
654
		 * @since 6.0.0
655
		 *
656
		 * @param \BulkWP\BulkDelete\Core\Base\BaseModule The delete module.
657
		 */
658
		do_action( 'bd_render_attachment_settings', $this );
659
	}
660
661
	/**
662
	 * Render limit settings.
663
	 *
664
	 * @param string $item_type Item Type to be displayed in label.
665
	 */
666
	protected function render_limit_settings( $item_type = '' ) {
667
		if ( empty( $item_type ) ) {
668
			$item_type = $this->item_type;
669
		}
670
		bd_render_limit_settings( $this->field_slug, $item_type );
671
	}
672
673
	/**
674
	 * Render cron settings based on whether scheduler is present or not.
675
	 */
676
	protected function render_cron_settings() {
677
		$pro_class = '';
678
679
		$disabled_attr = 'disabled';
680
		if ( empty( $this->scheduler_url ) ) {
681
			$disabled_attr = '';
682
		}
683
		?>
684
685
		<tr>
686
			<td scope="row" colspan="2">
687
				<label>
688
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="false" type="radio"
689
					checked="checked" class="schedule-deletion">
690
					<?php _e( 'Delete now', 'bulk-delete' ); ?>
691
				</label>
692
693
				<label>
694
					<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" value="true" type="radio"
695
					class="schedule-deletion" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron" <?php echo esc_attr( $disabled_attr ); ?>>
696
					<?php _e( 'Schedule', 'bulk-delete' ); ?>
697
				</label>
698
699
				<input name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start"
700
					id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_start" value="now"
701
					type="text" <?php echo esc_attr( $disabled_attr ); ?> autocomplete="off"><?php _e( 'repeat ', 'bulk-delete' ); ?>
702
703
				<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq"
704
						id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_cron_freq" <?php echo esc_attr( $disabled_attr ); ?>>
705
706
					<option value="-1"><?php _e( "Don't repeat", 'bulk-delete' ); ?></option>
707
					<?php
708
					/**
709
					 * List of cron schedules.
710
					 *
711
					 * @since 6.0.0
712
					 *
713
					 * @param array                                   $cron_schedules List of cron schedules.
714
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module         Module.
715
					 */
716
					$cron_schedules = apply_filters( 'bd_cron_schedules', wp_get_schedules(), $this );
717
					?>
718
719
					<?php foreach ( $cron_schedules as $key => $value ) : ?>
720
						<option
721
							value="<?php echo esc_attr( $key ); ?>"><?php echo esc_html( $value['display'] ); ?></option>
722
					<?php endforeach; ?>
723
				</select>
724
725
				<?php if ( ! empty( $this->scheduler_url ) ) : ?>
726
					<?php
727
					$pro_class = 'bd-' . str_replace( '_', '-', $this->field_slug ) . '-pro';
728
729
					/**
730
					 * HTML class of the span that displays the 'Pro only feature' message.
731
					 *
732
					 * @since 6.0.0
733
					 *
734
					 * @param string                                  $pro_class  HTML class.
735
					 * @param string                                  $field_slug Field Slug of module.
736
					 * @param \BulkWP\BulkDelete\Core\Base\BaseModule $module     Module.
737
					 */
738
					$pro_class = apply_filters( 'bd_pro_only_feature_class', $pro_class, $this->field_slug, $this )
739
					?>
740
741
					<span class="<?php echo sanitize_html_class( $pro_class ); ?>" style="color:red">
742
						<?php _e( 'Only available in Pro Addon', 'bulk-delete' ); ?> <a
743
							href="<?php echo esc_url( $this->scheduler_url ); ?>" target="_blank">Buy now</a>
744
					</span>
745
				<?php endif; ?>
746
			</td>
747
		</tr>
748
749
		<tr
750
		<?php if ( ! empty( $pro_class ) ) : ?>
751
			class="<?php echo sanitize_html_class( $pro_class ); ?>" style="display: none;"
752
		<?php endif; ?>
753
		>
754
755
			<td scope="row" colspan="2">
756
				<?php
757
				_e( 'Enter time in <strong>Y-m-d H:i:s</strong> format or enter <strong>now</strong> to use current time.', 'bulk-delete' );
758
759
				$markup = __( 'Want to add new a Cron schedule?', 'bulk-delete' ) . '&nbsp' .
760
					'<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>';
761
762
				$content = __( 'Learn how to add your desired Cron schedule.', 'bulk-delete' );
763
				echo '&nbsp', bd_generate_help_tooltip( $markup, $content );
764
				?>
765
			</td>
766
		</tr>
767
		<?php
768
	}
769
770
	/**
771
	 * Render submit button.
772
	 */
773
	protected function render_submit_button() {
774
		bd_render_submit_button( $this->action );
775
	}
776
}
777