PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 5.3.0
Admin and Site Enhancements (ASE) v5.3.0
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 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-common-methods.php 3 years ago class-content-management.php 3 years ago class-custom-code.php 3 years ago class-deactivation.php 3 years ago class-disable-components.php 3 years ago class-login-logout.php 3 years ago class-optimizations.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
920 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 $option_name = $args['option_name'];
20
21 if ( !empty($option_name) ) {
22 $options = get_option( $option_name, array() );
23 } else {
24 $options = get_option( ASENHA_SLUG_U, array() );
25 }
26
27 $field_name = $args['field_name'];
28 $field_description = $args['field_description'];
29 $field_option_value = ( array_key_exists( $args['field_id'], $options ) ? $options[$args['field_id']] : false );
30 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ;
31 echo '<label for="' . esc_attr( $field_name ) . '"></label>' ;
32 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
33 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
34 // For when the options / sub-fields occupy lengthy vertical space, we add show all / less toggler
35
36 if ( array_key_exists( 'field_options_moreless', $args ) && $args['field_options_moreless'] ) {
37 echo '<div class="asenha-field-with-options field-show-more">' ;
38 echo '<a id="' . $args['field_slug'] . '-show-moreless" class="show-more-less show-more" href="#">Expand &#9660;</a>' ;
39 echo '<div class="asenha-field-options-wrapper wrapper-show-more">' ;
40 } else {
41 echo '<div class="asenha-field-with-options">' ;
42 echo '<div class="asenha-field-options-wrapper">' ;
43 }
44
45 }
46 echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>' ;
47 // For field with additional options / sub-fields, we add wrapper for them
48 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
49 echo '<div class="asenha-subfields" style="display:none"></div>' ;
50 }
51 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
52
53 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
54 echo '</div>' ;
55 echo '</div>' ;
56 }
57
58 }
59
60 /**
61 * Render checkbox field as sub-field of a toggle/switcher checkbox
62 *
63 * @since 1.9.0
64 */
65 function render_checkbox_plain( $args )
66 {
67 $option_name = $args['option_name'];
68
69 if ( !empty($option_name) ) {
70 $options = get_option( $option_name, array() );
71 } else {
72 $options = get_option( ASENHA_SLUG_U, array() );
73 }
74
75 $field_name = $args['field_name'];
76 $field_label = $args['field_label'];
77 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : false );
78 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ;
79 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>' ;
80 }
81
82 /**
83 * Render checkbox field as sub-field of a toggle/switcher checkbox
84 *
85 * @since 1.3.0
86 */
87 function render_checkbox_subfield( $args )
88 {
89 $option_name = $args['option_name'];
90
91 if ( !empty($option_name) ) {
92 $options = get_option( $option_name, array() );
93 } else {
94 $options = get_option( ASENHA_SLUG_U, array() );
95 }
96
97 $field_name = $args['field_name'];
98 $field_label = $args['field_label'];
99 $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ? $options[$args['parent_field_id']][$args['field_id']] : false );
100 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>' ;
101 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>' ;
102 }
103
104 /**
105 * Render radio buttons field as sub-field of a toggle/switcher checkbox
106 *
107 * @since 1.3.0
108 */
109 function render_radio_buttons_subfield( $args )
110 {
111 $option_name = $args['option_name'];
112
113 if ( !empty($option_name) ) {
114 $options = get_option( $option_name, array() );
115 } else {
116 $options = get_option( ASENHA_SLUG_U, array() );
117 }
118
119 $field_id = $args['field_id'];
120 $field_name = $args['field_name'];
121 // $field_label = $args['field_label'];
122 $field_radios = $args['field_radios'];
123
124 if ( !empty($args['field_default']) ) {
125 $default_value = $args['field_default'];
126 } else {
127 $default_value = false;
128 }
129
130 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
131 foreach ( $field_radios as $radio_label => $radio_value ) {
132 echo '<input type="radio" id="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button" name="' . esc_attr( $field_name ) . '" value="' . $radio_value . '" ' . checked( $radio_value, $field_option_value, false ) . '>' ;
133 echo '<label for="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $radio_label ) . '</label>' ;
134 }
135 }
136
137 /**
138 * Render text field as sub-field of a toggle/switcher checkbox
139 *
140 * @since 1.4.0
141 */
142 function render_text_subfield( $args )
143 {
144 $option_name = $args['option_name'];
145
146 if ( !empty($option_name) ) {
147 $options = get_option( $option_name, array() );
148 } else {
149 $options = get_option( ASENHA_SLUG_U, array() );
150 }
151
152 $field_id = $args['field_id'];
153 $field_name = $args['field_name'];
154 $field_type = $args['field_type'];
155 $field_prefix = $args['field_prefix'];
156 $field_suffix = $args['field_suffix'];
157 $field_description = $args['field_description'];
158 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
159 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
160
161 if ( !empty($field_prefix) && !empty($field_suffix) ) {
162 $field_classname = ' with-prefix with-suffix';
163 } elseif ( !empty($field_prefix) && empty($field_suffix) ) {
164 $field_classname = ' with-prefix';
165 } elseif ( empty($field_prefix) && !empty($field_suffix) ) {
166 $field_classname = ' with-suffix';
167 } else {
168 $field_classname = '';
169 }
170
171
172 if ( $field_id == 'custom_login_slug' ) {
173 $field_placeholder = 'e.g. backend';
174 } elseif ( $field_id == 'redirect_after_login_to_slug' ) {
175 $field_placeholder = 'e.g. my-account';
176 } elseif ( $field_id == 'redirect_after_logout_to_slug' ) {
177 $field_placeholder = 'e.g. come-visit-again';
178 } elseif ( $field_id == 'login_fails_allowed' ) {
179 $field_placeholder = '3';
180 } elseif ( $field_id == 'login_lockout_maxcount' ) {
181 $field_placeholder = '3';
182 } else {
183 }
184
185 echo $field_prefix . '<input type="text" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $field_placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix ;
186 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>' ;
187 }
188
189 /**
190 * Render description field as sub-field of a toggle/switcher checkbox
191 *
192 * @since 4.6.0
193 */
194 function render_description_subfield( $args )
195 {
196 $field_description = $args['field_description'];
197 echo '<div class="asenha-subfield-description">' . $field_description . '</div>' ;
198 }
199
200 /**
201 * Render heading for sub-fields of a toggle/switcher checkbox
202 *
203 * @since 5.0.0
204 */
205 function render_subfields_heading( $args )
206 {
207 $subfields_heading = $args['subfields_heading'];
208 echo '<div class="asenha-subfields-heading">' . $subfields_heading . '</div>' ;
209 }
210
211 /**
212 * Render password field as sub-field of a toggle/switcher checkbox
213 *
214 * @since 4.1.0
215 */
216 function render_password_subfield( $args )
217 {
218 $option_name = $args['option_name'];
219
220 if ( !empty($option_name) ) {
221 $options = get_option( $option_name, array() );
222 } else {
223 $options = get_option( ASENHA_SLUG_U, array() );
224 }
225
226 $field_id = $args['field_id'];
227 $field_name = $args['field_name'];
228 $field_type = $args['field_type'];
229 $field_prefix = $args['field_prefix'];
230 $field_suffix = $args['field_suffix'];
231 $field_description = $args['field_description'];
232 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
233
234 if ( !empty($field_prefix) && !empty($field_suffix) ) {
235 $field_classname = ' with-prefix with-suffix';
236 } elseif ( !empty($field_prefix) && empty($field_suffix) ) {
237 $field_classname = ' with-prefix';
238 } elseif ( empty($field_prefix) && !empty($field_suffix) ) {
239 $field_classname = ' with-suffix';
240 } else {
241 $field_classname = '';
242 }
243
244 $placeholder = '';
245 echo $field_prefix . '<input type="password" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-password' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" size="24" autocomplete="off" value="' . $field_option_value . '">' . $field_suffix ;
246 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>' ;
247 }
248
249 /**
250 * Render number field as sub-field of a toggle/switcher checkbox
251 *
252 * @since 1.4.0
253 */
254 function render_number_subfield( $args )
255 {
256 $option_name = $args['option_name'];
257
258 if ( !empty($option_name) ) {
259 $options = get_option( $option_name, array() );
260 } else {
261 $options = get_option( ASENHA_SLUG_U, array() );
262 }
263
264 $field_id = $args['field_id'];
265 $field_name = $args['field_name'];
266 $field_type = $args['field_type'];
267 $field_prefix = $args['field_prefix'];
268 $field_suffix = $args['field_suffix'];
269 $field_intro = $args['field_intro'];
270 $field_description = $args['field_description'];
271 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
272
273 if ( !empty($field_prefix) && !empty($field_suffix) ) {
274 $field_classname = ' with-prefix with-suffix';
275 } elseif ( !empty($field_prefix) && empty($field_suffix) ) {
276 $field_classname = ' with-prefix';
277 } elseif ( empty($field_prefix) && !empty($field_suffix) ) {
278 $field_classname = ' with-suffix';
279 } else {
280 $field_classname = '';
281 }
282
283
284 if ( $field_id == 'revisions_max_number' || $field_id == 'custom_frontend_css_priority' || $field_id == 'head_code_priority' || $field_id == 'body_code_priority' || $field_id == 'footer_code_priority' ) {
285 $placeholder = '10';
286 } else {
287 $placeholder = '';
288 }
289
290 echo '<div class="asenha-subfield-number-wrapper">' ;
291 if ( !empty($field_intro) ) {
292 echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
293 }
294 echo '<div>' . $field_prefix . '<input type="number" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-number' . esc_attr( $field_classname ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix . '</div>' ;
295 if ( !empty($field_description) ) {
296 echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>' ;
297 }
298 echo '</div>' ;
299 }
300
301 /**
302 * Render select field as sub-field of a toggle/switcher checkbox
303 *
304 * @since 1.4.0
305 */
306 function render_select_subfield( $args )
307 {
308 $option_name = $args['option_name'];
309
310 if ( !empty($option_name) ) {
311 $options = get_option( $option_name, array() );
312 } else {
313 $options = get_option( ASENHA_SLUG_U, array() );
314 }
315
316 $field_id = $args['field_id'];
317 $field_name = $args['field_name'];
318 $field_type = $args['field_type'];
319 $field_prefix = $args['field_prefix'];
320 $field_suffix = $args['field_suffix'];
321 $field_select_options = $args['field_select_options'];
322 $field_select_default = $args['field_select_default'];
323 $field_intro = $args['field_intro'];
324 $field_description = $args['field_description'];
325
326 if ( !empty($args['field_select_default']) ) {
327 $default_value = $args['field_select_default'];
328 } else {
329 $default_value = false;
330 }
331
332 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
333
334 if ( !empty($field_prefix) && !empty($field_suffix) ) {
335 $field_classname = ' with-prefix with-suffix';
336 } elseif ( !empty($field_prefix) && empty($field_suffix) ) {
337 $field_classname = ' with-prefix';
338 } elseif ( empty($field_prefix) && !empty($field_suffix) ) {
339 $field_classname = ' with-suffix';
340 } else {
341 $field_classname = '';
342 }
343
344
345 if ( $args['display_none_on_load'] ) {
346 $inline_style = ' style="display:none;"';
347 } else {
348 $inline_style = '';
349 }
350
351 echo '<div class="asenha-subfield-select-wrapper">' ;
352 if ( !empty($field_intro) ) {
353 echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
354 }
355 echo '<div' . $inline_style . ' class="asenha-subfield-select-inner">' . $field_prefix ;
356 echo '<select name="' . $field_name . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">' ;
357 foreach ( $field_select_options as $label => $value ) {
358 echo '<option value="' . $value . '" ' . selected( $value, $field_option_value, false ) . '>' . $label . '</option>' ;
359 }
360 echo '</select>' ;
361 echo $field_suffix . '</div>' ;
362 if ( !empty($field_description) ) {
363 echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>' ;
364 }
365 echo '</div>' ;
366 }
367
368 /**
369 * Render textarea field as sub-field of a toggle/switcher checkbox
370 *
371 * @since 2.3.0
372 */
373 function render_textarea_subfield( $args )
374 {
375 $option_name = $args['option_name'];
376
377 if ( !empty($option_name) ) {
378 $options = get_option( $option_name, array() );
379 } else {
380 $options = get_option( ASENHA_SLUG_U, array() );
381 }
382
383 $field_id = $args['field_id'];
384 $field_slug = $args['field_slug'];
385 $field_name = $args['field_name'];
386 $field_type = $args['field_type'];
387 $field_rows = $args['field_rows'];
388 $field_intro = $args['field_intro'];
389 $field_description = $args['field_description'];
390 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
391 // Always load textarea content from robots.txt URL, whether it's a real, custom-made robots.txt file or a virtual one generated by WordPress
392
393 if ( 'robots_txt_content' == $field_id ) {
394
395 if ( array_key_exists( 'manage_robots_txt', $options ) ) {
396
397 if ( !$options['manage_robots_txt'] ) {
398 // Manage robots.txt feature is NOT enabled
399
400 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
401 $field_option_value = $options['robots_txt_content'];
402 } else {
403 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
404 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
405 $field_option_value = $robots_txt_content;
406 }
407
408 } else {
409 // Manage robots.txt feature is enabled
410
411 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
412 $field_option_value = $options['robots_txt_content'];
413 } else {
414 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
415 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
416 $field_option_value = $robots_txt_content;
417 }
418
419 }
420
421 } else {
422 // Manage robots.txt feature has never been enabled yet
423 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
424 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
425 $field_option_value = $robots_txt_content;
426 }
427
428 } else {
429 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
430 }
431
432 echo '<div class="asenha-subfield-textarea-wrapper">' ;
433 if ( !empty($field_intro) ) {
434 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
435 }
436 echo '<textarea rows="' . $field_rows . '" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '" placeholder="' . esc_attr( $field_placeholder ) . '">' . esc_textarea( $field_option_value ) . '</textarea>' ;
437 if ( !empty($field_description) ) {
438 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>' ;
439 }
440 echo '</div>' ;
441 }
442
443 /**
444 * Render test email subfield for Email Delivery module
445 *
446 * @since 5.3.0
447 */
448 function render_custom_html( $args )
449 {
450 // name attribute is emptied so this input will be excluded from saving into ASENHA option
451 echo $args['html'] ;
452 }
453
454 /**
455 * Render sortable menu field
456 *
457 * @since 2.0.0
458 */
459 function render_sortable_menu( $args )
460 {
461 ?>
462 <div class="subfield-description">Drag and drop menu items to the desired position. Optionally change 3rd party plugin/theme's menu item titles or hide some items until toggled by clicking "Show All" at the bottom of the admin menu.</div>
463 <?php
464 ?>
465 <ul id="custom-admin-menu" class="menu ui-sortable">
466 <?php
467 global $menu, $submenu ;
468 $common_methods = new Common_Methods();
469 $option_name = $args['option_name'];
470
471 if ( !empty($option_name) ) {
472 $options = get_option( $option_name, array() );
473 } else {
474 $options = get_option( ASENHA_SLUG_U, array() );
475 }
476
477 // Set menu items to be excluded from title renaming. These are from WordPress core.
478 $renaming_not_allowed = array(
479 'menu-dashboard',
480 'menu-pages',
481 'menu-posts',
482 'menu-media',
483 'menu-comments',
484 'menu-appearance',
485 'menu-plugins',
486 'menu-users',
487 'menu-tools',
488 'menu-settings'
489 );
490 // Get custom menu item titles
491
492 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
493 $custom_menu_titles = $options['custom_menu_titles'];
494 $custom_menu_titles = explode( ',', $custom_menu_titles );
495 } else {
496 $custom_menu_titles = array();
497 }
498
499 // Get menu items hidden by toggle
500 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
501 $i = 1;
502 // Check if there's an existing custom menu order data stored in options
503
504 if ( array_key_exists( 'custom_menu_order', $options ) ) {
505 $custom_menu = $options['custom_menu_order'];
506 $custom_menu = explode( ',', $custom_menu );
507 $menu_key_in_use = array();
508 // Render sortables with data in custom menu order
509 foreach ( $custom_menu as $custom_menu_item ) {
510 foreach ( $menu as $menu_key => $menu_info ) {
511
512 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
513 $menu_item_title = $menu_info[2];
514 $menu_item_id = $menu_info[2];
515 } else {
516 $menu_item_title = $menu_info[0];
517 $menu_item_id = $menu_info[5];
518 }
519
520 $menu_url_fragment = '';
521
522 if ( $custom_menu_item == $menu_item_id ) {
523 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
524 ?>
525 <li id="<?php
526 echo esc_attr( $menu_item_id ) ;
527 ?>" class="menu-item parent-menu-item menu-item-depth-0">
528 <div class="menu-item-bar">
529 <div class="menu-item-handle">
530 <span class="dashicons dashicons-menu"></span>
531 <div class="item-title">
532 <div class="title-wrapper">
533 <span class="menu-item-title">
534 <?php
535
536 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
537 $separator_name_ori = $menu_info[2];
538 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
539 $separator_name = str_replace( '--last', '-Last', $separator_name );
540 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
541 } else {
542
543 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
544 $menu_item_title = $menu_info[0];
545 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
546 } else {
547 // Get defaul/custom menu item title
548 foreach ( $custom_menu_titles as $custom_menu_title ) {
549 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
550 $custom_menu_title = explode( '__', $custom_menu_title );
551
552 if ( $custom_menu_title[0] == $menu_item_id ) {
553 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] );
554 // e.g. Code Snippets
555 break;
556 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
557 } else {
558 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
559 }
560
561 }
562 ?>
563 <input type="text" value="<?php
564 echo wp_kses_post( $menu_item_title ) ;
565 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
566 echo esc_attr( $menu_item_id ) ;
567 ?>">
568 <?php
569 }
570
571 }
572
573 ?>
574 </span><!-- end of .menu-item-title -->
575 <?php
576 ?>
577 </div><!-- end of .title-wrapper -->
578 <div class="options-for-hiding">
579 <?php
580 $hide_text = 'Hide until toggled';
581 $checkbox_class = 'parent-menu-hide-checkbox';
582 ?>
583 <label class="menu-item-checkbox-label">
584 <?php
585
586 if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) {
587 ?>
588 <input type="checkbox" id="hide-status-for-<?php
589 echo esc_attr( $menu_item_id_transformed ) ;
590 ?>" class="<?php
591 echo esc_attr( $checkbox_class ) ;
592 ?>" data-menu-item-title="<?php
593 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
594 ?>" data-menu-item-id="<?php
595 echo esc_attr( $menu_item_id_transformed ) ;
596 ?>" data-menu-item-id-ori="<?php
597 echo esc_attr( $menu_item_id ) ;
598 ?>" data-menu-url-fragment="<?php
599 echo esc_attr( $menu_url_fragment ) ;
600 ?>" checked>
601 <span><?php
602 echo esc_html( $hide_text ) ;
603 ?></span>
604 <?php
605 } else {
606 ?>
607 <input type="checkbox" id="hide-status-for-<?php
608 echo esc_attr( $menu_item_id_transformed ) ;
609 ?>" class="<?php
610 echo esc_attr( $checkbox_class ) ;
611 ?>" data-menu-item-title="<?php
612 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
613 ?>" data-menu-item-id="<?php
614 echo esc_attr( $menu_item_id_transformed ) ;
615 ?>" data-menu-item-id-ori="<?php
616 echo esc_attr( $menu_item_id ) ;
617 ?>" data-menu-url-fragment="<?php
618 echo esc_attr( $menu_url_fragment ) ;
619 ?>">
620 <span><?php
621 echo esc_html( $hide_text ) ;
622 ?></span>
623 <?php
624 }
625
626 ?>
627 </label>
628 <?php
629 ?>
630 </div><!-- end of .options-for-hiding -->
631 </div><!-- end of .item-title -->
632 </div><!-- end of .menu-item-handle -->
633 </div><!-- end of .menu-item-bar -->
634 <?php
635 ?>
636 <?php
637 $i = 1;
638 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
639 }
640 ?>
641 </li>
642 <?php
643 $menu_key_in_use[] = $menu_key;
644 }
645
646 }
647 }
648 // Render the rest of the current menu towards the end of the sortables
649 foreach ( $menu as $menu_key => $menu_info ) {
650
651 if ( !in_array( $menu_key, $menu_key_in_use ) ) {
652
653 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
654 $menu_item_id = $menu_info[2];
655 } else {
656 $menu_item_id = $menu_info[5];
657 }
658
659 $menu_item_title = $menu_info[0];
660 $menu_url_fragment = '';
661 // Exclude Show All/Less toggles
662
663 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
664 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
665 ?>
666 <li id="<?php
667 echo esc_attr( $menu_item_id ) ;
668 ?>" class="menu-item parent-menu-item menu-item-depth-0">
669 <div class="menu-item-bar">
670 <div class="menu-item-handle">
671 <span class="dashicons dashicons-menu"></span>
672 <div class="item-title">
673 <div class="title-wrapper">
674 <span class="menu-item-title">
675 <?php
676
677 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
678 $separator_name_ori = $menu_info[2];
679 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
680 $separator_name = str_replace( '--last', '-Last', $separator_name );
681 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
682 } else {
683 ?>
684 <input type="text" value="<?php
685 echo wp_kses_post( $menu_item_title ) ;
686 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
687 echo esc_attr( $menu_item_id ) ;
688 ?>">
689 <?php
690 }
691
692 ?>
693 </span>
694 <?php
695 ?>
696 </div>
697 <div class="options-for-hiding">
698 <?php
699 $hide_text = 'Hide until toggled';
700 $checkbox_class = 'parent-menu-hide-checkbox';
701 ?>
702 <label class="menu-item-checkbox-label">
703 <input type="checkbox" id="hide-status-for-<?php
704 echo esc_attr( $menu_item_id_transformed ) ;
705 ?>" class="<?php
706 echo esc_attr( $checkbox_class ) ;
707 ?>" data-menu-item-id="<?php
708 echo esc_attr( $menu_item_id ) ;
709 ?>">
710 <span><?php
711 echo esc_html( $hide_text ) ;
712 ?></span>
713 </label>
714 <?php
715 ?>
716 </div><!-- end of .options-for-hiding -->
717 </div><!-- end of .item-title -->
718 </div><!-- end of .menu-item-handle -->
719 </div><!-- end of .menu-item-bar -->
720 <div class="menu-item-settings parent-menu-item-settings wp-clearfix" style="display:none;">
721 </div><!-- end of .menu-item-settings -->
722 <?php
723 $i = 1;
724 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
725 ?>
726 <?php
727 }
728 ?>
729 </li><!-- end of .menu-item -->
730 <?php
731 }
732
733 }
734
735 }
736 } else {
737 // No custom menu order has been saved yet
738 // Render sortables with existing items in the admin menu
739 foreach ( $menu as $menu_key => $menu_info ) {
740
741 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
742 $menu_item_id = $menu_info[2];
743 } else {
744 $menu_item_id = $menu_info[5];
745 }
746
747 $menu_url_fragment = '';
748 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
749 ?>
750 <li id="<?php
751 echo esc_attr( $menu_item_id ) ;
752 ?>" class="menu-item parent-menu-item menu-item-depth-0">
753 <div class="menu-item-bar">
754 <div class="menu-item-handle">
755 <span class="dashicons dashicons-menu"></span>
756 <div class="item-title">
757 <div class="title-wrapper">
758 <span class="menu-item-title">
759 <?php
760
761 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
762 $separator_name_ori = $menu_info[2];
763 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
764 $separator_name = str_replace( '--last', '-Last', $separator_name );
765 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
766 } else {
767
768 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
769 $menu_item_title = $menu_info[0];
770 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
771 } else {
772 ?>
773 <input type="text" value="<?php
774 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ) ;
775 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
776 echo esc_attr( $menu_item_id ) ;
777 ?>">
778 <?php
779 }
780
781 }
782
783 ?>
784 </span>
785 <?php
786 ?>
787 </div><!-- end of .title-wrapper -->
788 <div class="options-for-hiding">
789 <?php
790 $hide_text = 'Hide until toggled';
791 $checkbox_class = 'parent-menu-hide-checkbox';
792 ?>
793 <label class="menu-item-checkbox-label">
794 <input type="checkbox" id="hide-status-for-<?php
795 echo esc_attr( $menu_item_id_transformed ) ;
796 ?>" class="<?php
797 echo esc_attr( $checkbox_class ) ;
798 ?>" data-menu-item-id="<?php
799 echo esc_attr( $menu_item_id ) ;
800 ?>">
801 <span><?php
802 echo esc_html( $hide_text ) ;
803 ?></span>
804 </label>
805 <?php
806 ?>
807 </div><!-- end of .options-for-hiding -->
808 </div><!-- end of .item-title -->
809 </div><!-- end of .menu-item-handle -->
810 </div><!-- end of .menu-item-bar -->
811 <?php
812 $i = 1;
813 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
814 ?>
815 <?php
816 }
817 ?>
818 </li>
819 <?php
820 }
821 }
822
823 ?>
824 </ul>
825 <?php
826 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
827 $field_id = $args['field_id'];
828 $field_name = $args['field_name'];
829 $field_description = $args['field_description'];
830 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
831 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
832 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
833 $field_id = 'custom_menu_titles';
834 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
835 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
836 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
837 // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
838 $field_id = 'custom_menu_hidden';
839 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
840 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
841 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
842 }
843
844 /**
845 * Render textarea field as sub-field of a toggle/switcher checkbox
846 *
847 * @since 2.3.0
848 */
849 function render_datatable( $args )
850 {
851 global $wpdb ;
852 $option_name = $args['option_name'];
853
854 if ( !empty($option_name) ) {
855 $options = get_option( $option_name, array() );
856 } else {
857 $options = get_option( ASENHA_SLUG_U, array() );
858 }
859
860 $field_id = $args['field_id'];
861 $field_slug = $args['field_slug'];
862 $field_name = $args['field_name'];
863 $field_type = $args['field_type'];
864 $field_description = $args['field_description'];
865 $table_title = $args['table_title'];
866 $table_name = $args['table_name'];
867 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
868 ?>
869 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
870 <thead>
871 <tr class="datatable-tr">
872 <th class="datatable-th">IP Address<br />Last Username</th>
873 <th class="datatable-th">Attempts<br />Lockouts</th>
874 <th class="datatable-th">Last Attempt On</th>
875 </tr>
876 </thead>
877 <tbody>
878 <?php
879 $limit = 1000;
880 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) );
881 $entries = $wpdb->get_results( $sql, ARRAY_A );
882 foreach ( $entries as $entry ) {
883 $unixtime = $entry['unixtime'];
884
885 if ( function_exists( 'wp_date' ) ) {
886 $date = wp_date( 'F j, Y', $unixtime );
887 $time = wp_date( 'H:i:s', $unixtime );
888 } else {
889 $date = date_i18n( 'F j, Y', $unixtime );
890 $time = date_i18n( 'H:i:s', $unixtime );
891 }
892
893 ?>
894 <tr class="datatable-tr">
895 <td class="datatable-td"><?php
896 echo esc_html( $entry['ip_address'] ) ;
897 ?><br /><?php
898 echo esc_html( $entry['username'] ) ;
899 ?></td>
900 <td class="datatable-td"><?php
901 echo esc_html( $entry['fail_count'] ) ;
902 ?><br /><?php
903 echo esc_html( $entry['lockout_count'] ) ;
904 ?></td>
905 <td class="datatable-td"><?php
906 echo esc_html( $date ) ;
907 ?><br /><?php
908 echo esc_html( $time ) ;
909 ?></td>
910 </tr>
911 <?php
912 }
913 ?>
914 </tbody>
915 </table>
916 <?php
917 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
918 }
919
920 }