Completed
Push — 178-feature/delete-terms--by-p... ( 870088...49e5db )
by Sudar
35:16 queued 20:25
created

Renderer::are_private_posts_present()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
	 * Render Post Types as radio buttons.
18
	 */
19
	protected function render_post_type_as_radios() {
20
		$field_slug = $this->field_slug;
21
22
		$post_types = $this->get_post_types();
23
		?>
24
25
		<?php foreach ( $post_types as $post_type ) : ?>
26
27
			<tr>
28
				<td scope="row">
29
					<input type="radio" name="<?php echo esc_attr( $field_slug ); ?>_post_type"
30
						value="<?php echo esc_attr( $post_type->name ); ?>"
31
						id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
32
33
					<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
34
						<?php echo esc_html( $post_type->label ); ?>
35
					</label>
36
				</td>
37
			</tr>
38
39
		<?php endforeach; ?>
40
		<?php
41
	}
42
43
	/**
44
	 * Render Post type with status and post count checkboxes.
45
	 */
46
	protected function render_post_type_with_status() {
47
		$post_types_by_status = $this->get_post_types_by_status();
48
		?>
49
		<tr>
50
			<td scope="row" colspan="2">
51
				<select class="enhanced-post-types-with-status" multiple="multiple" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]">
52
				<?php foreach ( $post_types_by_status as $post_type => $all_status ) : ?>
53
					<optgroup label="<?php echo esc_html( $post_type ); ?>">
54
					<?php foreach ( $all_status as $status_key => $status_value ) : ?>
55
						<option value="<?php echo esc_attr( $status_key ); ?>"><?php echo esc_html( $status_value ); ?></option>
56
					<?php endforeach; ?>
57
					</optgroup>
58
				<?php endforeach; ?>
59
				</select>
60
			</td>
61
		</tr>
62
		<?php
63
	}
64
65
	/**
66
	 * Split post type and status.
67
	 *
68
	 * @param string $str Post type and status combination.
69
	 *
70
	 * @return array Post type and status as elements of array.
71
	 */
72 9
	protected function split_post_type_and_status( $str ) {
73 9
		$type_status = array();
74
75 9
		$str_arr = explode( '-', $str );
76
77 9
		if ( count( $str_arr ) > 1 ) {
78
			$type_status['status'] = end( $str_arr );
79
			$type_status['type']   = implode( '-', array_slice( $str_arr, 0, - 1 ) );
80
		} else {
81 9
			$type_status['status'] = 'publish';
82 9
			$type_status['type']   = $str;
83
		}
84
85 9
		return $type_status;
86
	}
87
88
	/**
89
	 * Render user role dropdown.
90
	 */
