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 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-settings-fields-render.php
admin-site-enhancements / classes Last commit date
class-activation.php 3 years ago class-admin-interface.php 3 years ago class-content-management.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-security.php 3 years ago class-settings-fields-render.php 3 years ago class-settings-sanitization.php 3 years ago class-settings-sections-fields.php 3 years ago class-utilities.php 3 years ago
class-settings-fields-render.php
331 lines
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class related to rendering of settings fields on the admin page
7 *
8 * @since 2.2.0
9 */
10 class Settings_Fields_Render {
11
12 /**
13 * Render checkbox field as a toggle/switcher
14 *
15 * @since 1.0.0
16 */
17 function render_checkbox_toggle( $args ) {
18
19 $options = get_option( ASENHA_SLUG_U );
20
21 $field_name = $args['field_name'];
22 $field_description = $args['field_description'];
23 $field_option_value = ( array_key_exists( $args['field_id'], $options ) ) ? $options[$args['field_id']] : false;
24
25 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
26 echo '<label for="' . esc_attr( $field_name ) . '"></label>';
27
28 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
29 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
30 // For when the options / sub-fields occupy lengthy vertical space, we add show all / less toggler
31 if ( array_key_exists( 'field_options_moreless', $args ) && $args['field_options_moreless'] ) {
32 echo '<div class="asenha-field-with-options field-show-more">';
33 echo '<a id="' . $args['field_slug'] . '-show-moreless" class="show-more-less show-more" href="#">Expand &#9660;</a>';
34 echo '<div class="asenha-field-options-wrapper wrapper-show-more">';
35 } else {
36 echo '<div class="asenha-field-with-options">';
37 echo '<div class="asenha-field-options-wrapper">';
38 }
39
40 }
41
42 echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>';
43
44 // For field with additional options / sub-fields, we add wrapper for them
45 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
46 echo '<div class="asenha-subfields" style="display:none"></div>';
47 }
48
49
50 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
51 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
52 echo '</div>';
53 echo '</div>';
54 }
55
56 }
57
58 /**
59 * Render checkbox field as sub-field of a toggle/switcher checkbox
60 *
61 * @since 1.9.0
62 */
63 function render_checkbox_plain( $args ) {
64
65 $options = get_option( ASENHA_SLUG_U );
66
67 $field_name = $args['field_name'];
68 $field_label = $args['field_label'];
69 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : false;
70
71 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
72 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
73
74 }
75
76 /**
77 * Render checkbox field as sub-field of a toggle/switcher checkbox
78 *
79 * @since 1.3.0
80 */
81 function render_checkbox_subfield( $args ) {
82
83 $options = get_option( ASENHA_SLUG_U );
84
85 $field_name = $args['field_name'];
86 $field_label = $args['field_label'];
87 $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ) ? $options[$args['parent_field_id']][$args['field_id']] : false;
88
89 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
90 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
91
92 }
93
94 /**
95 * Render text field as sub-field of a toggle/switcher checkbox
96 *
97 * @since 1.4.0
98 */
99 function render_text_subfield( $args ) {
100
101 $options = get_option( ASENHA_SLUG_U );
102
103 $field_id = $args['field_id'];
104 $field_name = $args['field_name'];
105 $field_type = $args['field_type'];
106 $field_prefix = $args['field_prefix'];
107 $field_suffix = $args['field_suffix'];
108 $field_description = $args['field_description'];
109 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
110
111 if ( $field_id == 'custom_login_slug' ) {
112 $placeholder = 'e.g. backend';
113 } elseif ( $field_id == 'redirect_after_login_to_slug' ) {
114 $placeholder = 'e.g. my-account';
115 } elseif ( $field_id == 'redirect_after_logout_to_slug' ) {
116 $placeholder = 'e.g. come-visit-again';
117 } else {}
118
119 echo $field_prefix . '<input type="text" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix;
120 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
121
122 }
123
124 /**
125 * Render sortable menu field
126 *
127 * @since 2.0.0
128 */
129 function render_sortable_menu( $args ) {
130
131 ?>
132 <div class="subfield-description">Drag and drop menu items to the desired position and optionally hide them until "Show All" at the bottom of the admin menu is clicked.</div>
133 <ul id="custom-admin-menu" class="menu ui-sortable">
134 <?php
135
136 global $menu;
137 global $submenu;
138 $options = get_option( ASENHA_SLUG_U );
139
140 // Get hidden menu items
141 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
142 $hidden_menu = $options['custom_menu_hidden'];
143 $hidden_menu = explode( ',', $hidden_menu );
144 } else {
145 $hidden_menu = array();
146 }
147
148 $i = 1;
149
150 // Check if there's an existing custom menu order data stored in options
151
152 if ( array_key_exists( 'custom_menu_order', $options ) ) {
153
154 $custom_menu = $options['custom_menu_order'];
155 $custom_menu = explode( ',', $custom_menu );
156
157 // Render sortables with data in custom menu order
158
159 foreach ( $custom_menu as $custom_menu_item ) {
160
161 foreach ( $menu as $menu_key => $menu_info ) {
162
163 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
164 $menu_item_id = $menu_info[2];
165 } else {
166 $menu_item_id = $menu_info[5];
167 }
168
169 if ( $custom_menu_item == $menu_item_id ) {
170
171 ?>
172 <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
173 <div class="menu-item-bar">
174 <div class="menu-item-handle ui-sortable-handle">
175 <div class="item-title">
176 <span class="menu-item-title">
177 <?php
178
179 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
180 $separator_name = $menu_info[2];
181 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
182 $separator_name = str_replace( '--last', '-Last', $separator_name );
183 echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~';
184 } else {
185 echo wp_kses_post( $menu_info[0] );
186 }
187
188 ?>
189 </span>
190 <label class="menu-item-checkbox-label">
191 <?php
192 if ( in_array( $custom_menu_item, $hidden_menu ) ) {
193 ?>
194 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>" checked>
195 <span>Hide</span>
196 <?php
197 } else {
198 ?>
199 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>">
200 <span>Hide</span>
201 <?php
202 }
203 ?>
204 </label>
205 </div>
206 </div>
207 </div>
208 <?php
209
210 $i = 1;
211
212 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
213 ?>
214 <div class="menu-item-settings wp-clearfix" style="display:none;">
215 <?php
216
217 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
218
219 $i++;
220
221 // echo $submenu_item[0];
222
223 }
224 ?>
225 </div>
226 <?php
227
228 }
229 ?>
230 </li>
231
232 <?php
233
234 }
235
236 }
237
238 }
239
240 } else {
241
242 // Render sortables with existing items in the admin menu
243
244 foreach ( $menu as $menu_key => $menu_info ) {
245
246 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
247 $menu_item_id = $menu_info[2];
248 } else {
249 $menu_item_id = $menu_info[5];
250 }
251
252 ?>
253 <li id="<?php echo wp_kses_post( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
254 <div class="menu-item-bar">
255 <div class="menu-item-handle ui-sortable-handle">
256 <div class="item-title">
257 <span class="menu-item-title">
258 <?php
259
260 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
261 $separator_name = $menu_info[2];
262 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
263 $separator_name = str_replace( '--last', '-Last', $separator_name );
264 echo '~~ ' . wp_kses_post( $separator_name ) . ' ~~';
265 } else {
266 echo wp_kses_post( $menu_info[0] );
267 }
268
269 ?>
270 </span>
271 <label class="menu-item-checkbox-label">
272 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo wp_kses_post( $menu_item_id ); ?>">
273 <span>Hide</span>
274 </label>
275 </div>
276 </div>
277 </div>
278 <?php
279
280 $i = 1;
281
282 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
283 ?>
284 <div class="menu-item-settings wp-clearfix" style="display:none;">
285 <?php
286
287 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
288
289 $i++;
290
291 // echo $submenu_item[0];
292
293 }
294 ?>
295 </div>
296 <?php
297
298 }
299 ?>
300 </li>
301
302 <?php
303
304 }
305
306
307 }
308
309
310 ?>
311 </ul>
312 <?php
313
314 $field_id = $args['field_id'];
315 $field_name = $args['field_name'];
316 $field_description = $args['field_description'];
317 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
318
319 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
320 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
321
322 $field_id = 'custom_menu_hidden';
323 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
324 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
325
326 // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
327 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
328
329 }
330
331 }