PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 7.0.2
Admin and Site Enhancements (ASE) v7.0.2
9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 8.3.2 8.4.0 8.4.1 8.4.2 8.5.0 8.5.1 8.5.2 8.6.0 8.6.1 8.6.2 8.7.0 5.0.1 5.0.2 5.0.2.1 5.0.2.2 5.0.2.3 5.0.2.4 5.1.0 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1 5.5.0 5.5.1 5.5.2 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.8.0 5.8.1 6.0.0 6.0.3 6.0.4 6.0.5 6.0.5.1 6.0.6 6.0.7 6.0.8.1 6.1.0 6.1.3 6.2.0 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.2.6 6.2.7 6.3.0 6.3.1 6.3.2 6.4.0 6.5.0 6.5.1 6.6.0 6.7.0 6.8.0 6.8.2 6.8.3 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13.1 6.9.13.2 6.9.2 6.9.3 6.9.4 6.9.5 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.2 7.0.2.1 7.0.2.2 7.0.2.3 7.0.3 7.1.0 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2.0 7.2.1 7.3.0 7.3.1 7.3.2 7.3.3 7.4.0 7.4.2 7.4.4 7.4.5 7.4.6 7.4.7 7.4.8 7.5.0 7.5.1 7.5.2 7.5.3 7.5.4 7.6.0 7.6.1 7.6.1.1 7.6.10 7.6.11 7.6.2 7.6.3 7.6.4 7.6.5 7.6.6 7.6.7 7.6.7.1 7.6.8 7.6.9 7.7.0 7.8.0 7.8.1 7.8.10 7.8.11 7.8.12 7.8.13 7.8.14 7.8.15 7.8.16 7.8.17 7.8.18 7.8.2 7.8.3 7.8.4 7.8.5 7.8.5.1 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1 7.9.10 7.9.11 7.9.2 7.9.3 7.9.4 7.9.5 7.9.6 7.9.7 7.9.8 7.9.9 8.0.0 8.0.1 8.0.2 8.0.3 8.0.4 8.0.5 8.0.6 8.0.7 8.0.8 8.1.0 8.1.1 8.1.2 8.1.3 8.1.4 8.2.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.2.0 3.3.0 3.4.0 3.5.0 3.6.1 3.7.0 3.8.0 3.9.0 3.9.1 3.9.2 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.8.0 4.8.1 4.8.2 4.8.3 4.9.0 4.9.1 4.9.2 4.9.3 5.0.0
admin-site-enhancements / classes / class-settings-fields-render.php
admin-site-enhancements / classes Last commit date
class-activation.php 2 years ago class-admin-columns-manager.php 2 years ago class-admin-menu-organizer.php 2 years ago class-auto-publish-posts-with-missed-schedule.php 2 years ago class-avif-upload.php 2 years ago class-change-login-url.php 2 years ago class-cleanup-admin-bar.php 2 years ago class-code-snippets-manager.php 2 years ago class-common-methods.php 2 years ago class-content-duplication.php 2 years ago class-content-order.php 2 years ago class-custom-admin-footer-text.php 2 years ago class-custom-body-class.php 2 years ago class-custom-content-types.php 2 years ago class-custom-css.php 2 years ago class-custom-nav-menu-items-in-new-tab.php 2 years ago class-deactivation.php 2 years ago class-disable-comments.php 2 years ago class-disable-dashboard-widgets.php 2 years ago class-disable-feeds.php 2 years ago class-disable-gutenberg.php 2 years ago class-disable-rest-api.php 2 years ago class-disable-smaller-components.php 2 years ago class-disable-updates.php 2 years ago class-disable-xml-rpc.php 2 years ago class-display-system-summary.php 2 years ago class-email-address-obfuscator.php 2 years ago class-email-delivery.php 2 years ago class-enhance-list-tables.php 2 years ago class-external-permalinks.php 2 years ago class-heartbeat-control.php 2 years ago class-hide-admin-bar.php 2 years ago class-hide-admin-notices.php 2 years ago class-image-sizes-panel.php 2 years ago class-image-upload-control.php 2 years ago class-insert-head-body-footer-code.php 2 years ago class-last-login-column.php 2 years ago class-limit-login-attempts.php 2 years ago class-login-id-type.php 2 years ago class-login-logout-menu.php 2 years ago class-maintenance-mode.php 2 years ago class-manage-ads-appads-txt.php 2 years ago class-manage-robots-txt.php 2 years ago class-media-replacement.php 2 years ago class-multiple-user-roles.php 2 years ago class-obfuscate-author-slugs.php 2 years ago class-open-external-links-in-new-tab.php 2 years ago class-password-protection.php 2 years ago class-redirect-after-login.php 2 years ago class-redirect-after-logout.php 2 years ago class-redirect-fourofour.php 2 years ago class-revisions-control.php 2 years ago class-search-engines-visibility.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-show-custom-taxonomy-filters.php 2 years ago class-site-identity-on-login-page.php 2 years ago class-svg-upload.php 2 years ago class-various-admin-ui-enhancements.php 2 years ago class-view-admin-as-role.php 2 years ago class-wider-admin-menu.php 2 years ago
class-settings-fields-render.php
1043 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 * Render checkbox field as a toggle/switcher
13 *
14 * @since 1.0.0
15 */
16 function render_checkbox_toggle( $args ) {
17 $option_name = $args['option_name'];
18 if ( !empty( $option_name ) ) {
19 $options = get_option( $option_name, array() );
20 } else {
21 $options = get_option( ASENHA_SLUG_U, array() );
22 }
23 $field_name = $args['field_name'];
24 $field_description = $args['field_description'];
25 $field_option_value = ( array_key_exists( $args['field_id'], $options ) ? $options[$args['field_id']] : false );
26 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-field-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
27 echo '<label for="' . esc_attr( $field_name ) . '"></label>';
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="' . esc_attr( $args['field_slug'] ) . '-show-moreless" class="show-more-less show-more" href="#">' . __( 'Expand', 'admin-site-enhancements' ) . ' &#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 echo '<div class="asenha-field-description">' . wp_kses_post( $field_description ) . '</div>';
41 // For field with additional options / sub-fields, we add wrapper for them
42 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
43 echo '<div class="asenha-subfields" style="display:none"></div>';
44 }
45 // For field with additional options / sub-fields, we add a wrapper to enclose field descriptions
46 if ( array_key_exists( 'field_options_wrapper', $args ) && $args['field_options_wrapper'] ) {
47 echo '</div>';
48 echo '</div>';
49 }
50 }
51
52 /**
53 * Render checkbox field as sub-field of a toggle/switcher checkbox
54 *
55 * @since 1.9.0
56 */
57 function render_checkbox_plain( $args ) {
58 $option_name = $args['option_name'];
59 if ( !empty( $option_name ) ) {
60 $options = get_option( $option_name, array() );
61 } else {
62 $options = get_option( ASENHA_SLUG_U, array() );
63 }
64 $field_name = $args['field_name'];
65 $field_label = $args['field_label'];
66 $default_value = false;
67 switch ( $args['field_id'] ) {
68 case 'login_page_disable_registration':
69 $default_value = ( 1 == get_option( 'users_can_register' ) ? false : true );
70 break;
71 }
72 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : $default_value );
73 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
74 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
75 }
76
77 /**
78 * Render checkbox field as sub-field of a toggle/switcher checkbox
79 *
80 * @since 1.3.0
81 */
82 function render_checkbox_subfield( $args ) {
83 $option_name = $args['option_name'];
84 if ( !empty( $option_name ) ) {
85 $options = get_option( $option_name, array() );
86 } else {
87 $options = get_option( ASENHA_SLUG_U, array() );
88 }
89 $field_name = $args['field_name'];
90 $field_label = $args['field_label'];
91 if ( 'enable_duplication_for' == $args['parent_field_id'] ) {
92 // Default is true/enabled. Usually for options introduced at a later date where the previous default is true/enabled.
93 $default_value = true;
94 } else {
95 // Default is false / checked
96 $default_value = false;
97 }
98 $field_option_value = ( isset( $options[$args['parent_field_id']][$args['field_id']] ) ? $options[$args['parent_field_id']][$args['field_id']] : $default_value );
99 echo '<input type="checkbox" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox" name="' . esc_attr( $field_name ) . '" ' . checked( $field_option_value, true, false ) . '>';
100 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . wp_kses_post( $field_label ) . '</label>';
101 }
102
103 /**
104 * Render radio buttons field as sub-field of a toggle/switcher checkbox
105 *
106 * @since 1.3.0
107 */
108 function render_radio_buttons_subfield( $args ) {
109 $option_name = $args['option_name'];
110 if ( !empty( $option_name ) ) {
111 $options = get_option( $option_name, array() );
112 } else {
113 $options = get_option( ASENHA_SLUG_U, array() );
114 }
115 $field_id = $args['field_id'];
116 $field_name = $args['field_name'];
117 $field_radios = $args['field_radios'];
118 if ( !empty( $args['field_default'] ) ) {
119 $default_value = $args['field_default'];
120 } else {
121 $default_value = false;
122 }
123 $field_description = ( isset( $args['field_description'] ) ? $args['field_description'] : '' );
124 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
125 echo '<div class="asenha-subfield-radio-button-wrapper">';
126 foreach ( $field_radios as $radio_label => $radio_value ) {
127 echo '<input type="radio" id="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $radio_value ) . '" ' . checked( $radio_value, $field_option_value, false ) . '>';
128 echo '<label for="' . esc_attr( $field_id . '_' . $radio_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $radio_label ) . '</label>';
129 }
130 echo '</div>';
131 if ( !empty( $field_description ) ) {
132 echo '<div class="asenha-subfield-description">' . wp_kses_post( $field_description ) . '</div>';
133 }
134 }
135
136 /**
137 * Render checkboxes field as sub-field of a toggle/switcher checkbox
138 *
139 * @since 6.9.2
140 */
141 function render_checkboxes_subfield( $args ) {
142 $options = get_option( ASENHA_SLUG_U, array() );
143 $field_id = $args['field_id'];
144 $field_name = $args['field_name'];
145 $field_options = $args['field_options'];
146 $layout = ( !empty( $args['layout'] ) ? $args['layout'] : 'horizontal' );
147 $default_value = ( !empty( $args['field_default'] ) ? $args['field_default'] : array() );
148 $field_option_value = ( isset( $options[$field_id] ) ? (array) $options[$field_id] : $default_value );
149 echo '<div class="wrapper-for-checkboxes ' . esc_attr( $layout ) . '">';
150 foreach ( $field_options as $option_label => $option_value ) {
151 echo '<div>';
152 echo '<input type="checkbox" id="' . esc_attr( $field_id . '_' . $option_value ) . '" class="asenha-subfield-radio-button" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $option_value ) . '" ' . checked( in_array( $option_value, $field_option_value ), 1, false ) . '>';
153 echo '<label for="' . esc_attr( $field_id . '_' . $option_value ) . '" class="asenha-subfield-radio-button-label">' . wp_kses_post( $option_label ) . '</label>';
154 echo '</div>';
155 }
156 echo '</div>';
157 }
158
159 /**
160 * Render text field as sub-field of a toggle/switcher checkbox
161 *
162 * @since 1.4.0
163 */
164 function render_text_subfield( $args ) {
165 $option_name = $args['option_name'];
166 if ( !empty( $option_name ) ) {
167 $options = get_option( $option_name, array() );
168 } else {
169 $options = get_option( ASENHA_SLUG_U, array() );
170 }
171 $field_id = $args['field_id'];
172 $field_name = $args['field_name'];
173 $field_width_classname = ( isset( $args['field_width_classname'] ) ? $args['field_width_classname'] : '' );
174 $field_type = $args['field_type'];
175 $field_prefix = $args['field_prefix'];
176 $field_suffix = $args['field_suffix'];
177 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
178 $field_description = $args['field_description'];
179 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
180 if ( $field_id == 'live_site_url' ) {
181 $field_option_value = ( isset( $options[$args['field_id']] ) ? base64_decode( $options[$args['field_id']] ) : '' );
182 }
183 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
184 $field_classname = ' with-prefix with-suffix';
185 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
186 $field_classname = ' with-prefix';
187 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
188 $field_classname = ' with-suffix';
189 } else {
190 $field_classname = '';
191 }
192 if ( !empty( $field_width_classname ) ) {
193 $field_classname .= ' ' . $field_width_classname;
194 }
195 echo wp_kses_post( $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 ) . '">' . wp_kses_post( $field_suffix );
196 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
197 }
198
199 /**
200 * Render description field as sub-field of a toggle/switcher checkbox
201 *
202 * @since 4.6.0
203 */
204 function render_description_subfield( $args ) {
205 $field_description = $args['field_description'];
206 echo '<div class="asenha-subfield-description">' . wp_kses( $field_description, get_kses_with_custom_html_ruleset() ) . '</div>';
207 }
208
209 /**
210 * Render heading for sub-fields of a toggle/switcher checkbox
211 *
212 * @since 5.0.0
213 */
214 function render_subfields_heading( $args ) {
215 $subfields_heading = $args['subfields_heading'];
216 echo '<div class="asenha-subfields-heading">' . wp_kses_post( $subfields_heading ) . '</div>';
217 }
218
219 /**
220 * Render password field as sub-field of a toggle/switcher checkbox
221 *
222 * @since 4.1.0
223 */
224 function render_password_subfield( $args ) {
225 $option_name = $args['option_name'];
226 if ( !empty( $option_name ) ) {
227 $options = get_option( $option_name, array() );
228 } else {
229 $options = get_option( ASENHA_SLUG_U, array() );
230 }
231 $field_id = $args['field_id'];
232 $field_name = $args['field_name'];
233 $field_type = $args['field_type'];
234 $field_prefix = $args['field_prefix'];
235 $field_suffix = $args['field_suffix'];
236 $field_description = $args['field_description'];
237 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
238 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
239 $field_classname = ' with-prefix with-suffix';
240 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
241 $field_classname = ' with-prefix';
242 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
243 $field_classname = ' with-suffix';
244 } else {
245 $field_classname = '';
246 }
247 $placeholder = '';
248 echo wp_kses_post( $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="' . esc_attr( $field_option_value ) . '">' . wp_kses_post( $field_suffix );
249 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
250 }
251
252 /**
253 * Render number field as sub-field of a toggle/switcher checkbox
254 *
255 * @since 1.4.0
256 */
257 function render_number_subfield( $args ) {
258 $option_name = $args['option_name'];
259 if ( !empty( $option_name ) ) {
260 $options = get_option( $option_name, array() );
261 } else {
262 $options = get_option( ASENHA_SLUG_U, array() );
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_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
271 $field_description = ( isset( $args['field_description'] ) ? $args['field_description'] : '' );
272 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
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 echo '<div class="asenha-subfield-number-wrapper">';
283 if ( !empty( $field_intro ) ) {
284 echo '<div class="asenha-subfield-number-intro">' . wp_kses_post( $field_intro ) . '</div>';
285 }
286 echo '<div>' . wp_kses_post( $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( $field_placeholder ) . '" value="' . esc_attr( $field_option_value ) . '">' . wp_kses_post( $field_suffix ) . '</div>';
287 if ( !empty( $field_description ) ) {
288 echo '<div class="asenha-subfield-number-description">' . wp_kses_post( $field_description ) . '</div>';
289 }
290 echo '</div>';
291 }
292
293 /**
294 * Render select field as sub-field of a toggle/switcher checkbox
295 *
296 * @since 1.4.0
297 */
298 function render_select_subfield( $args ) {
299 $option_name = $args['option_name'];
300 if ( !empty( $option_name ) ) {
301 $options = get_option( $option_name, array() );
302 } else {
303 $options = get_option( ASENHA_SLUG_U, array() );
304 }
305 $field_id = $args['field_id'];
306 $field_name = $args['field_name'];
307 $field_type = $args['field_type'];
308 $field_prefix = $args['field_prefix'];
309 $field_suffix = $args['field_suffix'];
310 $field_select_options = $args['field_select_options'];
311 $field_select_default = $args['field_select_default'];
312 $field_intro = $args['field_intro'];
313 $field_description = $args['field_description'];
314 if ( !empty( $args['field_select_default'] ) ) {
315 $default_value = $args['field_select_default'];
316 } else {
317 $default_value = false;
318 }
319 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
320 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
321 $field_classname = ' with-prefix with-suffix';
322 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
323 $field_classname = ' with-prefix';
324 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
325 $field_classname = ' with-suffix';
326 } else {
327 $field_classname = '';
328 }
329 if ( $args['display_none_on_load'] ) {
330 $inline_style = ' style="display:none;"';
331 } else {
332 $inline_style = '';
333 }
334 echo '<div class="asenha-subfield-select-wrapper">';
335 if ( !empty( $field_intro ) ) {
336 echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>';
337 }
338 echo '<div' . esc_attr( $inline_style ) . ' class="asenha-subfield-select-inner">' . wp_kses_post( $field_prefix );
339 echo '<select name="' . esc_attr( $field_name ) . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">';
340 foreach ( $field_select_options as $label => $value ) {
341 echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $field_option_value, false ) . '>' . esc_html( $label ) . '</option>';
342 }
343 echo '</select>';
344 echo wp_kses_post( $field_suffix ) . '</div>';
345 if ( !empty( $field_description ) ) {
346 echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>';
347 }
348 echo '</div>';
349 }
350
351 /**
352 * Render textarea field as sub-field of a toggle/switcher checkbox
353 *
354 * @since 2.3.0
355 */
356 function render_textarea_subfield( $args ) {
357 $option_name = $args['option_name'];
358 if ( !empty( $option_name ) ) {
359 $options = get_option( $option_name, array() );
360 } else {
361 $options = get_option( ASENHA_SLUG_U, array() );
362 }
363 $field_id = $args['field_id'];
364 $field_slug = $args['field_slug'];
365 $field_name = $args['field_name'];
366 $field_type = $args['field_type'];
367 $field_rows = $args['field_rows'];
368 $field_intro = $args['field_intro'];
369 $field_description = $args['field_description'];
370 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
371 // 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
372 if ( 'robots_txt_content' == $field_id ) {
373 if ( array_key_exists( 'manage_robots_txt', $options ) ) {
374 if ( !$options['manage_robots_txt'] ) {
375 // Manage robots.txt feature is NOT enabled
376 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
377 $field_option_value = $options['robots_txt_content'];
378 } else {
379 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
380 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
381 $field_option_value = $robots_txt_content;
382 }
383 } else {
384 // Manage robots.txt feature is enabled
385 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
386 $field_option_value = $options['robots_txt_content'];
387 } else {
388 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
389 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
390 $field_option_value = $robots_txt_content;
391 }
392 }
393 } else {
394 // Manage robots.txt feature has never been enabled yet
395 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
396 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
397 $field_option_value = $robots_txt_content;
398 }
399 } else {
400 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
401 }
402 echo '<div class="asenha-subfield-textarea-wrapper">';
403 if ( !empty( $field_intro ) ) {
404 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>';
405 }
406 echo '<textarea rows="' . esc_attr( $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>';
407 if ( !empty( $field_description ) ) {
408 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>';
409 }
410 echo '</div>';
411 }
412
413 /**
414 * Render textarea field as sub-field of a toggle/switcher checkbox
415 *
416 * @since 2.3.0
417 */
418 function render_wpeditor_subfield( $args ) {
419 $option_name = $args['option_name'];
420 if ( !empty( $option_name ) ) {
421 $options = get_option( $option_name, array() );
422 } else {
423 $options = get_option( ASENHA_SLUG_U, array() );
424 }
425 $field_id = $args['field_id'];
426 $field_slug = $args['field_slug'];
427 $field_name = $args['field_name'];
428 $field_type = $args['field_type'];
429 $field_intro = $args['field_intro'];
430 $field_description = $args['field_description'];
431 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
432 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
433 $editor_settings = $args['editor_settings'];
434 // https://developer.wordpress.org/reference/classes/_wp_editors/parse_settings/
435 echo '<div class="asenha-subfield-wpeditor-wrapper">';
436 if ( !empty( $field_intro ) ) {
437 echo '<div class="asenha-subfield-wpeditor-intro">' . wp_kses_post( $field_intro ) . '</div>';
438 }
439 $content = $field_option_value;
440 $editor_id = str_replace( array('[', ']'), array('--', ''), $field_name );
441 // vi( $editor_id, '', 'for ' . $field_name );
442 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
443 echo wp_editor( $content, $editor_id, $editor_settings );
444 if ( !empty( $field_description ) ) {
445 echo '<div class="asenha-subfield-wpeditor-description">' . wp_kses_post( $field_description ) . '</div>';
446 }
447 echo '</div>';
448 }
449
450 /**
451 * Render custom HTML subfield
452 *
453 * @since 5.3.0
454 */
455 function render_custom_html( $args ) {
456 echo wp_kses( $args['html'], get_kses_with_custom_html_ruleset() );
457 }
458
459 /**
460 * Render media subfield
461 *
462 * @since 6.2.2
463 */
464 function render_media_subfield( $args ) {
465 $field_id = $args['field_id'];
466 $field_slug = $args['field_slug'];
467 $field_name = $args['field_name'];
468 $field_media_frame_title = $args['field_media_frame_title'];
469 $field_media_frame_multiple = $args['field_media_frame_multiple'];
470 $field_media_frame_library_type = $args['field_media_frame_library_type'];
471 $field_media_frame_button_text = $args['field_media_frame_button_text'];
472 $field_intro = $args['field_intro'];
473 $field_description = $args['field_description'];
474 $options = get_option( $args['option_name'], array() );
475 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
476 ?>
477 <div class="media-subfield-wrapper">
478 <input id="<?php
479 echo esc_attr( $field_slug );
480 ?>" class="image-picker" type="text" size="40" name="<?php
481 echo esc_attr( $field_name );
482 ?>" value="<?php
483 echo esc_url( $field_option_value );
484 ?>" />
485 <button id="<?php
486 echo esc_attr( $field_slug );
487 ?>-button" class="image-picker-button button-secondary">Select an Image</button>
488 <?php
489 if ( !empty( $field_description ) ) {
490 echo '<div class="asenha-subfield-description media-subfield">' . wp_kses_post( $field_description ) . '</div>';
491 }
492 ?>
493 </div>
494 <?php
495 }
496
497 /**
498 * Render media subfield
499 *
500 * @since 6.2.2
501 */
502 function render_color_picker_subfield( $args ) {
503 $common_methods = new Common_Methods();
504 $field_id = $args['field_id'];
505 $field_slug = $args['field_slug'];
506 $field_name = $args['field_name'];
507 $field_intro = $args['field_intro'];
508 $field_description = $args['field_description'];
509 $field_default_value = $args['field_default_value'];
510 $options = get_option( $args['option_name'], array() );
511 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $field_default_value );
512 ?>
513 <div class="color-subfield-wrapper">
514 <input type="text" id="<?php
515 echo esc_attr( $field_slug );
516 ?>" name="<?php
517 echo esc_attr( $field_name );
518 ?>" value="<?php
519 echo esc_attr( $common_methods->sanitize_hex_color( $field_option_value ) );
520 ?>" data-default-color="<?php
521 echo esc_attr( $common_methods->sanitize_hex_color( $field_default_value ) );
522 ?>" class="color-picker"/>
523 </div>
524 <?php
525 }
526
527 /**
528 * Render sortable menu field
529 *
530 * @since 2.0.0
531 */
532 function render_sortable_menu( $args ) {
533 ?>
534 <div class="subfield-description"><?php
535 echo esc_html__( '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.', 'admin-site-enhancements' );
536 ?></div>
537 <?php
538 ?>
539 <ul id="custom-admin-menu" class="menu ui-sortable">
540 <?php
541 global $menu, $submenu;
542 $common_methods = new Common_Methods();
543 $option_name = $args['option_name'];
544 if ( !empty( $option_name ) ) {
545 $options = get_option( $option_name, array() );
546 } else {
547 $options = get_option( ASENHA_SLUG_U, array() );
548 }
549 // Set menu items to be excluded from title renaming. These are from WordPress core.
550 $renaming_not_allowed = array(
551 'menu-dashboard',
552 'menu-pages',
553 // 'menu-posts',
554 'menu-media',
555 'menu-comments',
556 'menu-appearance',
557 'menu-plugins',
558 'menu-users',
559 'menu-tools',
560 'menu-settings',
561 );
562 // Get custom menu item titles
563 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
564 $custom_menu_titles = $options['custom_menu_titles'];
565 $custom_menu_titles = explode( ',', $custom_menu_titles );
566 } else {
567 $custom_menu_titles = array();
568 }
569 // Get menu items hidden by toggle
570 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
571 $i = 1;
572 // Check if there's an existing custom menu order data stored in options
573 if ( array_key_exists( 'custom_menu_order', $options ) ) {
574 $custom_menu = $options['custom_menu_order'];
575 $custom_menu = explode( ',', $custom_menu );
576 $menu_key_in_use = array();
577 // Render sortables with data in custom menu order
578 foreach ( $custom_menu as $custom_menu_item ) {
579 foreach ( $menu as $menu_key => $menu_info ) {
580 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
581 $menu_item_title = $menu_info[2];
582 $menu_item_id = $menu_info[2];
583 } else {
584 $menu_item_title = $menu_info[0];
585 $menu_item_id = $menu_info[5];
586 }
587 $menu_url_fragment = '';
588 if ( $custom_menu_item == $menu_item_id ) {
589 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
590 $is_custom_menu = 'no';
591 ?>
592 <li id="<?php
593 echo esc_attr( $menu_item_id );
594 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
595 echo esc_attr( $is_custom_menu );
596 ?>">
597 <div class="menu-item-bar">
598 <div class="menu-item-handle">
599 <span class="dashicons dashicons-menu"></span>
600 <div class="item-title">
601 <div class="title-wrapper">
602 <span class="menu-item-title">
603 <?php
604 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
605 $separator_name_ori = $menu_info[2];
606 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
607 $separator_name = str_replace( '--last', '-Last', $separator_name );
608 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
609 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
610 } else {
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 if ( $custom_menu_title[0] == $menu_item_id ) {
620 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] );
621 // e.g. Code Snippets
622 break;
623 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
624 } else {
625 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
626 }
627 }
628 ?>
629 <input type="text" value="<?php
630 echo wp_kses_post( $menu_item_title );
631 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
632 echo esc_attr( $menu_item_id );
633 ?>">
634 <?php
635 }
636 }
637 ?>
638 </span><!-- end of .menu-item-title -->
639 <?php
640 ?>
641 </div><!-- end of .title-wrapper -->
642 <div class="options-for-hiding">
643 <?php
644 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
645 $checkbox_class = 'parent-menu-hide-checkbox';
646 ?>
647 <label class="menu-item-checkbox-label">
648 <?php
649 if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) {
650 ?>
651 <input type="checkbox" id="hide-status-for-<?php
652 echo esc_attr( $menu_item_id_transformed );
653 ?>" class="<?php
654 echo esc_attr( $checkbox_class );
655 ?>" data-menu-item-title="<?php
656 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
657 ?>" data-menu-item-id="<?php
658 echo esc_attr( $menu_item_id_transformed );
659 ?>" data-menu-item-id-ori="<?php
660 echo esc_attr( $menu_item_id );
661 ?>" data-menu-url-fragment="<?php
662 echo esc_attr( $menu_url_fragment );
663 ?>" checked>
664 <span><?php
665 echo esc_html( $hide_text );
666 ?></span>
667 <?php
668 } else {
669 ?>
670 <input type="checkbox" id="hide-status-for-<?php
671 echo esc_attr( $menu_item_id_transformed );
672 ?>" class="<?php
673 echo esc_attr( $checkbox_class );
674 ?>" data-menu-item-title="<?php
675 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
676 ?>" data-menu-item-id="<?php
677 echo esc_attr( $menu_item_id_transformed );
678 ?>" data-menu-item-id-ori="<?php
679 echo esc_attr( $menu_item_id );
680 ?>" data-menu-url-fragment="<?php
681 echo esc_attr( $menu_url_fragment );
682 ?>">
683 <span><?php
684 echo esc_html( $hide_text );
685 ?></span>
686 <?php
687 }
688 ?>
689 </label>
690 <?php
691 ?>
692 </div><!-- end of .options-for-hiding -->
693 </div><!-- end of .item-title -->
694 </div><!-- end of .menu-item-handle -->
695 </div><!-- end of .menu-item-bar -->
696 <?php
697 $i = 1;
698 ?>
699 <div class="remove-menu-item"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="#bbbbbb" d="M24 2.4L21.6 0L12 9.6L2.4 0L0 2.4L9.6 12L0 21.6L2.4 24l9.6-9.6l9.6 9.6l2.4-2.4l-9.6-9.6z"/></svg></div>
700 </li>
701 <?php
702 $menu_key_in_use[] = $menu_key;
703 }
704 }
705 }
706 // Render the rest of the current menu towards the end of the sortables
707 foreach ( $menu as $menu_key => $menu_info ) {
708 if ( !in_array( $menu_key, $menu_key_in_use ) ) {
709 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
710 $menu_item_id = $menu_info[2];
711 } else {
712 $menu_item_id = $menu_info[5];
713 }
714 $menu_item_title = $menu_info[0];
715 $menu_url_fragment = '';
716 // Strip tags
717 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
718 // Exclude Show All/Less toggles
719 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
720 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
721 $is_custom_menu = 'no';
722 ?>
723 <li id="<?php
724 echo esc_attr( $menu_item_id );
725 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
726 echo esc_attr( $is_custom_menu );
727 ?>">
728 <div class="menu-item-bar">
729 <div class="menu-item-handle">
730 <span class="dashicons dashicons-menu"></span>
731 <div class="item-title">
732 <div class="title-wrapper">
733 <span class="menu-item-title">
734 <?php
735 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
736 $separator_name_ori = $menu_info[2];
737 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
738 $separator_name = str_replace( '--last', '-Last', $separator_name );
739 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
740 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
741 } else {
742 ?>
743 <input type="text" value="<?php
744 echo wp_kses_post( $menu_item_title );
745 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
746 echo esc_attr( $menu_item_id );
747 ?>">
748 <?php
749 }
750 ?>
751 </span>
752 <?php
753 ?>
754 </div>
755 <div class="options-for-hiding">
756 <?php
757 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
758 $checkbox_class = 'parent-menu-hide-checkbox';
759 ?>
760 <label class="menu-item-checkbox-label">
761 <input type="checkbox" id="hide-status-for-<?php
762 echo esc_attr( $menu_item_id_transformed );
763 ?>" class="<?php
764 echo esc_attr( $checkbox_class );
765 ?>" data-menu-item-title="<?php
766 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
767 ?>" data-menu-item-id="<?php
768 echo esc_attr( $menu_item_id_transformed );
769 ?>" data-menu-item-id-ori="<?php
770 echo esc_attr( $menu_item_id );
771 ?>" data-menu-url-fragment="<?php
772 echo esc_attr( $menu_url_fragment );
773 ?>">
774 <span><?php
775 echo esc_html( $hide_text );
776 ?></span>
777 </label>
778 <?php
779 ?>
780 </div><!-- end of .options-for-hiding -->
781 </div><!-- end of .item-title -->
782 </div><!-- end of .menu-item-handle -->
783 </div><!-- end of .menu-item-bar -->
784 <?php
785 $i = 1;
786 ?>
787 <div class="remove-menu-item"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="#bbbbbb" d="M24 2.4L21.6 0L12 9.6L2.4 0L0 2.4L9.6 12L0 21.6L2.4 24l9.6-9.6l9.6 9.6l2.4-2.4l-9.6-9.6z"/></svg></div>
788 </li><!-- end of .menu-item -->
789 <?php
790 }
791 }
792 }
793 } else {
794 // No custom menu order has been saved yet
795 // Render sortables with existing items in the admin menu
796 foreach ( $menu as $menu_key => $menu_info ) {
797 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
798 $menu_item_id = $menu_info[2];
799 } else {
800 $menu_item_id = $menu_info[5];
801 }
802 $menu_url_fragment = '';
803 $menu_item_title = $menu_info[0];
804 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
805 // Strip tags
806 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
807 $is_custom_menu = 'no';
808 ?>
809 <li id="<?php
810 echo esc_attr( $menu_item_id );
811 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
812 echo esc_attr( $is_custom_menu );
813 ?>">
814 <div class="menu-item-bar">
815 <div class="menu-item-handle">
816 <span class="dashicons dashicons-menu"></span>
817 <div class="item-title">
818 <div class="title-wrapper">
819 <span class="menu-item-title">
820 <?php
821 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
822 $separator_name_ori = $menu_info[2];
823 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
824 $separator_name = str_replace( '--last', '-Last', $separator_name );
825 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
826 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
827 } else {
828 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
829 echo wp_kses_post( $menu_item_title );
830 } else {
831 ?>
832 <input type="text" value="<?php
833 echo wp_kses_post( $menu_item_title );
834 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
835 echo esc_attr( $menu_item_id );
836 ?>">
837 <?php
838 }
839 }
840 ?>
841 </span>
842 <?php
843 ?>
844 </div><!-- end of .title-wrapper -->
845 <div class="options-for-hiding">
846 <?php
847 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
848 $checkbox_class = 'parent-menu-hide-checkbox';
849 ?>
850 <label class="menu-item-checkbox-label">
851 <input type="checkbox" id="hide-status-for-<?php
852 echo esc_attr( $menu_item_id_transformed );
853 ?>" class="<?php
854 echo esc_attr( $checkbox_class );
855 ?>" data-menu-item-title="<?php
856 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
857 ?>" data-menu-item-id="<?php
858 echo esc_attr( $menu_item_id_transformed );
859 ?>" data-menu-item-id-ori="<?php
860 echo esc_attr( $menu_item_id );
861 ?>" data-menu-url-fragment="<?php
862 echo esc_attr( $menu_url_fragment );
863 ?>">
864 <span><?php
865 echo esc_html( $hide_text );
866 ?></span>
867 </label>
868 <?php
869 ?>
870 </div><!-- end of .options-for-hiding -->
871 </div><!-- end of .item-title -->
872 </div><!-- end of .menu-item-handle -->
873 </div><!-- end of .menu-item-bar -->
874 <?php
875 $i = 1;
876 ?>
877 <div class="remove-menu-item"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24"><path fill="#bbbbbb" d="M24 2.4L21.6 0L12 9.6L2.4 0L0 2.4L9.6 12L0 21.6L2.4 24l9.6-9.6l9.6 9.6l2.4-2.4l-9.6-9.6z"/></svg></div>
878 </li>
879 <?php
880 }
881 }
882 ?>
883 </ul>
884 <?php
885 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
886 $field_id = $args['field_id'];
887 $field_name = $args['field_name'];
888 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
889 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
890 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
891 $this->output_admin_menu_organizer_hidden_field( 'custom_menu_titles' );
892 // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
893 $this->output_admin_menu_organizer_hidden_field( 'custom_menu_hidden' );
894 }
895
896 /**
897 * Output hidden field
898 *
899 * @since 6.9.13
900 */
901 public function output_admin_menu_organizer_hidden_field( $field_id ) {
902 $options = get_option( ASENHA_SLUG_U, array() );
903 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
904 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
905 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
906 }
907
908 /**
909 * Render textarea field as sub-field of a toggle/switcher checkbox
910 *
911 * @since 2.3.0
912 */
913 function render_datatable( $args ) {
914 global $wpdb;
915 $option_name = $args['option_name'];
916 if ( !empty( $option_name ) ) {
917 $options = get_option( $option_name, array() );
918 } else {
919 $options = get_option( ASENHA_SLUG_U, array() );
920 }
921 $field_id = $args['field_id'];
922 $field_slug = $args['field_slug'];
923 $field_name = $args['field_name'];
924 $field_type = $args['field_type'];
925 $field_description = $args['field_description'];
926 $table_title = $args['table_title'];
927 $table_name = $args['table_name'];
928 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
929 ?>
930 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
931 <thead>
932 <tr class="datatable-tr">
933 <th class="datatable-th"><?php
934 _e( 'IP Address<br />Last Username', 'admin-site-enhancements' );
935 ?></th>
936 <th class="datatable-th"><?php
937 _e( 'Attempts<br />Lockouts', 'admin-site-enhancements' );
938 ?></th>
939 <th class="datatable-th"><?php
940 _e( 'Last Attempt On', 'admin-site-enhancements' );
941 ?></th>
942 </tr>
943 </thead>
944 <tbody>
945 <?php
946 $limit = 1000;
947 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array($limit) );
948 $entries = $wpdb->get_results( $sql, ARRAY_A );
949 foreach ( $entries as $entry ) {
950 $unixtime = $entry['unixtime'];
951 if ( function_exists( 'wp_date' ) ) {
952 $date = wp_date( 'F j, Y', $unixtime );
953 $time = wp_date( 'H:i:s', $unixtime );
954 } else {
955 $date = date_i18n( 'F j, Y', $unixtime );
956 $time = date_i18n( 'H:i:s', $unixtime );
957 }
958 ?>
959 <tr class="datatable-tr">
960 <td class="datatable-td"><?php
961 echo esc_html( $entry['ip_address'] );
962 ?><br /><?php
963 echo esc_html( $entry['username'] );
964 ?></td>
965 <td class="datatable-td"><?php
966 echo esc_html( $entry['fail_count'] );
967 ?><br /><?php
968 echo esc_html( $entry['lockout_count'] );
969 ?></td>
970 <td class="datatable-td"><span class="unixtime"><?php
971 echo esc_html( $entry['unixtime'] );
972 ?></span><?php
973 echo esc_html( $date );
974 ?><br /><?php
975 echo esc_html( $time );
976 ?></td>
977 </tr>
978 <?php
979 }
980 ?>
981 </tbody>
982 </table>
983 <?php
984 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
985 }
986
987 /**
988 * Render checks and status for AVIF support
989 *
990 * @link https://php.watch/versions/8.1/gd-avif
991 * @since 5.7.0
992 */
993 public function render_avif_support_status() {
994 // Check status of GD extension and it's AVIF support
995 if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
996 $is_gd_enabled = true;
997 $gd_info = gd_info();
998 $gd_version = $gd_info['GD Version'];
999 $gd_avif_support = ( isset( $gd_info['AVIF Support'] ) ? isset( $gd_info['AVIF Support'] ) : false );
1000 if ( $gd_avif_support ) {
1001 $gd_status = $gd_version . ' <span class="supported">' . __( 'with AVIF support', 'admin-site-enhancements' ) . '</span>';
1002 } else {
1003 $gd_status = $gd_version . ' <span class="unsupported">' . __( 'without AVIF support', 'admin-site-enhancements' ) . '</span>';
1004 }
1005 } else {
1006 $is_gd_enabled = false;
1007 $gd_avif_support = false;
1008 $gd_status = __( 'Not available', 'admin-site-enhancements' );
1009 }
1010 // Check status of ImageMagick library and it's AVIF support
1011 if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
1012 $is_imagick_enabled = true;
1013 $imagick_version = \Imagick::getVersion();
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 if ( version_compare( $imagick_version, '7.0.25', '>=' ) ) {
1020 $imagick_avif_support = true;
1021 $imagick_status = $imagick_version . ' <span class="supported">with AVIF support</span>';
1022 } else {
1023 $imagick_avif_support = false;
1024 $imagick_status = $imagick_version . ' <span class="unsupported">without AVIF support</span>';
1025 }
1026 } else {
1027 $is_imagick_enabled = false;
1028 $imagick_avif_support = false;
1029 $imagick_status = __( 'Not available', 'admin-site-enhancements' );
1030 }
1031 echo '<div class="asenha-subfield-status">';
1032 echo '<div class="status-title">' . __( 'AVIF Support Status', 'admin-site-enhancements' ) . '</div>';
1033 echo '<div class="status-body">';
1034 echo '<div class="status-item"><span class="status-item-title">PHP</span> : ' . wp_kses_post( phpversion() ) . '</div>';
1035 echo '<div class="status-item"><span class="status-item-title">GD</span> : ' . wp_kses_post( $gd_status ) . '</div>';
1036 echo '<div class="status-item"><span class="status-item-title">ImageMagick</span> : ' . wp_kses_post( $imagick_status ) . '</div>';
1037 echo '</div>';
1038 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.', 'admin-site-enhancements' ) . '</div>';
1039 echo '</div>';
1040 }
1041
1042 }
1043