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
|
|
|
bd_render_user_role_dropdown( $this->field_slug ); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|