PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 6.2.6
Admin and Site Enhancements (ASE) v6.2.6
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
1046 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 media subfield
458 *
459 * @since 6.2.2
460 */
461 function render_media_subfield( $args )
462 {
463 $field_id = $args['field_id'];
464 $field_slug = $args['field_slug'];
465 $field_name = $args['field_name'];
466 $field_media_frame_title = $args['field_media_frame_title'];
467 $field_media_frame_multiple = $args['field_media_frame_multiple'];
468 $field_media_frame_library_type = $args['field_media_frame_library_type'];
469 $field_media_frame_button_text = $args['field_media_frame_button_text'];
470 $field_intro = $args['field_intro'];
471 $field_description = $args['field_description'];
472 $options = get_option( $args['option_name'], array() );
473 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
474 ?>
475 <div class="media-subfield-wrapper">
476 <input id="<?php
477 echo esc_attr( $field_slug ) ;
478 ?>" class="image-picker" type="text" size="36" name="<?php
479 echo esc_attr( $field_name ) ;
480 ?>" value="<?php
481 echo esc_url( $field_option_value ) ;
482 ?>" />
483 <button id="<?php
484 echo esc_attr( $field_slug ) ;
485 ?>-button" class="image-picker-button button-secondary">Select an Image</button>
486 </div>
487 <?php
488 }
489
490 /**
491 * Render media subfield
492 *
493 * @since 6.2.2
494 */
495 function render_color_picker_subfield( $args )
496 {
497 $common_methods = new Common_Methods();
498 $field_id = $args['field_id'];
499 $field_slug = $args['field_slug'];
500 $field_name = $args['field_name'];
501 $field_intro = $args['field_intro'];
502 $field_description = $args['field_description'];
503 $field_default_value = $args['field_default_value'];
504 $options = get_option( $args['option_name'], array() );
505 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
506 ?>
507 <div class="color-subfield-wrapper">
508 <input type="text" id="<?php
509 echo esc_attr( $field_slug ) ;
510 ?>" name="<?php
511 echo esc_attr( $field_name ) ;
512 ?>" value="<?php
513 echo $common_methods->sanitize_hex_color( $field_option_value ) ;
514 ?>" data-default-color="<?php
515 echo $common_methods->sanitize_hex_color( $field_default_value ) ;
516 ?>" class="color-picker"/>
517 </div>
518 <?php
519 }
520
521 /**
522 * Render sortable menu field
523 *
524 * @since 2.0.0
525 */
526 function render_sortable_menu( $args )
527 {
528 ?>
529 <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>
530 <?php
531 ?>
532 <ul id="custom-admin-menu" class="menu ui-sortable">
533 <?php
534 global $menu, $submenu ;
535 $common_methods = new Common_Methods();
536 $option_name = $args['option_name'];
537
538 if ( !empty($option_name) ) {
539 $options = get_option( $option_name, array() );
540 } else {
541 $options = get_option( ASENHA_SLUG_U, array() );
542 }
543
544 // Set menu items to be excluded from title renaming. These are from WordPress core.
545 $renaming_not_allowed = array(
546 'menu-dashboard',
547 'menu-pages',
548 'menu-posts',
549 'menu-media',
550 'menu-comments',
551 'menu-appearance',
552 'menu-plugins',
553 'menu-users',
554 'menu-tools',
555 'menu-settings'
556 );
557 // Get custom menu item titles
558
559 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
560 $custom_menu_titles = $options['custom_menu_titles'];
561 $custom_menu_titles = explode( ',', $custom_menu_titles );
562 } else {
563 $custom_menu_titles = array();
564 }
565
566 // Get menu items hidden by toggle
567 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
568 $i = 1;
569 // Check if there's an existing custom menu order data stored in options
570
571 if ( array_key_exists( 'custom_menu_order', $options ) ) {
572 $custom_menu = $options['custom_menu_order'];
573 $custom_menu = explode( ',', $custom_menu );
574 $menu_key_in_use = array();
575 // Render sortables with data in custom menu order
576 foreach ( $custom_menu as $custom_menu_item ) {
577 foreach ( $menu as $menu_key => $menu_info ) {
578
579 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
580 $menu_item_title = $menu_info[2];
581 $menu_item_id = $menu_info[2];
582 } else {
583 $menu_item_title = $menu_info[0];
584 $menu_item_id = $menu_info[5];
585 }
586
587 $menu_url_fragment = '';
588
589 if ( $custom_menu_item == $menu_item_id ) {
590 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
591 ?>
592 <li id="<?php
593 echo esc_attr( $menu_item_id ) ;
594 ?>" class="menu-item parent-menu-item menu-item-depth-0">
595 <div class="menu-item-bar">
596 <div class="menu-item-handle">
597 <span class="dashicons dashicons-menu"></span>
598 <div class="item-title">
599 <div class="title-wrapper">
600 <span class="menu-item-title">
601 <?php
602
603 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
604 $separator_name_ori = $menu_info[2];
605 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
606 $separator_name = str_replace( '--last', '-Last', $separator_name );
607 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
608 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
609 } else {
610
611 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
612 $menu_item_title = $menu_info[0];
613 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
614 } else {
615 // Get defaul/custom menu item title
616 foreach ( $custom_menu_titles as $custom_menu_title ) {
617 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
618 $custom_menu_title = explode( '__', $custom_menu_title );
619
620 if ( $custom_menu_title[0] == $menu_item_id ) {
621 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] );
622 // e.g. Code Snippets
623 break;
624 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
625 } else {
626 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
627 }
628
629 }
630 ?>
631 <input type="text" value="<?php
632 echo wp_kses_post( $menu_item_title ) ;
633 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
634 echo esc_attr( $menu_item_id ) ;
635 ?>">
636 <?php
637 }
638
639 }
640
641 ?>
642 </span><!-- end of .menu-item-title -->
643 <?php
644 ?>
645 </div><!-- end of .title-wrapper -->
646 <div class="options-for-hiding">
647 <?php
648 $hide_text = 'Hide until toggled';
649 $checkbox_class = 'parent-menu-hide-checkbox';
650 ?>
651 <label class="menu-item-checkbox-label">
652 <?php
653
654 if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) {
655 ?>
656 <input type="checkbox" id="hide-status-for-<?php
657 echo esc_attr( $menu_item_id_transformed ) ;
658 ?>" class="<?php
659 echo esc_attr( $checkbox_class ) ;
660 ?>" data-menu-item-title="<?php
661 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
662 ?>" data-menu-item-id="<?php
663 echo esc_attr( $menu_item_id_transformed ) ;
664 ?>" data-menu-item-id-ori="<?php
665 echo esc_attr( $menu_item_id ) ;
666 ?>" data-menu-url-fragment="<?php
667 echo esc_attr( $menu_url_fragment ) ;
668 ?>" checked>
669 <span><?php
670 echo esc_html( $hide_text ) ;
671 ?></span>
672 <?php
673 } else {
674 ?>
675 <input type="checkbox" id="hide-status-for-<?php
676 echo esc_attr( $menu_item_id_transformed ) ;
677 ?>" class="<?php
678 echo esc_attr( $checkbox_class ) ;
679 ?>" data-menu-item-title="<?php
680 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) ) ;
681 ?>" data-menu-item-id="<?php
682 echo esc_attr( $menu_item_id_transformed ) ;
683 ?>" data-menu-item-id-ori="<?php
684 echo esc_attr( $menu_item_id ) ;
685 ?>" data-menu-url-fragment="<?php
686 echo esc_attr( $menu_url_fragment ) ;
687 ?>">
688 <span><?php
689 echo esc_html( $hide_text ) ;
690 ?></span>
691 <?php
692 }
693
694 ?>
695 </label>
696 <?php
697 ?>
698 </div><!-- end of .options-for-hiding -->
699 </div><!-- end of .item-title -->
700 </div><!-- end of .menu-item-handle -->
701 </div><!-- end of .menu-item-bar -->
702 <?php
703 $i = 1;
704 ?>
705 </li>
706 <?php
707 $menu_key_in_use[] = $menu_key;
708 }
709
710 }
711 }
712 // Render the rest of the current menu towards the end of the sortables
713 foreach ( $menu as $menu_key => $menu_info ) {
714
715 if ( !in_array( $menu_key, $menu_key_in_use ) ) {
716
717 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
718 $menu_item_id = $menu_info[2];
719 } else {
720 $menu_item_id = $menu_info[5];
721 }
722
723 $menu_item_title = $menu_info[0];
724 $menu_url_fragment = '';
725 // Strip tags
726 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
727 // Exclude Show All/Less toggles
728
729 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
730 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
731 ?>
732 <li id="<?php
733 echo esc_attr( $menu_item_id ) ;
734 ?>" class="menu-item parent-menu-item menu-item-depth-0">
735 <div class="menu-item-bar">
736 <div class="menu-item-handle">
737 <span class="dashicons dashicons-menu"></span>
738 <div class="item-title">
739 <div class="title-wrapper">
740 <span class="menu-item-title">
741 <?php
742
743 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
744 $separator_name_ori = $menu_info[2];
745 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
746 $separator_name = str_replace( '--last', '-Last', $separator_name );
747 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
748 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
749 } else {
750 ?>
751 <input type="text" value="<?php
752 echo wp_kses_post( $menu_item_title ) ;
753 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
754 echo esc_attr( $menu_item_id ) ;
755 ?>">
756 <?php
757 }
758
759 ?>
760 </span>
761 <?php
762 ?>
763 </div>
764 <div class="options-for-hiding">
765 <?php
766 $hide_text = 'Hide until toggled';
767 $checkbox_class = 'parent-menu-hide-checkbox';
768 ?>
769 <label class="menu-item-checkbox-label">
770 <input type="checkbox" id="hide-status-for-<?php
771 echo esc_attr( $menu_item_id_transformed ) ;
772 ?>" class="<?php
773 echo esc_attr( $checkbox_class ) ;
774 ?>" data-menu-item-id="<?php
775 echo esc_attr( $menu_item_id_transformed ) ;
776 ?>">
777 <span><?php
778 echo esc_html( $hide_text ) ;
779 ?></span>
780 </label>
781 <?php
782 ?>
783 </div><!-- end of .options-for-hiding -->
784 </div><!-- end of .item-title -->
785 </div><!-- end of .menu-item-handle -->
786 </div><!-- end of .menu-item-bar -->
787 <?php
788 $i = 1;
789 ?>
790 </li><!-- end of .menu-item -->
791 <?php
792 }
793
794 }
795
796 }
797 } else {
798 // No custom menu order has been saved yet
799 // Render sortables with existing items in the admin menu
800 foreach ( $menu as $menu_key => $menu_info ) {
801
802 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
803 $menu_item_id = $menu_info[2];
804 } else {
805 $menu_item_id = $menu_info[5];
806 }
807
808 $menu_url_fragment = '';
809 $menu_item_title = $menu_info[0];
810 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
811 // Strip tags
812 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
813 ?>
814 <li id="<?php
815 echo esc_attr( $menu_item_id ) ;
816 ?>" class="menu-item parent-menu-item menu-item-depth-0">
817 <div class="menu-item-bar">
818 <div class="menu-item-handle">
819 <span class="dashicons dashicons-menu"></span>
820 <div class="item-title">
821 <div class="title-wrapper">
822 <span class="menu-item-title">
823 <?php
824
825 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
826 $separator_name_ori = $menu_info[2];
827 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
828 $separator_name = str_replace( '--last', '-Last', $separator_name );
829 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
830 echo '~~ ' . esc_html( $separator_name ) . ' ~~' ;
831 } else {
832
833 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
834 echo wp_kses_post( $menu_item_title ) ;
835 } else {
836 ?>
837 <input type="text" value="<?php
838 echo wp_kses_post( $menu_item_title ) ;
839 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
840 echo esc_attr( $menu_item_id ) ;
841 ?>">
842 <?php
843 }
844
845 }
846
847 ?>
848 </span>
849 <?php
850 ?>
851 </div><!-- end of .title-wrapper -->
852 <div class="options-for-hiding">
853 <?php
854 $hide_text = 'Hide until toggled';
855 $checkbox_class = 'parent-menu-hide-checkbox';
856 ?>
857 <label class="menu-item-checkbox-label">
858 <input type="checkbox" id="hide-status-for-<?php
859 echo esc_attr( $menu_item_id_transformed ) ;
860 ?>" class="<?php
861 echo esc_attr( $checkbox_class ) ;
862 ?>" data-menu-item-id="<?php
863 echo esc_attr( $menu_item_id_transformed ) ;
864 ?>">
865 <span><?php
866 echo esc_html( $hide_text ) ;
867 ?></span>
868 </label>
869 <?php
870 ?>
871 </div><!-- end of .options-for-hiding -->
872 </div><!-- end of .item-title -->
873 </div><!-- end of .menu-item-handle -->
874 </div><!-- end of .menu-item-bar -->
875 <?php
876 $i = 1;
877 ?>
878 </li>
879 <?php
880 }
881 }
882
883 ?>
884 </ul>
885 <?php
886 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
887 $field_id = $args['field_id'];
888 $field_name = $args['field_name'];
889 $field_description = $args['field_description'];
890 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
891 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
892 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
893 $field_id = 'custom_menu_titles';
894 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
895 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
896 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
897 // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
898 $field_id = 'custom_menu_hidden';
899 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
900 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
901 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
902 }
903
904 /**
905 * Render textarea field as sub-field of a toggle/switcher checkbox
906 *
907 * @since 2.3.0
908 */
909 function render_datatable( $args )
910 {
911 global $wpdb ;
912 $option_name = $args['option_name'];
913
914 if ( !empty($option_name) ) {
915 $options = get_option( $option_name, array() );
916 } else {
917 $options = get_option( ASENHA_SLUG_U, array() );
918 }
919
920 $field_id = $args['field_id'];
921 $field_slug = $args['field_slug'];
922 $field_name = $args['field_name'];
923 $field_type = $args['field_type'];
924 $field_description = $args['field_description'];
925 $table_title = $args['table_title'];
926 $table_name = $args['table_name'];
927 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
928 ?>
929 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
930 <thead>
931 <tr class="datatable-tr">
932 <th class="datatable-th">IP Address<br />Last Username</th>
933 <th class="datatable-th">Attempts<br />Lockouts</th>
934 <th class="datatable-th">Last Attempt On</th>
935 </tr>
936 </thead>
937 <tbody>
938 <?php
939 $limit = 1000;
940 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array( $limit ) );
941 $entries = $wpdb->get_results( $sql, ARRAY_A );
942 foreach ( $entries as $entry ) {
943 $unixtime = $entry['unixtime'];
944
945 if ( function_exists( 'wp_date' ) ) {
946 $date = wp_date( 'F j, Y', $unixtime );
947 $time = wp_date( 'H:i:s', $unixtime );
948 } else {
949 $date = date_i18n( 'F j, Y', $unixtime );
950 $time = date_i18n( 'H:i:s', $unixtime );
951 }
952
953 ?>
954 <tr class="datatable-tr">
955 <td class="datatable-td"><?php
956 echo esc_html( $entry['ip_address'] ) ;
957 ?><br /><?php
958 echo esc_html( $entry['username'] ) ;
959 ?></td>
960 <td class="datatable-td"><?php
961 echo esc_html( $entry['fail_count'] ) ;
962 ?><br /><?php
963 echo esc_html( $entry['lockout_count'] ) ;
964 ?></td>
965 <td class="datatable-td"><?php
966 echo esc_html( $date ) ;
967 ?><br /><?php
968 echo esc_html( $time ) ;
969 ?></td>
970 </tr>
971 <?php
972 }
973 ?>
974 </tbody>
975 </table>
976 <?php
977 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">' ;
978 }
979
980 /**
981 * Render checks and status for AVIF support
982 *
983 * @link https://php.watch/versions/8.1/gd-avif
984 * @since 5.7.0
985 */
986 public function render_avif_support_status()
987 {
988 // Check status of GD extension and it's AVIF support
989
990 if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
991 $is_gd_enabled = true;
992 $gd_info = gd_info();
993 $gd_version = $gd_info['GD Version'];
994 $gd_avif_support = ( isset( $gd_info['AVIF Support'] ) ? isset( $gd_info['AVIF Support'] ) : false );
995
996 if ( $gd_avif_support ) {
997 $gd_status = $gd_version . ' <span class="supported">with AVIF support</span>';
998 } else {
999 $gd_status = $gd_version . ' <span class="unsupported">without AVIF support</span>';
1000 }
1001
1002 } else {
1003 $is_gd_enabled = false;
1004 $gd_avif_support = false;
1005 $gd_status = 'Not available';
1006 }
1007
1008 // Check status of ImageMagick library and it's AVIF support
1009
1010 if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
1011 $is_imagick_enabled = true;
1012 $imagick_version = \Imagick::getVersion();
1013
1014 if ( preg_match( '/((?:[0-9]+\\.?)+)/', $imagick_version['versionString'], $matches ) ) {
1015 $imagick_version = $matches[0];
1016 } else {
1017 $imagick_version = $imagick_version['versionString'];
1018 }
1019
1020
1021 if ( version_compare( $imagick_version, '7.0.25', '>=' ) ) {
1022 $imagick_avif_support = true;
1023 $imagick_status = $imagick_version . ' <span class="supported">with AVIF support</span>';
1024 } else {
1025 $imagick_avif_support = false;
1026 $imagick_status = $imagick_version . ' <span class="unsupported">without AVIF support</span>';
1027 }
1028
1029 } else {
1030 $is_imagick_enabled = false;
1031 $imagick_avif_support = false;
1032 $imagick_status = 'Not available';
1033 }
1034
1035 echo '<div class="asenha-subfield-status">' ;
1036 echo '<div class="status-title">AVIF Support Status</div>' ;
1037 echo '<div class="status-body">' ;
1038 echo '<div class="status-item"><span class="status-item-title">PHP</span> : ' . wp_kses_post( phpversion() ) . '</div>' ;
1039 echo '<div class="status-item"><span class="status-item-title">GD</span> : ' . wp_kses_post( $gd_status ) . '</div>' ;
1040 echo '<div class="status-item"><span class="status-item-title">ImageMagick</span> : ' . wp_kses_post( $imagick_status ) . '</div>' ;
1041 echo '</div>' ;
1042 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>' ;
1043 echo '</div>' ;
1044 }
1045
1046 }