91
	protected function render_user_role_dropdown() {
92
		global $wp_roles;
93
		?>
94
95
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_roles[]" class="select2"
96
				multiple="multiple" data-placeholder="<?php _e( 'Select User Role', 'bulk-delete' ); ?>">
97
98
			<?php foreach ( $wp_roles->roles as $role => $role_details ) : ?>
99
				<option value="<?php echo esc_attr( $role ); ?>">
100
					<?php echo esc_html( $role_details['name'] ), ' (', absint( $this->get_user_count_by_role( $role ) ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?>
101
				</option>
102
			<?php endforeach; ?>
103
		</select>
104
105
		<?php
106
	}
107
108
	/**
109
	 * Render Post type dropdown.
110
	 */
111
	protected function render_post_type_dropdown() {
112
		bd_render_post_type_dropdown( $this->field_slug );
113
	}
114
115
	/**
116
	 * Render Taxonomy dropdown.
117
	 */
118
	protected function render_taxonomy_dropdown() {
119
		$taxonomies = get_taxonomies( array(), 'objects' );
120
		?>
121
122
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy" class="enhanced-taxonomy-list" data-placeholder="<?php _e( 'Select Taxonomy', 'bulk-delete' ); ?>">
123
			<?php foreach ( $taxonomies as $taxonomy ) : ?>
124
				<option value="<?php echo esc_attr( $taxonomy->name ); ?>">
125
					<?php echo esc_html( $taxonomy->label ); ?>
126
				</option>
127
			<?php endforeach; ?>
128
		</select>
129
		<?php
130
	}
131
132
	/**
133
	 * Render Category dropdown.
134
	 */
135
	protected function render_category_dropdown() {
136
		$categories = $this->get_categories();
137
		?>
138
139
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>"
140
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>"
0 ignored issues
show
Bug introduced by
The method enable_ajax_if_needed_to_dropdown_class_name() does not exist on BulkWP\BulkDelete\Core\Base\Mixin\Renderer. Since it exists in all sub-types, consider adding an abstract or default implementation to BulkWP\BulkDelete\Core\Base\Mixin\Renderer. ( Ignorable by Annotation )

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

140
				class="<?php echo sanitize_html_class( $this->/** @scrutinizer ignore-call */ enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>"
Loading history...
141
				data-taxonomy="category" multiple>
142
143
			<option value="all">
144
				<?php _e( 'All Categories', 'bulk-delete' ); ?>
145
			</option>
146
147
			<?php foreach ( $categories as $category ) : ?>
148
				<option value="<?php echo absint( $category->cat_ID ); ?>">
149
					<?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
150
				</option>
151
			<?php endforeach; ?>
152
153
		</select>
154
		<?php
155
	}
156
157
	/**
158
	 * Render String based comparison operators dropdown.
159
	 */
160
	protected function render_string_comparison_operators() {
161
		?>
162
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator">
163
			<option value="equal_to"><?php _e( 'equal to', 'bulk-delete' ); ?></option>
164
			<option value="not_equal_to"><?php _e( 'not equal to', 'bulk-delete' ); ?></option>
165
			<option value="starts_with"><?php _e( 'starts with', 'bulk-delete' ); ?></option>
166
			<option value="ends_with"><?php _e( 'ends with', 'bulk-delete' ); ?></option>
167
			<option value="contains"><?php _e( 'contains', 'bulk-delete' ); ?></option>
168
			<option value="not_contains"><?php _e( 'not contains', 'bulk-delete' ); ?></option>
169
		</select>
170
		<?php
171
	}
172
173
	/**
174
	 * Render number based comparison operators dropdown.
175
	 */
176
	protected function render_number_comparison_operators() {
177
		?>
178
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_operator">
179
			<option value="equal_to"><?php _e( 'equal to', 'bulk-delete' ); ?></option>
180
			<option value="not_equal_to"><?php _e( 'not equal to', 'bulk-delete' ); ?></option>
181
			<option value="less_than"><?php _e( 'less than', 'bulk-delete' ); ?></option>
182
			<option value="greater_than"><?php _e( 'greater than', 'bulk-delete' ); ?></option>
183
		</select>
184
		<?php
185
	}
186
187
	/**
188
	 * Render Tags dropdown.
189
	 */
190
	protected function render_tags_dropdown() {
191
		$tags = $this->get_tags();
192
		?>
193
194
		<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>"
195
				class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>"
196
				data-taxonomy="post_tag" multiple>
197
198
			<option value="all">
199
				<?php _e( 'All Tags', 'bulk-delete' ); ?>
200
			</option>
201
202
			<?php foreach ( $tags as $tag ) : ?>
203
				<option value="<?php echo absint( $tag->term_id ); ?>">
204
					<?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?>
205
				</option>
206
			<?php endforeach; ?>
207
		</select>
208
		<?php
209
	}
210
211
	/**
212
	 * Render Sticky Posts dropdown.
213
	 */
214
	protected function render_sticky_post_dropdown() {
215
		$posts = $this->get_sticky_posts();
216
		?>
217
		<table class="optiontable">
218
			<tr>
219
				<td scope="row">
220
					<input type="checkbox" class="smbd_sticky_post_options" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="All">
221
					<label>All</label>
222
				</td>
223
			</tr>
224
			<?php
225
			foreach ( $posts as $post ) :
226
				$user = get_userdata( $post->post_author );
227
				?>
228
			<tr>
229
				<td scope="row">
230
				<input type="checkbox" class="smbd_sticky_post_options" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>">
231
				<label><?php echo esc_html( $post->post_title . ' Published by ' . $user->display_name . ' on ' . $post->post_date ); ?></label>
232
				</td>
233
			</tr>
234
			<?php endforeach; ?>
235
		</table>
236
		<?php
237
	}
238
239
	/**
240
	 * Render have post settings.
241
	 */
242
	protected function render_have_post_settings() {
243
		?>
244
		<p><label for="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts"><input type="checkbox" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts" id="smbd_<?php echo esc_attr( $this->field_slug ); ?>_no_posts"> <?php _e( 'Only if it doesn\'t contain any post', 'bulk-delete' ); ?></label></p>
245
		<?php
246
	}
247
248
	/**
249
	 * Render Post Types as checkboxes.
250
	 *
251
	 * @since 5.6.0
252
	 *
253
	 * @param string $name Name of post type checkboxes.
254
	 */
255
	protected function render_post_type_checkboxes( $name ) {
256
		$post_types = bd_get_post_types();
257
		?>
258
259
		<?php foreach ( $post_types as $post_type ) : ?>
260
261
		<tr>
262
			<td scope="row">
263
				<input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>"
264
					id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked>
265
266
				<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>">
267
					<?php echo esc_html( $post_type->label ); ?>
268
				</label>
269
			</td>
270
		</tr>
271
272
		<?php endforeach; ?>
273
		<?php
274
	}
275
276
	/**
277
	 * Render the "private post" setting fields.
278
	 */
279
	protected function render_private_post_settings() {
280
		bd_render_private_post_settings( $this->field_slug );
281
	}
282
283
	/**
284
	 * Get the threshold after which enhanced select should be used.
285
	 *
286
	 * @return int Threshold.
287
	 */
288
	protected function get_enhanced_select_threshold() {
289
		/**
290
		 * Filter the enhanced select threshold.
291
		 *
292
		 * @since 6.0.0
293
		 *
294
		 * @param int Threshold.
295
		 */
296
		return apply_filters( 'bd_enhanced_select_threshold', 1000 );
297
	}
298
}
299