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 Category dropdown. |
117
|
|
|
*/ |
118
|
|
|
protected function render_category_dropdown() { |
119
|
|
|
$categories = $this->get_categories(); |
120
|
|
|
?> |
121
|
|
|
|
122
|
|
|
<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_category[]" data-placeholder="<?php _e( 'Select Categories', 'bulk-delete' ); ?>" |
123
|
|
|
class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $categories ), 'select2-taxonomy' ) ); ?>" |
|
|
|
|
124
|
|
|
data-taxonomy="category" multiple> |
125
|
|
|
|
126
|
|
|
<option value="all"> |
127
|
|
|
<?php _e( 'All Categories', 'bulk-delete' ); ?> |
128
|
|
|
</option> |
129
|
|
|
|
130
|
|
|
<?php foreach ( $categories as $category ) : ?> |
131
|
|
|
<option value="<?php echo absint( $category->cat_ID ); ?>"> |
132
|
|
|
<?php echo esc_html( $category->cat_name ), ' (', absint( $category->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
133
|
|
|
</option> |
134
|
|
|
<?php endforeach; ?> |
135
|
|
|
|
136
|
|
|
</select> |
137
|
|
|
<?php |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Render Tags dropdown. |
142
|
|
|
*/ |
143
|
|
|
protected function render_tags_dropdown() { |
144
|
|
|
$tags = $this->get_tags(); |
145
|
|
|
?> |
146
|
|
|
|
147
|
|
|
<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" data-placeholder="<?php _e( 'Select Tags', 'bulk-delete' ); ?>" |
148
|
|
|
class="<?php echo sanitize_html_class( $this->enable_ajax_if_needed_to_dropdown_class_name( count( $tags ), 'select2-taxonomy' ) ); ?>" |
149
|
|
|
data-taxonomy="post_tag" multiple> |
150
|
|
|
|
151
|
|
|
<option value="all"> |
152
|
|
|
<?php _e( 'All Tags', 'bulk-delete' ); ?> |
153
|
|
|
</option> |
154
|
|
|
|
155
|
|
|
<?php foreach ( $tags as $tag ) : ?> |
156
|
|
|
<option value="<?php echo absint( $tag->term_id ); ?>"> |
157
|
|
|
<?php echo esc_html( $tag->name ), ' (', absint( $tag->count ), ' ', __( 'Posts', 'bulk-delete' ), ')'; ?> |
158
|
|
|
</option> |
159
|
|
|
<?php endforeach; ?> |
160
|
|
|
</select> |
161
|
|
|
<?php |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Render Sticky Posts dropdown. |
166
|
|
|
*/ |
167
|
|
|
protected function render_sticky_post_dropdown() { |
168
|
|
|
$posts = $this->get_sticky_posts(); |
169
|
|
|
?> |
170
|
|
|
<table class="optiontable"> |
171
|
|
|
<tr> |
172
|
|
|
<td scope="row"> |
173
|
|
|
<input type="checkbox" class="smbd_sticky_post_options" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="All"> |
174
|
|
|
<label>All</label> |
175
|
|
|
</td> |
176
|
|
|
</tr> |
177
|
|
|
<?php |
178
|
|
|
foreach ( $posts as $post ) : |
179
|
|
|
$user = get_userdata( $post->post_author ); |
180
|
|
|
?> |
181
|
|
|
<tr> |
182
|
|
|
<td scope="row"> |
183
|
|
|
<input type="checkbox" class="smbd_sticky_post_options" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>[]" value="<?php echo absint( $post->ID ); ?>"> |
184
|
|
|
<label><?php echo esc_html( $post->post_title . ' Published by ' . $user->display_name . ' on ' . $post->post_date ); ?></label> |
185
|
|
|
</td> |
186
|
|
|
</tr> |
187
|
|
|
<?php endforeach; ?> |
188
|
|
|
</table> |
189
|
|
|
<?php |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Render Post Types as checkboxes. |
194
|
|
|
* |
195
|
|
|
* @since 5.6.0 |
196
|
|
|
* |
197
|
|
|
* @param string $name Name of post type checkboxes. |
198
|
|
|
*/ |
199
|
|
|
protected function render_post_type_checkboxes( $name ) { |
200
|
|
|
$post_types = bd_get_post_types(); |
201
|
|
|
?> |
202
|
|
|
|
203
|
|
|
<?php foreach ( $post_types as $post_type ) : ?> |
204
|
|
|
|
205
|
|
|
<tr> |
206
|
|
|
<td scope="row"> |
207
|
|
|
<input type="checkbox" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $post_type->name ); ?>" |
208
|
|
|
id="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>" checked> |
209
|
|
|
|
210
|
|
|
<label for="smbd_post_type_<?php echo esc_html( $post_type->name ); ?>"> |
211
|
|
|
<?php echo esc_html( $post_type->label ); ?> |
212
|
|
|
</label> |
213
|
|
|
</td> |
214
|
|
|
</tr> |
215
|
|
|
|
216
|
|
|
<?php endforeach; ?> |
217
|
|
|
<?php |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Get the threshold after which enhanced select should be used. |
222
|
|
|
* |
223
|
|
|
* @return int Threshold. |
224
|
|
|
*/ |
225
|
|
|
protected function get_enhanced_select_threshold() { |
226
|
|
|
/** |
227
|
|
|
* Filter the enhanced select threshold. |
228
|
|
|
* |
229
|
|
|
* @since 6.0.0 |
230
|
|
|
* |
231
|
|
|
* @param int Threshold. |
232
|
|
|
*/ |
233
|
|
|
return apply_filters( 'bd_enhanced_select_threshold', 1000 ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Check there is have any private post is exist. |
238
|
|
|
* |
239
|
|
|
* @since 6.0.0 |
240
|
|
|
* |
241
|
|
|
* @param string $post_type. |
242
|
|
|
* |
243
|
|
|
* @return bool |
244
|
|
|
*/ |
245
|
|
|
public function are_private_posts_present( $post_type='any') { |
246
|
|
|
$args = array( |
247
|
|
|
'post_status' => array( 'private' ), |
248
|
|
|
'post_type' => $post_type, |
249
|
|
|
); |
250
|
|
|
$query = new \WP_Query( $args ); |
251
|
|
|
|
252
|
|
|
return $query->have_posts(); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|