|
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="select2-post" 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
|
|
|
protected function split_post_type_and_status( $str ) { |
|
73
|
|
|
$type_status = array(); |
|
74
|
|
|
|
|
75
|
|
|
$str_arr = explode( '-', $str ); |
|
76
|
|
|
|
|
77
|
|
|
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
|
|
|
$type_status['status'] = 'publish'; |
|
82
|
|
|
$type_status['type'] = $str; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
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
|
|
|
$types = bd_get_post_types(); |
|
113
|
|
|
?> |
|
114
|
|
|
<tr> |
|
115
|
|
|
<td scope="row" > |
|
116
|
|
|
<select class="select2" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_post_type"> |
|
117
|
|
|
<?php foreach ( $types as $type ) : ?> |
|
118
|
|
|
<option value="<?php echo esc_attr( $type->name ); ?>"> |
|
119
|
|
|
<?php echo esc_html( $type->labels->singular_name . ' (' . $type->name . ')' ); ?> |
|
120
|
|
|
</option> |
|
121
|
|
|
<?php endforeach; ?> |
|
122
|
|
|
</select> |
|
123
|
|
|
</td> |
|
124
|
|
|
</tr> |
|
125
|
|
|
<?php |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Render Taxonomy dropdown. |
|
130
|
|
|
*/ |
|
131
|
|
|
protected function render_taxonomy_dropdown() { |
|
132
|
|
|
$taxonomies = get_taxonomies( array(), 'objects' ); |
|
133
|
|
|
?> |
|
134
|
|
|
<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_taxonomy" class="select2" multiple="multiple" data-placeholder="<?php _e( 'Select Taxonomy', 'bulk-delete' ); ?>"> |
|
135
|
|
|
<?php foreach ( $taxonomies as $role => $taxonomy ) : ?> |
|
136
|
|
|
<option value="<?php echo esc_attr( $taxonomy->name ); ?>"> |
|
137
|
|
|
<?php echo esc_html( $taxonomy->label ); ?> |
|
138
|
|
|
</option> |
|
139
|
|
|
<?php endforeach; ?> |
|
140
|
|
|
</select> |
|
141
|
|
|
<?php |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Render term options. |
|
146
|
|
|
*/ |
|
147
|
|
|
protected function render_term_options() { |
|
148
|
|
|
?> |
|
149
|
|
|
<h4><?php _e( 'Delete terms that', 'bulk-delete' ); ?></h4> |
|
150
|
|
|
<select name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_opt"> |
|
151
|
|
|
<?php if( $this->field_slug == 'by_name' ){ ?> |
|
152
|
|
|
<option value="equal_to">equal to</option> |
|
153
|
|
|
<option value="not_equal_to">not equal to</option> |
|
154
|
|
|
<option value="starts">starts</option> |
|
155
|
|
|
<option value="ends">ends</option> |
|
156
|
|
|
<option value="contains">contains</option> |
|
157
|
|
|
<option value="non_contains">non contains</option> |
|
158
|
|
|
<?php }elseif( $this->field_slug == 'by_post_count' ){ ?> |
|
159
|
|
|
<option value="equal_to">equal to</option> |
|
160
|
|
|
<option value="not_equal_to">not equal to</option> |
|
161
|
|
|
<option value="less_than">less than</option> |
|
162
|
|
|
<option value="greater_than">greater than</option> |
|
163
|
|
|
<?php }?> |
|
164
|
|
|
</select> With |
|
165
|
|
|
<input type="text" name="smbd_<?php echo esc_attr( $this->field_slug ); ?>_term_text"> |
|
166
|
|
|
<?php |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Render have post settings. |
|
171
|
|
|
*/ |
|
172
|
|
|
protected function render_have_post_settings() { |
|
173
|
|
|
?> |
|
174
|
|
|
<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> |
|
175
|
|
|
<?php |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|