PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 3.9.1
Admin and Site Enhancements (ASE) v3.9.1
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
719 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
299 if ( 'robots_txt_content' == $field_id ) {
300
301 if ( array_key_exists( 'manage_robots_txt', $options ) && ! $options['manage_robots_txt'] ) {
302 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
303 $field_option_value = $options['robots_txt_content'];
304 }
305 }
306
307 if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) {
308 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
309 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
310 $field_option_value = $robots_txt_content;
311 }
312
313 } else {
314 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
315 }
316
317 echo '<div class="asenha-subfield-textarea-wrapper">';
318
319 if ( ! empty( $field_intro ) ) {
320 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>';
321 }
322
323
324 echo '<textarea rows="30" class="asenha-subfield-textarea" id="' . esc_attr( $field_name ) . '" name="' . esc_attr( $field_name ) . '">' . esc_textarea( $field_option_value ) . '</textarea>';
325
326 if ( ! empty( $field_description ) ) {
327 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>';
328 }
329
330 echo '</div>';
331
332 }
333
334 /**
335 * Render sortable menu field
336 *
337 * @since 2.0.0
338 */
339 function render_sortable_menu( $args ) {
340
341 ?>
342 <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>
343 <ul id="custom-admin-menu" class="menu ui-sortable">
344 <?php
345
346 global $menu;
347 global $submenu;
348 $common_methods = new Common_Methods;
349 $options = get_option( ASENHA_SLUG_U, array() );
350
351 // Set menu items to be excluded from title renaming. These are from WordPress core.
352 $renaming_not_allowed = array( 'menu-dashboard', 'menu-pages', 'menu-posts', 'menu-media', 'menu-comments', 'menu-appearance', 'menu-plugins', 'menu-users', 'menu-tools', 'menu-settings' );
353
354 // Get custom menu item titles
355 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
356 $custom_menu_titles = $options['custom_menu_titles'];
357 $custom_menu_titles = explode( ',', $custom_menu_titles );
358 } else {
359 $custom_menu_titles = array();
360 }
361
362 // Get hidden menu items
363 if ( array_key_exists( 'custom_menu_hidden', $options ) ) {
364 $hidden_menu = $options['custom_menu_hidden'];
365 $hidden_menu = explode( ',', $hidden_menu );
366 } else {
367 $hidden_menu = array();
368 }
369
370 $i = 1;
371
372 // Check if there's an existing custom menu order data stored in options
373
374 if ( array_key_exists( 'custom_menu_order', $options ) ) {
375
376 $custom_menu = $options['custom_menu_order'];
377 $custom_menu = explode( ',', $custom_menu );
378
379 $menu_key_in_use = array();
380
381 // Render sortables with data in custom menu order
382
383 foreach ( $custom_menu as $custom_menu_item ) {
384
385 foreach ( $menu as $menu_key => $menu_info ) {
386
387 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
388 $menu_item_id = $menu_info[2];
389 } else {
390 $menu_item_id = $menu_info[5];
391 }
392
393 if ( $custom_menu_item == $menu_item_id ) {
394
395 ?>
396 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
397 <div class="menu-item-bar">
398 <div class="menu-item-handle ui-sortable-handle">
399 <div class="item-title">
400 <span class="menu-item-title">
401 <?php
402
403 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
404 $separator_name = $menu_info[2];
405 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
406 $separator_name = str_replace( '--last', '-Last', $separator_name );
407 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
408 } else {
409 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
410 // echo wp_kses_post( $menu_info[0] );
411 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) );
412 } else {
413
414 // Get defaul/custom menu item title
415 foreach ( $custom_menu_titles as $custom_menu_title ) {
416
417 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
418
419 $custom_menu_title = explode( '__', $custom_menu_title );
420
421 if ( $custom_menu_title[0] == $menu_item_id ) {
422 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] ); // e.g. Code Snippets
423 break; // stop foreach loop so $menu_item_title is not overwritten in the next iteration
424 } else {
425 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
426 }
427
428 }
429
430 ?>
431 <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 ); ?>">
432 <?php
433 }
434 }
435
436 ?>
437 </span>
438 <label class="menu-item-checkbox-label">
439 <?php
440 if ( in_array( $custom_menu_item, $hidden_menu ) ) {
441 ?>
442 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>" checked>
443 <span>Hide</span>
444 <?php
445 } else {
446 ?>
447 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
448 <span>Hide</span>
449 <?php
450 }
451 ?>
452 </label>
453 </div>
454 </div>
455 </div>
456 <?php
457
458 $i = 1;
459
460 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
461 ?>
462 <div class="menu-item-settings wp-clearfix" style="display:none;">
463 <?php
464
465 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
466
467 $i++;
468
469 // echo $submenu_item[0];
470
471 }
472 ?>
473 </div>
474 <?php
475
476 }
477 ?>
478 </li>
479
480 <?php
481
482 $menu_key_in_use[] = $menu_key;
483
484 }
485
486 }
487
488 }
489
490 // Render the rest of the current menu towards the end of the sortables
491
492 foreach ( $menu as $menu_key => $menu_info ) {
493
494 if ( ! in_array( $menu_key, $menu_key_in_use ) ) {
495
496 $menu_item_id = $menu_info[5];
497 $menu_item_title = $menu_info[0];
498
499 // Exclude Show All/Less toggles
500
501 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
502
503 ?>
504 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
505 <div class="menu-item-bar">
506 <div class="menu-item-handle ui-sortable-handle">
507 <div class="item-title">
508 <span class="menu-item-title">
509 <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 ); ?>">
510 </span>
511 <label class="menu-item-checkbox-label">
512 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
513 <span>Hide</span>
514 </label>
515 </div>
516 </div>
517 </div>
518 <?php
519
520 }
521
522 $i = 1;
523
524 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
525 ?>
526 <div class="menu-item-settings wp-clearfix" style="display:none;">
527 <?php
528
529 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
530
531 $i++;
532
533 // echo $submenu_item[0];
534
535 }
536 ?>
537 </div>
538 <?php
539
540 }
541 ?>
542 </li>
543
544 <?php
545
546 }
547
548 }
549
550 } else {
551
552 // Render sortables with existing items in the admin menu
553
554 foreach ( $menu as $menu_key => $menu_info ) {
555
556 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
557 $menu_item_id = $menu_info[2];
558 } else {
559 $menu_item_id = $menu_info[5];
560 }
561
562 ?>
563 <li id="<?php echo esc_attr( $menu_item_id ); ?>" class="menu-item menu-item-depth-0">
564 <div class="menu-item-bar">
565 <div class="menu-item-handle ui-sortable-handle">
566 <div class="item-title">
567 <span class="menu-item-title">
568 <?php
569
570 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
571 $separator_name = $menu_info[2];
572 $separator_name = str_replace( 'separator', 'Separator-', $separator_name );
573 $separator_name = str_replace( '--last', '-Last', $separator_name );
574 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
575 } else {
576 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
577 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_info[0] ) );
578 } else {
579 ?>
580 <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 ); ?>">
581 <?php
582 }
583 }
584
585 ?>
586 </span>
587 <label class="menu-item-checkbox-label">
588 <input type="checkbox" class="menu-item-checkbox" data-menu-item-id="<?php echo esc_attr( $menu_item_id ); ?>">
589 <span>Hide</span>
590 </label>
591 </div>
592 </div>
593 </div>
594 <?php
595
596 $i = 1;
597
598 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
599 ?>
600 <div class="menu-item-settings wp-clearfix" style="display:none;">
601 <?php
602
603 foreach ( $submenu[$menu_info[2]] as $submenu_item ) {
604
605 $i++;
606
607 // echo $submenu_item[0];
608
609 }
610 ?>
611 </div>
612 <?php
613
614 }
615 ?>
616 </li>
617
618 <?php
619
620 }
621
622
623 }
624
625
626 ?>
627 </ul>
628 <?php
629
630 $field_id = $args['field_id'];
631 $field_name = $args['field_name'];
632 $field_description = $args['field_description'];
633 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
634
635 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
636 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
637
638 $field_id = 'custom_menu_titles';
639 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
640 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
641
642 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
643 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
644
645 $field_id = 'custom_menu_hidden';
646 $field_name = ASENHA_SLUG_U . '['. $field_id .']';
647 $field_option_value = ( isset( $options[$field_id] ) ) ? $options[$field_id] : '';
648
649 // Hidden input field to store hidden menu itmes (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
650 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
651
652 }
653
654 /**
655 * Render textarea field as sub-field of a toggle/switcher checkbox
656 *
657 * @since 2.3.0
658 */
659 function render_datatable( $args ) {
660
661 global $wpdb;
662
663 $options = get_option( ASENHA_SLUG_U, array() );
664
665 $field_id = $args['field_id'];
666 $field_slug = $args['field_slug'];
667 $field_name = $args['field_name'];
668 $field_type = $args['field_type'];
669 $field_description = $args['field_description'];
670 $table_title = $args['table_title'];
671 $table_name = $args['table_name'];
672 $field_option_value = ( isset( $options[$args['field_id']] ) ) ? $options[$args['field_id']] : '';
673
674 ?>
675 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
676 <thead>
677 <tr class="datatable-tr">
678 <th class="datatable-th">IP Address<br />Last Username</th>
679 <th class="datatable-th">Attempts<br />Lockouts</th>
680 <th class="datatable-th">Last Attempt On</th>
681 </tr>
682 </thead>
683 <tbody>
684 <?php
685
686 $limit = 1000;
687
688 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) );
689
690 $entries = $wpdb->get_results( $sql, ARRAY_A );
691
692 foreach( $entries as $entry ) {
693
694 $unixtime = $entry['unixtime'];
695 if ( function_exists( 'wp_date' ) ) {
696 $date = wp_date( 'F j, Y', $unixtime );
697 $time = wp_date( 'H:i:s', $unixtime );
698 } else {
699 $date = date_i18n( 'F j, Y', $unixtime );
700 $time = date_i18n( 'H:i:s', $unixtime );
701 }
702 ?>
703 <tr class="datatable-tr">
704 <td class="datatable-td"><?php echo esc_html( $entry['ip_address'] ); ?><br /><?php echo esc_html( $entry['username'] ); ?></td>
705 <td class="datatable-td"><?php echo esc_html( $entry['fail_count'] ); ?><br /><?php echo esc_html( $entry['lockout_count'] ); ?></td>
706 <td class="datatable-td"><?php echo esc_html( $date ); ?><br /><?php echo esc_html( $time ); ?></td>
707 </tr>
708 <?php
709 }
710
711 ?>
712 </tbody>
713 </table>
714 <?php
715
716 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
717 }
718
719 }