PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.1.0
Admin and Site Enhancements (ASE) v6.1.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 2 years ago class-admin-interface.php 2 years ago class-common-methods.php 2 years ago class-content-management.php 2 years ago class-custom-code.php 2 years ago class-deactivation.php 2 years ago class-disable-components.php 2 years ago class-login-logout.php 2 years ago class-optimizations.php 2 years ago class-security.php 2 years ago class-settings-fields-render.php 2 years ago class-settings-sanitization.php 2 years ago class-settings-sections-fields.php 2 years ago class-utilities.php 2 years ago
class-settings-fields-render.php
995 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 = ( isset( $args['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 } elseif ( $field_id == 'convert_to_webp_quality' ) {
287 $placeholder = '82';
288 } else {
289 $placeholder = '';
290 }
291
292 echo '<div class="asenha-subfield-number-wrapper">' ;
293 if ( !empty($field_intro) ) {
294 echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
295 }
296 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>' ;
297 if ( !empty($field_description) ) {
298 echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>' ;
299 }
300 echo '</div>' ;
301 }
302
303 /**
304 * Render select field as sub-field of a toggle/switcher checkbox
305 *
306 * @since 1.4.0
307 */
308 function render_select_subfield( $args )
309 {
310 $option_name = $args['option_name'];
311
312 if ( !empty($option_name) ) {
313 $options = get_option( $option_name, array() );
314 } else {
315 $options = get_option( ASENHA_SLUG_U, array() );
316 }
317
318 $field_id = $args['field_id'];
319 $field_name = $args['field_name'];
320 $field_type = $args['field_type'];
321 $field_prefix = $args['field_prefix'];
322 $field_suffix = $args['field_suffix'];
323 $field_select_options = $args['field_select_options'];
324 $field_select_default = $args['field_select_default'];
325 $field_intro = $args['field_intro'];
326 $field_description = $args['field_description'];
327
328 if ( !empty($args['field_select_default']) ) {
329 $default_value = $args['field_select_default'];
330 } else {
331 $default_value = false;
332 }
333
334 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
335
336 if ( !empty($field_prefix) && !empty($field_suffix) ) {
337 $field_classname = ' with-prefix with-suffix';
338 } elseif ( !empty($field_prefix) && empty($field_suffix) ) {
339 $field_classname = ' with-prefix';
340 } elseif ( empty($field_prefix) && !empty($field_suffix) ) {
341 $field_classname = ' with-suffix';
342 } else {
343 $field_classname = '';
344 }
345
346
347 if ( $args['display_none_on_load'] ) {
348 $inline_style = ' style="display:none;"';
349 } else {
350 $inline_style = '';
351 }
352
353 echo '<div class="asenha-subfield-select-wrapper">' ;
354 if ( !empty($field_intro) ) {
355 echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
356 }
357 echo '<div' . $inline_style . ' class="asenha-subfield-select-inner">' . $field_prefix ;
358 echo '<select name="' . $field_name . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">' ;
359 foreach ( $field_select_options as $label => $value ) {
360 echo '<option value="' . $value . '" ' . selected( $value, $field_option_value, false ) . '>' . $label . '</option>' ;
361 }
362 echo '</select>' ;
363 echo $field_suffix . '</div>' ;
364 if ( !empty($field_description) ) {
365 echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>' ;
366 }
367 echo '</div>' ;
368 }
369
370 /**
371 * Render textarea field as sub-field of a toggle/switcher checkbox
372 *
373 * @since 2.3.0
374 */
375 function render_textarea_subfield( $args )
376 {
377 $option_name = $args['option_name'];
378
379 if ( !empty($option_name) ) {
380 $options = get_option( $option_name, array() );
381 } else {
382 $options = get_option( ASENHA_SLUG_U, array() );
383 }
384
385 $field_id = $args['field_id'];
386 $field_slug = $args['field_slug'];
387 $field_name = $args['field_name'];
388 $field_type = $args['field_type'];
389 $field_rows = $args['field_rows'];
390 $field_intro = $args['field_intro'];
391 $field_description = $args['field_description'];
392 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
393 // 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
394
395 if ( 'robots_txt_content' == $field_id ) {
396
397 if ( array_key_exists( 'manage_robots_txt', $options ) ) {
398
399 if ( !$options['manage_robots_txt'] ) {
400 // Manage robots.txt feature is NOT enabled
401
402 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
403 $field_option_value = $options['robots_txt_content'];
404 } else {
405 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
406 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
407 $field_option_value = $robots_txt_content;
408 }
409
410 } else {
411 // Manage robots.txt feature is enabled
412
413 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
414 $field_option_value = $options['robots_txt_content'];
415 } else {
416 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
417 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
418 $field_option_value = $robots_txt_content;
419 }
420
421 }
422
423 } else {
424 // Manage robots.txt feature has never been enabled yet
425 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
426 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
427 $field_option_value = $robots_txt_content;
428 }
429
430 } else {
431 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
432 }
433
434 echo '<div class="asenha-subfield-textarea-wrapper">' ;
435 if ( !empty($field_intro) ) {
436 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>' ;
437 }
438 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>' ;
439 if ( !empty($field_description) ) {
440 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>' ;
441 }
442 echo '</div>' ;
443 }
444
445 /**
446 * Render test email subfield for Email Delivery module
447 *
448 * @since 5.3.0
449 */
450 function render_custom_html( $args )
451 {
452 // name attribute is emptied so this input will be excluded from saving into ASENHA option
453 echo $args['html'] ;
454 }
455
456 /**
457 * Render sortable menu field
458 *
459 * @since 2.0.0
460 */
461 function render_sortable_menu( $args )
462 {
463 ?>
464 <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>
465 <?php
466 ?>
467 <ul id="custom-admin-menu" class="menu ui-sortable">
468 <?php
469 global $menu, $submenu ;
470 $common_methods = new Common_Methods();
471 $option_name = $args['option_name'];
472
473 if ( !empty($option_name) ) {
474 $options = get_option( $option_name, array() );
475 } else {
476 $options = get_option( ASENHA_SLUG_U, array() );
477 }
478
479 // Set menu items to be excluded from title renaming. These are from WordPress core.
480 $renaming_not_allowed = array(
481 'menu-dashboard',
482 'menu-pages',
483 'menu-posts',
484 'menu-media',
485 'menu-comments',
486 'menu-appearance',
487 'menu-plugins',
488 'menu-users',
489 'menu-tools',
490 'menu-settings'
491 );
492 // Get custom menu item titles
493
494 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
495 $custom_menu_titles = $options['custom_menu_titles'];
496 $custom_menu_titles = explode( ',', $custom_menu_titles );
497 } else {
498 $custom_menu_titles = array();
499 }
500
501 // Get menu items hidden by toggle
502 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
503 $i = 1;
504 // Check if there's an existing custom menu order data stored in options
505
506 if ( array_key_exists( 'custom_menu_order', $options ) ) {
507 $custom_menu = $options['custom_menu_order'];
508 $custom_menu = explode( ',', $custom_menu );
509 $menu_key_in_use = array();
510 // Render sortables with data in custom menu order
511 foreach ( $custom_menu as $custom_menu_item ) {
512 foreach ( $menu as $menu_key => $menu_info ) {
513
514 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
515 $menu_item_title = $menu_info[2];
516 $menu_item_id = $menu_info[2];
517 } else {
518 $menu_item_title = $menu_info[0];
519 $menu_item_id = $menu_info[5];
520 }
521
522 $menu_url_fragment = '';
523
524 if ( $custom_menu_item == $menu_item_id ) {
525 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
526 ?>
527 <li id="<?php
528 echo esc_attr( $menu_item_id ) ;
529 ?>" class="menu-item parent-menu-item menu-item-depth-0">
530 <div class="menu-item-bar">
531 <div class="menu-item-handle">
532 <span class="dashicons dashicons-menu"></span>
533 <div class="item-title">
534 <div class="title-wrapper">
535 <span class="menu-item-title">
536 <?php
537
538 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
539 $separator_name_ori = $menu_info[2];
540 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
541 $separator_name = str_replace( '--last', '-Last', $separator_name );
542 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
543 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
544 } else {
545
546 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
547 $menu_item_title = $menu_info[0];
548 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
549 } else {
550 // Get defaul/custom menu item title
551 foreach ( $custom_menu_titles as $custom_menu_title ) {
552 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
553 $custom_menu_title = explode( '__', $custom_menu_title );
554
555 if ( $custom_menu_title[0] == $menu_item_id ) {
556 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] );
557 // e.g. Code Snippets
558 break;
559 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
560 } else {
561 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
562 }
563
564 }
565 ?>
566 <input type="text" value="<?php
567 echo wp_kses_post( $menu_item_title ) ;
568 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
569 echo esc_attr( $menu_item_id ) ;
570 ?>">
571 <?php
572 }
573
574 }
575
576 ?>
577 </span><!-- end of .menu-item-title -->
578 <?php
579 ?>
580 </div><!-- end of .title-wrapper -->
581 <div class="options-for-hiding">
582 <?php
583 $hide_text = 'Hide until toggled';
584 $checkbox_class = 'parent-menu-hide-checkbox';
585 ?>
586 <label class="menu-item-checkbox-label">
587 <?php
588
589 if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) {
590 ?>
591 <input type="checkbox" id="hide-status-for-<?php
592 echo esc_attr( $menu_item_id_transformed ) ;
593 ?>" class="<?php
594 echo esc_attr( $checkbox_class ) ;
595 ?>" data-menu-item-title="<?php
596 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
597 ?>" data-menu-item-id="<?php
598 echo esc_attr( $menu_item_id_transformed ) ;
599 ?>" data-menu-item-id-ori="<?php
600 echo esc_attr( $menu_item_id ) ;
601 ?>" data-menu-url-fragment="<?php
602 echo esc_attr( $menu_url_fragment ) ;
603 ?>" checked>
604 <span><?php
605 echo esc_html( $hide_text ) ;
606 ?></span>
607 <?php
608 } else {
609 ?>
610 <input type="checkbox" id="hide-status-for-<?php
611 echo esc_attr( $menu_item_id_transformed ) ;
612 ?>" class="<?php
613 echo esc_attr( $checkbox_class ) ;
614 ?>" data-menu-item-title="<?php
615 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
616 ?>" data-menu-item-id="<?php
617 echo esc_attr( $menu_item_id_transformed ) ;
618 ?>" data-menu-item-id-ori="<?php
619 echo esc_attr( $menu_item_id ) ;
620 ?>" data-menu-url-fragment="<?php
621 echo esc_attr( $menu_url_fragment ) ;
622 ?>">
623 <span><?php
624 echo esc_html( $hide_text ) ;
625 ?></span>
626 <?php
627 }
628
629 ?>
630 </label>
631 <?php
632 ?>
633 </div><!-- end of .options-for-hiding -->
634 </div><!-- end of .item-title -->
635 </div><!-- end of .menu-item-handle -->
636 </div><!-- end of .menu-item-bar -->
637 <?php
638 ?>
639 <?php
640 $i = 1;
641 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
642 }
643 ?>
644 </li>
645 <?php
646 $menu_key_in_use[] = $menu_key;
647 }
648
649 }
650 }
651 // Render the rest of the current menu towards the end of the sortables
652 foreach ( $menu as $menu_key => $menu_info ) {
653
654 if ( !in_array( $menu_key, $menu_key_in_use ) ) {
655
656 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
657 $menu_item_id = $menu_info[2];
658 } else {
659 $menu_item_id = $menu_info[5];
660 }
661
662 $menu_item_title = $menu_info[0];
663 $menu_url_fragment = '';
664 // Strip tags
665 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
666 // Exclude Show All/Less toggles
667
668 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
669 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
670 ?>
671 <li id="<?php
672 echo esc_attr( $menu_item_id ) ;
673 ?>" class="menu-item parent-menu-item menu-item-depth-0">
674 <div class="menu-item-bar">
675 <div class="menu-item-handle">
676 <span class="dashicons dashicons-menu"></span>
677 <div class="item-title">
678 <div class="title-wrapper">
679 <span class="menu-item-title">
680 <?php
681
682 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
683 $separator_name_ori = $menu_info[2];
684 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
685 $separator_name = str_replace( '--last', '-Last', $separator_name );
686 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
687 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
688 } else {
689 ?>
690 <input type="text" value="<?php
691 echo wp_kses_post( $menu_item_title ) ;
692 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
693 echo esc_attr( $menu_item_id ) ;
694 ?>">
695 <?php
696 }
697
698 ?>
699 </span>
700 <?php
701 ?>
702 </div>
703 <div class="options-for-hiding">
704 <?php
705 $hide_text = 'Hide until toggled';
706 $checkbox_class = 'parent-menu-hide-checkbox';
707 ?>
708 <label class="menu-item-checkbox-label">
709 <input type="checkbox" id="hide-status-for-<?php
710 echo esc_attr( $menu_item_id_transformed ) ;
711 ?>" class="<?php
712 echo esc_attr( $checkbox_class ) ;
713 ?>" data-menu-item-id="<?php
714 echo esc_attr( $menu_item_id_transformed ) ;
715 ?>">
716 <span><?php
717 echo esc_html( $hide_text ) ;
718 ?></span>
719 </label>
720 <?php
721 ?>
722 </div><!-- end of .options-for-hiding -->
723 </div><!-- end of .item-title -->
724 </div><!-- end of .menu-item-handle -->
725 </div><!-- end of .menu-item-bar -->
726 <?php
727 ?>
728 <?php
729 $i = 1;
730 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
731 ?>
732 <?php
733 }
734 ?>
735 </li><!-- end of .menu-item -->
736 <?php
737 }
738
739 }
740
741 }
742 } else {
743 // No custom menu order has been saved yet
744 // Render sortables with existing items in the admin menu
745 foreach ( $menu as $menu_key => $menu_info ) {
746
747 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
748 $menu_item_id = $menu_info[2];
749 } else {
750 $menu_item_id = $menu_info[5];
751 }
752
753 $menu_url_fragment = '';
754 $menu_item_title = $menu_info[0];
755 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
756 // Strip tags
757 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
758 ?>
759 <li id="<?php
760 echo esc_attr( $menu_item_id ) ;
761 ?>" class="menu-item parent-menu-item menu-item-depth-0">
762 <div class="menu-item-bar">
763 <div class="menu-item-handle">
764 <span class="dashicons dashicons-menu"></span>
765 <div class="item-title">
766 <div class="title-wrapper">
767 <span class="menu-item-title">
768 <?php
769
770 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
771 $separator_name_ori = $menu_info[2];
772 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
773 $separator_name = str_replace( '--last', '-Last', $separator_name );
774 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
775 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
776 } else {
777
778 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
779 echo wp_kses_post( $menu_item_title ) ;
780 } else {
781 ?>
782 <input type="text" value="<?php
783 echo wp_kses_post( $menu_item_title ) ;
784 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
785 echo esc_attr( $menu_item_id ) ;
786 ?>">
787 <?php
788 }
789
790 }
791
792 ?>
793 </span>
794 <?php
795 ?>
796 </div><!-- end of .title-wrapper -->
797 <div class="options-for-hiding">
798 <?php
799 $hide_text = 'Hide until toggled';
800 $checkbox_class = 'parent-menu-hide-checkbox';
801 ?>
802 <label class="menu-item-checkbox-label">
803 <input type="checkbox" id="hide-status-for-<?php
804 echo esc_attr( $menu_item_id_transformed ) ;
805 ?>" class="<?php
806 echo esc_attr( $checkbox_class ) ;
807 ?>" data-menu-item-id="<?php
808 echo esc_attr( $menu_item_id_transformed ) ;
809 ?>">
810 <span><?php
811 echo esc_html( $hide_text ) ;
812 ?></span>
813 </label>
814 <?php
815 ?>
816 </div><!-- end of .options-for-hiding -->
817 </div><!-- end of .item-title -->
818 </div><!-- end of .menu-item-handle -->
819 </div><!-- end of .menu-item-bar -->
820 <?php
821 $i = 1;
822 if ( array_key_exists( $menu_info[2], $submenu ) && @is_countable( $submenu[$menu_info[2]] ) && @sizeof( $submenu[$menu_info[2]] ) > 0 ) {
823 ?>
824 <?php
825 }
826 ?>
827 </li>
828 <?php
829 }
830 }
831
832 ?>
833 </ul>
834 <?php
835 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
836 $field_id = $args['field_id'];
837 $field_name = $args['field_name'];
838 $field_description = $args['field_description'];
839 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
840 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
841 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
842 $field_id = 'custom_menu_titles';
843 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
844 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
845 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
846 // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
847 $field_id = 'custom_menu_hidden';
848 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
849 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
850 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
851 }
852
853 /**
854 * Render textarea field as sub-field of a toggle/switcher checkbox
855 *
856 * @since 2.3.0
857 */
858 function render_datatable( $args )
859 {
860 global $wpdb ;
861 $option_name = $args['option_name'];
862
863 if ( !empty($option_name) ) {
864 $options = get_option( $option_name, array() );
865 } else {
866 $options = get_option( ASENHA_SLUG_U, array() );
867 }
868
869 $field_id = $args['field_id'];
870 $field_slug = $args['field_slug'];
871 $field_name = $args['field_name'];
872 $field_type = $args['field_type'];
873 $field_description = $args['field_description'];
874 $table_title = $args['table_title'];
875 $table_name = $args['table_name'];
876 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
877 ?>
878 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
879 <thead>
880 <tr class="datatable-tr">
881 <th class="datatable-th">IP Address<br />Last Username</th>
882 <th class="datatable-th">Attempts<br />Lockouts</th>
883 <th class="datatable-th">Last Attempt On</th>
884 </tr>
885 </thead>
886 <tbody>
887 <?php
888 $limit = 1000;
889 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) );
890 $entries = $wpdb->get_results( $sql, ARRAY_A );
891 foreach ( $entries as $entry ) {
892 $unixtime = $entry['unixtime'];
893
894 if ( function_exists( 'wp_date' ) ) {
895 $date = wp_date( 'F j, Y', $unixtime );
896 $time = wp_date( 'H:i:s', $unixtime );
897 } else {
898 $date = date_i18n( 'F j, Y', $unixtime );
899 $time = date_i18n( 'H:i:s', $unixtime );
900 }
901
902 ?>
903 <tr class="datatable-tr">
904 <td class="datatable-td"><?php
905 echo esc_html( $entry['ip_address'] ) ;
906 ?><br /><?php
907 echo esc_html( $entry['username'] ) ;
908 ?></td>
909 <td class="datatable-td"><?php
910 echo esc_html( $entry['fail_count'] ) ;
911 ?><br /><?php
912 echo esc_html( $entry['lockout_count'] ) ;
913 ?></td>
914 <td class="datatable-td"><?php
915 echo esc_html( $date ) ;
916 ?><br /><?php
917 echo esc_html( $time ) ;
918 ?></td>
919 </tr>
920 <?php
921 }
922 ?>
923 </tbody>
924 </table>
925 <?php
926 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
927 }
928
929 /**
930 * Render checks and status for AVIF support
931 *
932 * @link https://php.watch/versions/8.1/gd-avif
933 * @since 5.7.0
934 */
935 public function render_avif_support_status()
936 {
937 // Check status of GD extension and it's AVIF support
938
939 if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
940 $is_gd_enabled = true;
941 $gd_info = gd_info();
942 $gd_version = $gd_info['GD Version'];
943 $gd_avif_support = ( isset( $gd_info['AVIF Support'] ) ? isset( $gd_info['AVIF Support'] ) : false );
944
945 if ( $gd_avif_support ) {
946 $gd_status = $gd_version . ' <span class="supported">with AVIF support</span>';
947 } else {
948 $gd_status = $gd_version . ' <span class="unsupported">without AVIF support</span>';
949 }
950
951 } else {
952 $is_gd_enabled = false;
953 $gd_avif_support = false;
954 $gd_status = 'Not available';
955 }
956
957 // Check status of ImageMagick library and it's AVIF support
958
959 if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
960 $is_imagick_enabled = true;
961 $imagick_version = \Imagick::getVersion();
962
963 if ( preg_match( '/((?:[0-9]+\\.?)+)/', $imagick_version['versionString'], $matches ) ) {
964 $imagick_version = $matches[0];
965 } else {
966 $imagick_version = $imagick_version['versionString'];
967 }
968
969
970 if ( version_compare( $imagick_version, '7.0.25', '>=' ) ) {
971 $imagick_avif_support = true;
972 $imagick_status = $imagick_version . ' <span class="supported">with AVIF support</span>';
973 } else {
974 $imagick_avif_support = false;
975 $imagick_status = $imagick_version . ' <span class="unsupported">without AVIF support</span>';
976 }
977
978 } else {
979 $is_imagick_enabled = false;
980 $imagick_avif_support = false;
981 $imagick_status = 'Not available';
982 }
983
984 echo '<div class="asenha-subfield-status">' ;
985 echo '<div class="status-title">AVIF Support Status</div>' ;
986 echo '<div class="status-body">' ;
987 echo '<div class="status-item"><span class="status-item-title">PHP</span> : ' . wp_kses_post( phpversion() ) . '</div>' ;
988 echo '<div class="status-item"><span class="status-item-title">GD</span> : ' . wp_kses_post( $gd_status ) . '</div>' ;
989 echo '<div class="status-item"><span class="status-item-title">ImageMagick</span> : ' . wp_kses_post( $imagick_status ) . '</div>' ;
990 echo '</div>' ;
991 echo '<div class="status-footer">Full AVIF support requires that your server / hosting has <a href="https://php.watch/versions/8.1/gd-avif" target="_blank">GD extension</a> compiled with AVIF support in PHP 8.1 or greater, or, <a href="https://avif.io/blog/tutorials/imagemagick/" target="_blank">ImageMagick 7.0.25 or greater</a> installed. Without either, you can still upload AVIF files but without auto-generation of the smaller thumbnail sizes. A majority of <a href="https://avif.io/blog/articles/avif-browser-support/" target="_blank">modern desktop and mobile browsers</a> support the display of AVIF files.</div>' ;
992 echo '</div>' ;
993 }
994
995 }