PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 3.9.2
Admin and Site Enhancements (ASE) v3.9.2
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
729 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, array() );
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, array() );
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, array() );
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 radio buttons field as sub-field of a toggle/switcher checkbox
96 *
97 * @since 1.3.0
98 */
99 function render_radio_buttons_subfield( $args ) {
100
101 $options = get_option( ASENHA_SLUG_U, array() );
102
103 $field_id = $args['field_id'];
104 $field_name = $args['field_name'];
105 // $field_label = $args['field_label'];
106 $field_radios = $args['field_radios'];
107 if ( ! empty( $args['field_default'] ) ) {
108 $default_value = $args['field_default'];
109 } else {
110 $default_value = false;
111 }
112 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : $default_value;
113
114 foreach ( $field_radios as $radio_label => $radio_value ) {
115 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 ) . '>';
116 echo '<label for="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $radio_label ) . '</label>';
117 }
118
119 }
120
121 /**
122 * Render text field as sub-field of a toggle/switcher checkbox
123 *
124 * @since 1.4.0
125 */
126 function render_text_subfield( $args ) {
127
128 $options = get_option( ASENHA_SLUG_U, array() );
129
130 $field_id = $args['field_id'];
131 $field_name = $args['field_name'];
132 $field_type = $args['field_type'];
133 $field_prefix = $args['field_prefix'];
134 $field_suffix = $args['field_suffix'];
135 $field_description = $args['field_description'];
136 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
137
138 if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) {
139 $field_classname = ' with-prefix with-suffix';
140 } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) {
141 $field_classname = ' with-prefix';
142 } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) {
143 $field_classname = ' with-suffix';
144 } else {
145 $field_classname = '';
146 }
147
148 if ( $field_id == 'custom_login_slug' ) {
149 $placeholder = 'e.g. backend';
150 } elseif ( $field_id == 'redirect_after_login_to_slug' ) {
151 $placeholder = 'e.g. my-account';
152 } elseif ( $field_id == 'redirect_after_logout_to_slug' ) {
153 $placeholder = 'e.g. come-visit-again';
154 } elseif ( $field_id == 'login_fails_allowed' ) {
155 $placeholder = '3';
156 } elseif ( $field_id == 'login_lockout_maxcount' ) {
157 $placeholder = '3';
158 } else {
159 $placeholder = '';
160 }
161
162 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( $placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . $field_suffix;
163 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
164
165 }
166
167 /**
168 * Render number field as sub-field of a toggle/switcher checkbox
169 *
170 * @since 1.4.0
171 */
172 function render_number_subfield( $args ) {
173
174 $options = get_option( ASENHA_SLUG_U, array() );
175
176 $field_id = $args['field_id'];
177 $field_name = $args['field_name'];
178 $field_type = $args['field_type'];
179 $field_prefix = $args['field_prefix'];
180 $field_suffix = $args['field_suffix'];
181 $field_intro = $args['field_intro'];
182 $field_description = $args['field_description'];
183 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
184
185 if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) {
186 $field_classname = ' with-prefix with-suffix';
187 } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) {
188 $field_classname = ' with-prefix';
189 } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) {
190 $field_classname = ' with-suffix';
191 } else {
192 $field_classname = '';
193 }
194
195 if ( ( $field_id == 'revisions_max_number' ) || ( $field_id == 'head_code_priority' ) || ( $field_id == 'body_code_priority' ) || ( $field_id == 'footer_code_priority' ) ) {
196 $placeholder = '10';
197 } else {
198 $placeholder = '';
199 }
200
201 echo '<div class="asenha-subfield-number-wrapper">';
202
203 if ( ! empty( $field_intro ) ) {
204 echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>';
205 }
206
207 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>';
208
209 if ( ! empty( $field_description ) ) {
210 echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>';
211 }
212
213 echo '</div>';
214
215 }
216
217 /**
218 * Render select field as sub-field of a toggle/switcher checkbox
219 *
220 * @since 1.4.0
221 */
222 function render_select_subfield( $args ) {
223
224 $options = get_option( ASENHA_SLUG_U, array() );
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_select_options = $args['field_select_options'];
232 $field_select_default = $args['field_select_default'];
233 $field_intro = $args['field_intro'];
234 $field_description = $args['field_description'];
235 if ( ! empty( $args['field_select_default'] ) ) {
236 $default_value = $args['field_select_default'];
237 } else {
238 $default_value = false;
239 }
240 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : $default_value;
241
242 if ( ! empty( $field_prefix ) && ! empty( $field_suffix ) ) {
243 $field_classname = ' with-prefix with-suffix';
244 } elseif ( ! empty( $field_prefix ) && empty( $field_suffix ) ) {
245 $field_classname = ' with-prefix';
246 } elseif ( empty( $field_prefix ) && ! empty( $field_suffix ) ) {
247 $field_classname = ' with-suffix';
248 } else {
249 $field_classname = '';
250 }
251
252 if ( $args['display_none_on_load'] ) {
253 $inline_style = ' style="display:none;"';
254 } else {
255 $inline_style = '';
256 }
257
258 echo '<div class="asenha-subfield-select-wrapper">';
259
260 if ( ! empty( $field_intro ) ) {
261 echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>';
262 }
263
264 echo '<div' . $inline_style . ' class="asenha-subfield-select-inner">' . $field_prefix;
265 echo '<select name="' . $field_name . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">';
266
267 foreach ( $field_select_options as $label => $value ) {
268 echo '<option value="' . $value . '" ' . selected( $value, $field_option_value, false ) . '>' . $label . '</option>';
269 }
270
271 echo '</select>';
272 echo $field_suffix . '</div>';
273
274 if ( ! empty( $field_description ) ) {
275 echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>';
276 }
277
278 echo '</div>';
279
280 }
281
282 /**
283 * Render textarea field as sub-field of a toggle/switcher checkbox
284 *
285 * @since 2.3.0
286 */
287 function render_textarea_subfield( $args ) {
288
289 $options = get_option( ASENHA_SLUG_U, array() );
290
291 $field_id = $args['field_id'];
292 $field_slug = $args['field_slug'];
293 $field_name = $args['field_name'];
294 $field_type = $args['field_type'];
295 $field_intro = $args['field_intro'];
296 $field_description = $args['field_description'];
297
298 // 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
299 if ( 'robots_txt_content' == $field_id ) {
300 if ( array_key_exists( 'manage_robots_txt', $options ) ) {
301 if ( ! $options['manage_robots_txt'] ) { // Manage robots.txt feature is NOT enabled
302 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
303 $field_option_value = $options['robots_txt_content'];
304 } else {
305 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
306 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
307 $field_option_value = $robots_txt_content;
308 }
309 } else { // Manage robots.txt feature is enabled
310 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
311 $field_option_value = $options['robots_txt_content'];
312 } else {
313 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
314 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
315 $field_option_value = $robots_txt_content;
316 }
317 }
318 } else { // Manage robots.txt feature has never been enabled yet
319 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
320 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
321 $field_option_value = $robots_txt_content;
322 }
323 } else {
324 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
325 }
326
327 echo '<div class="asenha-subfield-textarea-wrapper">';
328
329 if ( ! empty( $field_intro ) ) {
330 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>';
331 }
332
333
334 echo '<textarea rows="30" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '">' . esc_textarea( $field_option_value ) . '</textarea>';
335
336 if ( ! empty( $field_description ) ) {
337 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>';
338 }
339
340 echo '</div>';
341
342 }
343
344 /**
345 * Render sortable menu field
346 *
347 * @since 2.0.0
348 */
349 function render_sortable_menu( $args ) {
350
351 ?>
352 <div class="subfield-description">Drag and drop menu items to the desired position. Optionally change item titles or hide some items until "Show All" at the bottom of the admin menu is clicked.</div>
353 <ul id="custom-admin-menu" class="menu ui-sortable">
354 <?php
355
356 global $menu;
357 global $submenu;
358 $common_methods = new Common_Methods;
359 $options = get_option( ASENHA_SLUG_U, array() );
360
361 // Set menu items to be excluded from title renaming. These are from WordPress core.
362 $renaming_not_allowed = array( 'menu-dashboard', 'menu-pages', 'menu-posts', 'menu-media', 'menu-comments', 'menu-appearance', 'menu-plugins', 'menu-users', 'menu-tools', 'menu-settings' );
363
364 // Get custom menu item titles
365 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
366 $custom_menu_titles = $options['custom_menu_titles'];
367 $custom_menu_titles = explode( ',', $custom_menu_titles );
368 } else {
369 $custom_menu_titles = array();
370 }
371
372 // Get hidden menu items
373 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
374 $hidden_menu = $options['custom_menu_hidden'];
375 $hidden_menu = explode( ',', $hidden_menu );
376 } else {
377 $hidden_menu = array();
378 }
379
380 $i = 1;
381
382 // Check if there's an existing custom menu order data stored in options
383
384 if ( array_key_exists( 'custom_menu_order', $options ) ) {
385
386 $custom_menu = $options['custom_menu_order'];
387 $custom_menu = explode( ',', $custom_menu );
388
389 $menu_key_in_use = array();
390
391 // Render sortables with data in custom menu order
392
393 foreach ( $custom_menu as $custom_menu_item ) {
394
395 foreach ( $menu as $menu_key => $menu_info ) {
396
397 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
398 $menu_item_id = $menu_info[2];
399 } else {
400 $menu_item_id = $menu_info[5];
401 }
402
403 if ( $custom_menu_item == $menu_item_id ) {
404
405 ?>
406 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
407 <div class="menu-item-bar">
408 <div class="menu-item-handle ui-sortable-handle">
409 <div class="item-title">
410 <span class="menu-item-title">
411 <?php
412
413 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
414 $separator_name = $menu_info[2];
415 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
416 $separator_name = str_replace( '--last', '-Last', $separator_name );
417 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
418 } else {
419 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
420 // echo wp_kses_post( $menu_info[0] );
421 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) );
422 } else {
423
424 // Get defaul/custom menu item title
425 foreach ( $custom_menu_titles as $custom_menu_title ) {
426
427 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
428
429 $custom_menu_title = explode( '__', $custom_menu_title );
430
431 if ( $custom_menu_title[0] == $menu_item_id ) {
432 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] ); // e.g. Code Snippets
433 break; // stop foreach loop so $menu_item_title is not overwritten in the next iteration
434 } else {
435 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
436 }
437
438 }
439
440 ?>
441 <input type="text" value="<?php echo wp_kses_post( $menu_item_title ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
442 <?php
443 }
444 }
445
446 ?>
447 </span>
448 <label class="menu-item-checkbox-label">
449 <?php
450 if ( in_array( $custom_menu_item, $hidden_menu ) ) {
451 ?>
452 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>" checked>
453 <span>Hide</span>
454 <?php
455 } else {
456 ?>
457 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
458 <span>Hide</span>
459 <?php
460 }
461 ?>
462 </label>
463 </div>
464 </div>
465 </div>
466 <?php
467
468 $i = 1;
469
470 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
471 ?>
472 <div class="menu-item-settings wp-clearfix" style="display:none;">
473 <?php
474
475 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
476
477 $i++;
478
479 // echo $submenu_item[0];
480
481 }
482 ?>
483 </div>
484 <?php
485
486 }
487 ?>
488 </li>
489
490 <?php
491
492 $menu_key_in_use[] = $menu_key;
493
494 }
495
496 }
497
498 }
499
500 // Render the rest of the current menu towards the end of the sortables
501
502 foreach ( $menu as $menu_key => $menu_info ) {
503
504 if ( ! in_array( $menu_key, $menu_key_in_use ) ) {
505
506 $menu_item_id = $menu_info[5];
507 $menu_item_title = $menu_info[0];
508
509 // Exclude Show All/Less toggles
510
511 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
512
513 ?>
514 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
515 <div class="menu-item-bar">
516 <div class="menu-item-handle ui-sortable-handle">
517 <div class="item-title">
518 <span class="menu-item-title">
519 <input type="text" value="<?php echo wp_kses_post( $menu_item_title ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
520 </span>
521 <label class="menu-item-checkbox-label">
522 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
523 <span>Hide</span>
524 </label>
525 </div>
526 </div>
527 </div>
528 <?php
529
530 }
531
532 $i = 1;
533
534 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
535 ?>
536 <div class="menu-item-settings wp-clearfix" style="display:none;">
537 <?php
538
539 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
540
541 $i++;
542
543 // echo $submenu_item[0];
544
545 }
546 ?>
547 </div>
548 <?php
549
550 }
551 ?>
552 </li>
553
554 <?php
555
556 }
557
558 }
559
560 } else {
561
562 // Render sortables with existing items in the admin menu
563
564 foreach ( $menu as $menu_key => $menu_info ) {
565
566 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
567 $menu_item_id = $menu_info[2];
568 } else {
569 $menu_item_id = $menu_info[5];
570 }
571
572 ?>
573 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
574 <div class="menu-item-bar">
575 <div class="menu-item-handle ui-sortable-handle">
576 <div class="item-title">
577 <span class="menu-item-title">
578 <?php
579
580 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
581 $separator_name = $menu_info[2];
582 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
583 $separator_name = str_replace( '--last', '-Last', $separator_name );
584 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
585 } else {
586 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
587 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) );
588 } else {
589 ?>
590 <input type="text" value="<?php echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) ); ?>" class="menu-item-custom-title" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
591 <?php
592 }
593 }
594
595 ?>
596 </span>
597 <label class="menu-item-checkbox-label">
598 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
599 <span>Hide</span>
600 </label>
601 </div>
602 </div>
603 </div>
604 <?php
605
606 $i = 1;
607
608 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
609 ?>
610 <div class="menu-item-settings wp-clearfix" style="display:none;">
611 <?php
612
613 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
614
615 $i++;
616
617 // echo $submenu_item[0];
618
619 }
620 ?>
621 </div>
622 <?php
623
624 }
625 ?>
626 </li>
627
628 <?php
629
630 }
631
632
633 }
634
635
636 ?>
637 </ul>
638 <?php
639
640 $field_id = $args['field_id'];
641 $field_name = $args['field_name'];
642 $field_description = $args['field_description'];
643 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
644
645 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
646 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
647
648 $field_id = 'custom_menu_titles';
649 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
650 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
651
652 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
653 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
654
655 $field_id = 'custom_menu_hidden';
656 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
657 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
658
659 // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
660 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
661
662 }
663
664 /**
665 * Render textarea field as sub-field of a toggle/switcher checkbox
666 *
667 * @since 2.3.0
668 */
669 function render_datatable( $args ) {
670
671 global $wpdb;
672
673 $options = get_option( ASENHA_SLUG_U, array() );
674
675 $field_id = $args['field_id'];
676 $field_slug = $args['field_slug'];
677 $field_name = $args['field_name'];
678 $field_type = $args['field_type'];
679 $field_description = $args['field_description'];
680 $table_title = $args['table_title'];
681 $table_name = $args['table_name'];
682 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
683
684 ?>
685 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
686 <thead>
687 <tr class="datatable-tr">
688 <th class="datatable-th">IP Address<br />Last Username</th>
689 <th class="datatable-th">Attempts<br />Lockouts</th>
690 <th class="datatable-th">Last Attempt On</th>
691 </tr>
692 </thead>
693 <tbody>
694 <?php
695
696 $limit = 1000;
697
698 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) );
699
700 $entries = $wpdb->get_results( $sql, ARRAY_A );
701
702 foreach( $entries as $entry ) {
703
704 $unixtime = $entry['unixtime'];
705 if ( function_exists( 'wp_date' ) ) {
706 $date = wp_date( 'F j, Y', $unixtime );
707 $time = wp_date( 'H:i:s', $unixtime );
708 } else {
709 $date = date_i18n( 'F j, Y', $unixtime );
710 $time = date_i18n( 'H:i:s', $unixtime );
711 }
712 ?>
713 <tr class="datatable-tr">
714 <td class="datatable-td"><?php echo esc_html( $entry['ip_address'] ); ?><br /><?php echo esc_html( $entry['username'] ); ?></td>
715 <td class="datatable-td"><?php echo esc_html( $entry['fail_count'] ); ?><br /><?php echo esc_html( $entry['lockout_count'] ); ?></td>
716 <td class="datatable-td"><?php echo esc_html( $date ); ?><br /><?php echo esc_html( $time ); ?></td>
717 </tr>
718 <?php
719 }
720
721 ?>
722 </tbody>
723 </table>
724 <?php
725
726 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
727 }
728
729 }