admin.php
4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
namespace q\eud\api;
// import classes ##
use q\eud;
use q\eud\plugin;
use q\eud\core\core;
use q\eud\core\helper as h;
class admin {
private $plugin;
function __construct(){
$this->plugin = plugin::get_instance();
}
/**
* Render admin fields
*
* @since 2.0.0.
* @return HTML
*/
function render( $array = null ){
// check if we have any fields to show ##
if (
is_null( $array )
|| ! is_array( $array )
) {
return false;
}
// check that we have all required arrays ##
if (
! $array['title'] // string ##
|| ! $array['label'] // lowercase string ##
|| ! $array['type']
) {
return false;
}
// is this toggleable ? ##
$toggleable = false === $array['title'] ? 'standard' : 'toggleable' ;
// keep labels formatted nicely ##
$array['label'] = \sanitize_key( $array['label'] );
// build out options ##
if ( ! self::has_options( $array ) ) {
return false;
}
?>
<tr valign="top" class="<?php \esc_attr_e( $toggleable ); ?>">
<th scope="row"><label for="q_eud_<?php \esc_attr_e( $array['label'] ); ?>"><?php \esc_attr_e( $array['title'] ); ?></label></th>
<td>
<?php
// options ##
self::build_options( $array );
// do we have a description ? ##
if ( isset( $array['description'] ) ) {
?>
<p class="description"><?php \esc_attr_e( $array['description'] ); ?></p>
<?php
}
?>
</td>
</tr>
<?php
}
public static function has_options( $array = null ){
if (
is_null( $array )
|| ! is_array( $array )
|| ! isset( $array['options'] )
|| ! isset( $array['label'] )
|| ! is_array( $array['options'] )
|| ! isset( $array['options_ID'] )
|| ! isset( $array['options_title'] )
|| ! isset( $array['label_select'] )
) {
return false;
}
// crude ##
return true;
}
public static function build_options( $array = null ){
if (
is_null( $array )
|| ! is_array( $array )
|| ! isset( $array['type'] )
) {
return false;
}
// start empty ##
$return = false;
switch ( $array['type'] ) {
case ( 'select' ) :
$return = self::field_select( $array );
break ;
}
// kick it back ##
return $return;
}
public static function field_select( $array = null ){
if (
is_null( $array )
|| ! is_array( $array )
|| ! isset( $array['options'] )
|| ! isset( $array['label'] )
|| ! is_array( $array['options'] )
|| ! isset( $array['options_ID'] )
|| ! isset( $array['options_title'] )
|| ! isset( $array['label_select'] )
) {
return false;
}
// is this a multiselect ? ##
$multiselect = isset( $array['multiselect'] ) ? ' multiple="multiple"' : '' ;
?>
<select <?php \esc_attr_e( $multiselect ); ?> name="<?php \esc_attr_e( $array['label'] ); ?>" id="q_eud_<?php \esc_attr_e( $array['label'] ); ?>">
<?php
// label ##
echo '<option value="">'.\esc_attr( $array['label_select'] ).'</option>';
// loop over all options ##
foreach ( $array['options'] as $item ) {
// id ##
$id = $item->{$array['options_ID']}; // ID
// title
$title = $item->{$array['options_title']}; // post_title ##
// check if option built ##
if (
! $id
|| ! $title
) {
continue;
}
?>
<option value='<?php \esc_attr_e( $id ); ?>'><?php esc_attr_e( $title ); ?></option>
<?php
}
?>
</select>
<?php
}
}