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
|
|
|
$users_count = count_users(); |
93
|
|
|
?> |
94
|
|
|
<select name="smbd_u_roles[]" class="select2" multiple="multiple" data-placeholder="<?php _e( 'Select Role', 'bulk-delete' ); ?>"> |
95
|
|
|
<?php foreach ( $users_count['avail_roles'] as $role => $count ) : ?> |
96
|
|
|
<?php |
97
|
|
|
$role_detail = get_role( $role ); |
98
|
|
|
$role_name = $role; |
99
|
|
|
|
100
|
|
|
if ( isset( $role_detail->name ) ) { |
101
|
|
|
$role_name = $role_detail->name; |
102
|
|
|
} |
103
|
|
|
?> |
104
|
|
|
|
105
|
|
|
<option value="<?php echo esc_attr( $role ); ?>"> |
106
|
|
|
<?php echo esc_html( $role_name ), '(', esc_html( $count ), ' ', __( 'Users', 'bulk-delete' ), ')'; ?> |
107
|
|
|
</option> |
108
|
|
|
<?php endforeach; ?> |
109
|
|
|
</select> |
110
|
|
|
<?php |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Render Post type dropdown. |
115
|
|
|
*/ |
116
|
|
|
protected function render_post_type_dropdown() { |
117
|
|
|
bd_render_post_type_dropdown( $this->field_slug ); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|