PluginProbe ʕ •ᴥ•ʔ
Admin and Site Enhancements (ASE) / 7.3.2
Admin and Site Enhancements (ASE) v7.3.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
1056 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 if ( isset( $options[$field_id] ) ) {
180 if ( 'live_site_url' == $field_id ) {
181 if ( false !== strpos( $options[$field_id], 'http' ) ) {
182 $field_option_value = $options[$field_id];
183 } else {
184 // Legacy support for when base64 encoding was used prior to v7.3.1
185 $field_option_value = base64_decode( $options[$field_id] );
186 }
187 } else {
188 $field_option_value = $options[$field_id];
189 }
190 } else {
191 $field_option_value = '';
192 }
193 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
194 $field_classname = ' with-prefix with-suffix';
195 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
196 $field_classname = ' with-prefix';
197 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
198 $field_classname = ' with-suffix';
199 } else {
200 $field_classname = '';
201 }
202 if ( !empty( $field_width_classname ) ) {
203 $field_classname .= ' ' . $field_width_classname;
204 }
205 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 );
206 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
207 }
208
209 /**
210 * Render description field as sub-field of a toggle/switcher checkbox
211 *
212 * @since 4.6.0
213 */
214 function render_description_subfield( $args ) {
215 $field_description = $args['field_description'];
216 echo '<div class="asenha-subfield-description">' . wp_kses( $field_description, get_kses_with_custom_html_ruleset() ) . '</div>';
217 }
218
219 /**
220 * Render heading for sub-fields of a toggle/switcher checkbox
221 *
222 * @since 5.0.0
223 */
224 function render_subfields_heading( $args ) {
225 $subfields_heading = $args['subfields_heading'];
226 echo '<div class="asenha-subfields-heading">' . wp_kses_post( $subfields_heading ) . '</div>';
227 }
228
229 /**
230 * Render password field as sub-field of a toggle/switcher checkbox
231 *
232 * @since 4.1.0
233 */
234 function render_password_subfield( $args ) {
235 $option_name = $args['option_name'];
236 if ( !empty( $option_name ) ) {
237 $options = get_option( $option_name, array() );
238 } else {
239 $options = get_option( ASENHA_SLUG_U, array() );
240 }
241 $field_id = $args['field_id'];
242 $field_name = $args['field_name'];
243 $field_type = $args['field_type'];
244 $field_prefix = $args['field_prefix'];
245 $field_suffix = $args['field_suffix'];
246 $field_description = $args['field_description'];
247 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
248 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
249 $field_classname = ' with-prefix with-suffix';
250 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
251 $field_classname = ' with-prefix';
252 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
253 $field_classname = ' with-suffix';
254 } else {
255 $field_classname = '';
256 }
257 $placeholder = '';
258 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 );
259 echo '<label for="' . esc_attr( $field_name ) . '" class="asenha-subfield-checkbox-label">' . esc_html( $field_description ) . '</label>';
260 }
261
262 /**
263 * Render number field as sub-field of a toggle/switcher checkbox
264 *
265 * @since 1.4.0
266 */
267 function render_number_subfield( $args ) {
268 $option_name = $args['option_name'];
269 if ( !empty( $option_name ) ) {
270 $options = get_option( $option_name, array() );
271 } else {
272 $options = get_option( ASENHA_SLUG_U, array() );
273 }
274 $field_id = $args['field_id'];
275 $field_name = $args['field_name'];
276 $field_type = $args['field_type'];
277 $field_prefix = $args['field_prefix'];
278 $field_suffix = $args['field_suffix'];
279 $field_intro = $args['field_intro'];
280 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
281 $field_description = ( isset( $args['field_description'] ) ? $args['field_description'] : '' );
282 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
283 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
284 $field_classname = ' with-prefix with-suffix';
285 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
286 $field_classname = ' with-prefix';
287 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
288 $field_classname = ' with-suffix';
289 } else {
290 $field_classname = '';
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>' . 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>';
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 $option_name = $args['option_name'];
310 if ( !empty( $option_name ) ) {
311 $options = get_option( $option_name, array() );
312 } else {
313 $options = get_option( ASENHA_SLUG_U, array() );
314 }
315 $field_id = $args['field_id'];
316 $field_name = $args['field_name'];
317 $field_type = $args['field_type'];
318 $field_prefix = $args['field_prefix'];
319 $field_suffix = $args['field_suffix'];
320 $field_select_options = $args['field_select_options'];
321 $field_select_default = $args['field_select_default'];
322 $field_intro = $args['field_intro'];
323 $field_description = $args['field_description'];
324 if ( !empty( $field_select_default ) ) {
325 $default_value = $field_select_default;
326 } else {
327 $default_value = false;
328 }
329 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $default_value );
330 if ( !empty( $field_prefix ) && !empty( $field_suffix ) ) {
331 $field_classname = ' with-prefix with-suffix';
332 } elseif ( !empty( $field_prefix ) && empty( $field_suffix ) ) {
333 $field_classname = ' with-prefix';
334 } elseif ( empty( $field_prefix ) && !empty( $field_suffix ) ) {
335 $field_classname = ' with-suffix';
336 } else {
337 $field_classname = '';
338 }
339 if ( $args['display_none_on_load'] ) {
340 $inline_style = ' style="display:none;"';
341 } else {
342 $inline_style = '';
343 }
344 echo '<div class="asenha-subfield-select-wrapper">';
345 if ( !empty( $field_intro ) ) {
346 echo '<div class="asenha-subfield-select-intro">' . wp_kses_post( $field_intro ) . '</div>';
347 }
348 echo '<div' . esc_attr( $inline_style ) . ' class="asenha-subfield-select-inner">' . wp_kses_post( $field_prefix );
349 echo '<select name="' . esc_attr( $field_name ) . '" class="asenha-subfield-select' . esc_attr( $field_classname ) . '">';
350 foreach ( $field_select_options as $label => $value ) {
351 echo '<option value="' . esc_attr( $value ) . '" ' . selected( $value, $field_option_value, false ) . '>' . esc_html( $label ) . '</option>';
352 }
353 echo '</select>';
354 echo wp_kses_post( $field_suffix ) . '</div>';
355 if ( !empty( $field_description ) ) {
356 echo '<div class="asenha-subfield-select-description">' . wp_kses_post( $field_description ) . '</div>';
357 }
358 echo '</div>';
359 }
360
361 /**
362 * Render textarea field as sub-field of a toggle/switcher checkbox
363 *
364 * @since 2.3.0
365 */
366 function render_textarea_subfield( $args ) {
367 $option_name = $args['option_name'];
368 if ( !empty( $option_name ) ) {
369 $options = get_option( $option_name, array() );
370 } else {
371 $options = get_option( ASENHA_SLUG_U, array() );
372 }
373 $field_id = $args['field_id'];
374 $field_slug = $args['field_slug'];
375 $field_name = $args['field_name'];
376 $field_type = $args['field_type'];
377 $field_rows = $args['field_rows'];
378 $field_intro = $args['field_intro'];
379 $field_description = $args['field_description'];
380 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
381 // 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
382 if ( 'robots_txt_content' == $field_id ) {
383 if ( array_key_exists( 'manage_robots_txt', $options ) ) {
384 if ( !$options['manage_robots_txt'] ) {
385 // Manage robots.txt feature is NOT enabled
386 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
387 $field_option_value = $options['robots_txt_content'];
388 } else {
389 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
390 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
391 $field_option_value = $robots_txt_content;
392 }
393 } else {
394 // Manage robots.txt feature is enabled
395 if ( array_key_exists( 'robots_txt_content', $options ) && $options['robots_txt_content'] ) {
396 $field_option_value = $options['robots_txt_content'];
397 } else {
398 $robots_txt_content = wp_remote_get( get_site_url() . '/robots.txt' );
399 $robots_txt_content = esc_textarea( trim( wp_remote_retrieve_body( $robots_txt_content ) ) );
400 $field_option_value = $robots_txt_content;
401 }
402 }
403 } else {
404 // Manage robots.txt feature has never been enabled yet
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 } else {
410 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
411 }
412 echo '<div class="asenha-subfield-textarea-wrapper">';
413 if ( !empty( $field_intro ) ) {
414 echo '<div class="asenha-subfield-textarea-intro">' . wp_kses_post( $field_intro ) . '</div>';
415 }
416 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>';
417 if ( !empty( $field_description ) ) {
418 echo '<div class="asenha-subfield-textarea-description">' . wp_kses_post( $field_description ) . '</div>';
419 }
420 echo '</div>';
421 }
422
423 /**
424 * Render textarea field as sub-field of a toggle/switcher checkbox
425 *
426 * @since 2.3.0
427 */
428 function render_wpeditor_subfield( $args ) {
429 $option_name = $args['option_name'];
430 if ( !empty( $option_name ) ) {
431 $options = get_option( $option_name, array() );
432 } else {
433 $options = get_option( ASENHA_SLUG_U, array() );
434 }
435 $field_id = $args['field_id'];
436 $field_slug = $args['field_slug'];
437 $field_name = $args['field_name'];
438 $field_type = $args['field_type'];
439 $field_intro = $args['field_intro'];
440 $field_description = $args['field_description'];
441 $field_placeholder = ( isset( $args['field_placeholder'] ) ? $args['field_placeholder'] : '' );
442 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
443 $editor_settings = $args['editor_settings'];
444 // https://developer.wordpress.org/reference/classes/_wp_editors/parse_settings/
445 echo '<div class="asenha-subfield-wpeditor-wrapper">';
446 if ( !empty( $field_intro ) ) {
447 echo '<div class="asenha-subfield-wpeditor-intro">' . wp_kses_post( $field_intro ) . '</div>';
448 }
449 $content = $field_option_value;
450 $editor_id = str_replace( array('[', ']'), array('--', ''), $field_name );
451 // vi( $editor_id, '', 'for ' . $field_name );
452 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
453 echo wp_editor( $content, $editor_id, $editor_settings );
454 if ( !empty( $field_description ) ) {
455 echo '<div class="asenha-subfield-wpeditor-description">' . wp_kses_post( $field_description ) . '</div>';
456 }
457 echo '</div>';
458 }
459
460 /**
461 * Render custom HTML subfield
462 *
463 * @since 5.3.0
464 */
465 function render_custom_html( $args ) {
466 echo wp_kses( $args['html'], get_kses_with_custom_html_ruleset() );
467 }
468
469 /**
470 * Render media subfield
471 *
472 * @since 6.2.2
473 */
474 function render_media_subfield( $args ) {
475 $field_id = $args['field_id'];
476 $field_slug = $args['field_slug'];
477 $field_name = $args['field_name'];
478 $field_media_frame_title = $args['field_media_frame_title'];
479 $field_media_frame_multiple = $args['field_media_frame_multiple'];
480 $field_media_frame_library_type = $args['field_media_frame_library_type'];
481 $field_media_frame_button_text = $args['field_media_frame_button_text'];
482 $field_intro = $args['field_intro'];
483 $field_description = $args['field_description'];
484 $options = get_option( $args['option_name'], array() );
485 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
486 ?>
487 <div class="media-subfield-wrapper">
488 <input id="<?php
489 echo esc_attr( $field_slug );
490 ?>" class="image-picker" type="text" size="40" name="<?php
491 echo esc_attr( $field_name );
492 ?>" value="<?php
493 echo esc_url( $field_option_value );
494 ?>" />
495 <button id="<?php
496 echo esc_attr( $field_slug );
497 ?>-button" class="image-picker-button button-secondary"><?php
498 echo __( 'Select an Image', 'admin-site-enhancements' );
499 ?></button>
500 <?php
501 if ( !empty( $field_description ) ) {
502 echo '<div class="asenha-subfield-description media-subfield">' . wp_kses_post( $field_description ) . '</div>';
503 }
504 ?>
505 </div>
506 <?php
507 }
508
509 /**
510 * Render media subfield
511 *
512 * @since 6.2.2
513 */
514 function render_color_picker_subfield( $args ) {
515 $common_methods = new Common_Methods();
516 $field_id = $args['field_id'];
517 $field_slug = $args['field_slug'];
518 $field_name = $args['field_name'];
519 $field_intro = $args['field_intro'];
520 $field_description = $args['field_description'];
521 $field_default_value = $args['field_default_value'];
522 $options = get_option( $args['option_name'], array() );
523 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : $field_default_value );
524 ?>
525 <div class="color-subfield-wrapper">
526 <input type="text" id="<?php
527 echo esc_attr( $field_slug );
528 ?>" name="<?php
529 echo esc_attr( $field_name );
530 ?>" value="<?php
531 echo esc_attr( $common_methods->sanitize_hex_color( $field_option_value ) );
532 ?>" data-default-color="<?php
533 echo esc_attr( $common_methods->sanitize_hex_color( $field_default_value ) );
534 ?>" class="color-picker"/>
535 </div>
536 <?php
537 }
538
539 /**
540 * Render sortable menu field
541 *
542 * @since 2.0.0
543 */
544 function render_sortable_menu( $args ) {
545 $triangle_right_icon = '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 16 16"><path fill="currentColor" d="M14.222 6.687a1.5 1.5 0 0 1 0 2.629l-10 5.499A1.5 1.5 0 0 1 2 13.5V2.502a1.5 1.5 0 0 1 2.223-1.314z"/></svg>';
546 ?>
547 <div class="subfield-description"><?php
548 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' );
549 ?></div>
550 <?php
551 ?>
552 <ul id="custom-admin-menu" class="menu ui-sortable">
553 <?php
554 global $menu, $submenu;
555 $common_methods = new Common_Methods();
556 $option_name = $args['option_name'];
557 if ( !empty( $option_name ) ) {
558 $options = get_option( $option_name, array() );
559 } else {
560 $options = get_option( ASENHA_SLUG_U, array() );
561 }
562 // Set menu items to be excluded from title renaming. These are from WordPress core.
563 $renaming_not_allowed = array(
564 'menu-dashboard',
565 'menu-pages',
566 // 'menu-posts',
567 'menu-media',
568 'menu-comments',
569 'menu-appearance',
570 'menu-plugins',
571 'menu-users',
572 'menu-tools',
573 'menu-settings',
574 );
575 // Get custom menu item titles
576 if ( array_key_exists( 'custom_menu_titles', $options ) ) {
577 $custom_menu_titles = $options['custom_menu_titles'];
578 $custom_menu_titles = explode( ',', $custom_menu_titles );
579 } else {
580 $custom_menu_titles = array();
581 }
582 // Get menu items hidden by toggle
583 $menu_hidden_by_toggle = $common_methods->get_menu_hidden_by_toggle();
584 $i = 1;
585 // Check if there's an existing custom menu order data stored in options
586 if ( array_key_exists( 'custom_menu_order', $options ) ) {
587 $custom_menu = $options['custom_menu_order'];
588 $custom_menu = explode( ',', $custom_menu );
589 $menu_key_in_use = array();
590 // Render sortables with data in custom menu order
591 foreach ( $custom_menu as $custom_menu_item ) {
592 foreach ( $menu as $menu_key => $menu_info ) {
593 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
594 $menu_item_title = $menu_info[2];
595 $menu_item_id = $menu_info[2];
596 } else {
597 $menu_item_title = $menu_info[0];
598 $menu_item_id = $menu_info[5];
599 }
600 $menu_url_fragment = '';
601 if ( $custom_menu_item == $menu_item_id ) {
602 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
603 $is_custom_menu = 'no';
604 ?>
605 <li id="<?php
606 echo esc_attr( $menu_item_id );
607 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
608 echo esc_attr( $is_custom_menu );
609 ?>">
610 <div class="menu-item-bar">
611 <div class="menu-item-handle">
612 <span class="dashicons dashicons-menu"></span>
613 <div class="item-title">
614 <div class="title-wrapper">
615 <span class="menu-item-title">
616 <?php
617 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
618 $separator_name_ori = $menu_info[2];
619 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
620 $separator_name = str_replace( '--last', '-Last', $separator_name );
621 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
622 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
623 } else {
624 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
625 $menu_item_title = $menu_info[0];
626 echo wp_kses_post( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
627 } else {
628 // Get defaul/custom menu item title
629 foreach ( $custom_menu_titles as $custom_menu_title ) {
630 // At this point, $custom_menu_title value looks like toplevel_page_snippets__Code Snippets
631 $custom_menu_title = explode( '__', $custom_menu_title );
632 if ( $custom_menu_title[0] == $menu_item_id ) {
633 $menu_item_title = $common_methods->strip_html_tags_and_content( $custom_menu_title[1] );
634 // e.g. Code Snippets
635 break;
636 // stop foreach loop so $menu_item_title is not overwritten in the next iteration
637 } else {
638 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_info[0] );
639 }
640 }
641 ?>
642 <input type="text" value="<?php
643 echo wp_kses_post( $menu_item_title );
644 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
645 echo esc_attr( $menu_item_id );
646 ?>">
647 <?php
648 }
649 }
650 ?>
651 </span><!-- end of .menu-item-title -->
652 <?php
653 ?>
654 </div><!-- end of .title-wrapper -->
655 <div class="options-for-hiding">
656 <?php
657 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
658 $checkbox_class = 'parent-menu-hide-checkbox';
659 ?>
660 <label class="menu-item-checkbox-label">
661 <?php
662 if ( in_array( $custom_menu_item, $menu_hidden_by_toggle ) ) {
663 ?>
664 <input type="checkbox" id="hide-status-for-<?php
665 echo esc_attr( $menu_item_id_transformed );
666 ?>" class="<?php
667 echo esc_attr( $checkbox_class );
668 ?>" data-menu-item-title="<?php
669 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
670 ?>" data-menu-item-id="<?php
671 echo esc_attr( $menu_item_id_transformed );
672 ?>" data-menu-item-id-ori="<?php
673 echo esc_attr( $menu_item_id );
674 ?>" data-menu-url-fragment="<?php
675 echo esc_attr( $menu_url_fragment );
676 ?>" checked>
677 <span><?php
678 echo esc_html( $hide_text );
679 ?></span>
680 <?php
681 } else {
682 ?>
683 <input type="checkbox" id="hide-status-for-<?php
684 echo esc_attr( $menu_item_id_transformed );
685 ?>" class="<?php
686 echo esc_attr( $checkbox_class );
687 ?>" data-menu-item-title="<?php
688 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
689 ?>" data-menu-item-id="<?php
690 echo esc_attr( $menu_item_id_transformed );
691 ?>" data-menu-item-id-ori="<?php
692 echo esc_attr( $menu_item_id );
693 ?>" data-menu-url-fragment="<?php
694 echo esc_attr( $menu_url_fragment );
695 ?>">
696 <span><?php
697 echo esc_html( $hide_text );
698 ?></span>
699 <?php
700 }
701 ?>
702 </label>
703 <?php
704 ?>
705 </div><!-- end of .options-for-hiding -->
706 </div><!-- end of .item-title -->
707 </div><!-- end of .menu-item-handle -->
708 </div><!-- end of .menu-item-bar -->
709 <?php
710 $i = 1;
711 ?>
712 <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>
713 </li>
714 <?php
715 $menu_key_in_use[] = $menu_key;
716 }
717 }
718 }
719 // Render the rest of the current menu towards the end of the sortables
720 foreach ( $menu as $menu_key => $menu_info ) {
721 if ( !in_array( $menu_key, $menu_key_in_use ) ) {
722 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
723 $menu_item_id = $menu_info[2];
724 } else {
725 $menu_item_id = $menu_info[5];
726 }
727 $menu_item_title = $menu_info[0];
728 $menu_url_fragment = '';
729 // Strip tags
730 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
731 // Exclude Show All/Less toggles
732 if ( false === strpos( $menu_item_id, 'toplevel_page_asenha_' ) ) {
733 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
734 $is_custom_menu = 'no';
735 ?>
736 <li id="<?php
737 echo esc_attr( $menu_item_id );
738 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
739 echo esc_attr( $is_custom_menu );
740 ?>">
741 <div class="menu-item-bar">
742 <div class="menu-item-handle">
743 <span class="dashicons dashicons-menu"></span>
744 <div class="item-title">
745 <div class="title-wrapper">
746 <span class="menu-item-title">
747 <?php
748 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
749 $separator_name_ori = $menu_info[2];
750 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
751 $separator_name = str_replace( '--last', '-Last', $separator_name );
752 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
753 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
754 } else {
755 ?>
756 <input type="text" value="<?php
757 echo wp_kses_post( $menu_item_title );
758 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
759 echo esc_attr( $menu_item_id );
760 ?>">
761 <?php
762 }
763 ?>
764 </span>
765 <?php
766 ?>
767 </div>
768 <div class="options-for-hiding">
769 <?php
770 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
771 $checkbox_class = 'parent-menu-hide-checkbox';
772 ?>
773 <label class="menu-item-checkbox-label">
774 <input type="checkbox" id="hide-status-for-<?php
775 echo esc_attr( $menu_item_id_transformed );
776 ?>" class="<?php
777 echo esc_attr( $checkbox_class );
778 ?>" data-menu-item-title="<?php
779 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
780 ?>" data-menu-item-id="<?php
781 echo esc_attr( $menu_item_id_transformed );
782 ?>" data-menu-item-id-ori="<?php
783 echo esc_attr( $menu_item_id );
784 ?>" data-menu-url-fragment="<?php
785 echo esc_attr( $menu_url_fragment );
786 ?>">
787 <span><?php
788 echo esc_html( $hide_text );
789 ?></span>
790 </label>
791 <?php
792 ?>
793 </div><!-- end of .options-for-hiding -->
794 </div><!-- end of .item-title -->
795 </div><!-- end of .menu-item-handle -->
796 </div><!-- end of .menu-item-bar -->
797 <?php
798 $i = 1;
799 ?>
800 <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>
801 </li><!-- end of .menu-item -->
802 <?php
803 }
804 }
805 }
806 } else {
807 // No custom menu order has been saved yet
808 // Render sortables with existing items in the admin menu
809 foreach ( $menu as $menu_key => $menu_info ) {
810 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
811 $menu_item_id = $menu_info[2];
812 } else {
813 $menu_item_id = $menu_info[5];
814 }
815 $menu_url_fragment = '';
816 $menu_item_title = $menu_info[0];
817 $menu_item_id_transformed = $common_methods->transform_menu_item_id( $menu_item_id );
818 // Strip tags
819 $menu_item_title = $common_methods->strip_html_tags_and_content( $menu_item_title );
820 $is_custom_menu = 'no';
821 ?>
822 <li id="<?php
823 echo esc_attr( $menu_item_id );
824 ?>" class="menu-item parent-menu-item menu-item-depth-0" data-custom-menu-item="<?php
825 echo esc_attr( $is_custom_menu );
826 ?>">
827 <div class="menu-item-bar">
828 <div class="menu-item-handle">
829 <span class="dashicons dashicons-menu"></span>
830 <div class="item-title">
831 <div class="title-wrapper">
832 <span class="menu-item-title">
833 <?php
834 if ( false !== strpos( $menu_info[4], 'wp-menu-separator' ) ) {
835 $separator_name_ori = $menu_info[2];
836 $separator_name = str_replace( 'separator', 'Separator-', $separator_name_ori );
837 $separator_name = str_replace( '--last', '-Last', $separator_name );
838 $separator_name = str_replace( '--woocommerce', '--WooCommerce', $separator_name );
839 echo '~~ ' . esc_html( $separator_name ) . ' ~~';
840 } else {
841 if ( in_array( $menu_item_id, $renaming_not_allowed ) ) {
842 echo wp_kses_post( $menu_item_title );
843 } else {
844 ?>
845 <input type="text" value="<?php
846 echo wp_kses_post( $menu_item_title );
847 ?>" class="menu-item-custom-title" data-menu-item-id="<?php
848 echo esc_attr( $menu_item_id );
849 ?>">
850 <?php
851 }
852 }
853 ?>
854 </span>
855 <?php
856 ?>
857 </div><!-- end of .title-wrapper -->
858 <div class="options-for-hiding">
859 <?php
860 $hide_text = __( 'Hide until toggled', 'admin-site-enhancements' );
861 $checkbox_class = 'parent-menu-hide-checkbox';
862 ?>
863 <label class="menu-item-checkbox-label">
864 <input type="checkbox" id="hide-status-for-<?php
865 echo esc_attr( $menu_item_id_transformed );
866 ?>" class="<?php
867 echo esc_attr( $checkbox_class );
868 ?>" data-menu-item-title="<?php
869 echo esc_attr( $common_methods->strip_html_tags_and_content( $menu_item_title ) );
870 ?>" data-menu-item-id="<?php
871 echo esc_attr( $menu_item_id_transformed );
872 ?>" data-menu-item-id-ori="<?php
873 echo esc_attr( $menu_item_id );
874 ?>" data-menu-url-fragment="<?php
875 echo esc_attr( $menu_url_fragment );
876 ?>">
877 <span><?php
878 echo esc_html( $hide_text );
879 ?></span>
880 </label>
881 <?php
882 ?>
883 </div><!-- end of .options-for-hiding -->
884 </div><!-- end of .item-title -->
885 </div><!-- end of .menu-item-handle -->
886 </div><!-- end of .menu-item-bar -->
887 <?php
888 $i = 1;
889 ?>
890 <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>
891 </li>
892 <?php
893 }
894 }
895 ?>
896 </ul>
897 <?php
898 // Hidden input field to store custom menu order (from options as is, or sortupdate) upon clicking Save Changes.
899 $field_id = $args['field_id'];
900 $field_name = $args['field_name'];
901 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
902 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
903 // Hidden input field to store custom menu titles (from options as is, or custom values entered on each non-WP-default menu items.
904 $this->output_admin_menu_organizer_hidden_field( 'custom_menu_titles' );
905 // Hidden input field to store hidden menu items (from options as is, or 'Hide' checkbox clicks) upon clicking Save Changes.
906 $this->output_admin_menu_organizer_hidden_field( 'custom_menu_hidden' );
907 }
908
909 /**
910 * Output hidden field
911 *
912 * @since 6.9.13
913 */
914 public function output_admin_menu_organizer_hidden_field( $field_id ) {
915 $options = get_option( ASENHA_SLUG_U, array() );
916 $field_name = ASENHA_SLUG_U . '[' . $field_id . ']';
917 $field_option_value = ( isset( $options[$field_id] ) ? $options[$field_id] : '' );
918 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-text" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
919 }
920
921 /**
922 * Render textarea field as sub-field of a toggle/switcher checkbox
923 *
924 * @since 2.3.0
925 */
926 function render_datatable( $args ) {
927 global $wpdb;
928 $option_name = $args['option_name'];
929 if ( !empty( $option_name ) ) {
930 $options = get_option( $option_name, array() );
931 } else {
932 $options = get_option( ASENHA_SLUG_U, array() );
933 }
934 $field_id = $args['field_id'];
935 $field_slug = $args['field_slug'];
936 $field_name = $args['field_name'];
937 $field_type = $args['field_type'];
938 $field_description = $args['field_description'];
939 $table_title = $args['table_title'];
940 $table_name = $args['table_name'];
941 $field_option_value = ( isset( $options[$args['field_id']] ) ? $options[$args['field_id']] : '' );
942 ?>
943 <table id="login-attempts-log" class="wp-list-table widefat striped datatable">
944 <thead>
945 <tr class="datatable-tr">
946 <th class="datatable-th"><?php
947 _e( 'IP Address<br />Last Username', 'admin-site-enhancements' );
948 ?></th>
949 <th class="datatable-th"><?php
950 _e( 'Attempts<br />Lockouts', 'admin-site-enhancements' );
951 ?></th>
952 <th class="datatable-th"><?php
953 _e( 'Last Attempt On', 'admin-site-enhancements' );
954 ?></th>
955 </tr>
956 </thead>
957 <tbody>
958 <?php
959 $limit = 1000;
960 $sql = $wpdb->prepare( "SELECT * FROM {$table_name} ORDER BY unixtime DESC LIMIT %d", array($limit) );
961 $entries = $wpdb->get_results( $sql, ARRAY_A );
962 foreach ( $entries as $entry ) {
963 $unixtime = $entry['unixtime'];
964 if ( function_exists( 'wp_date' ) ) {
965 $date = wp_date( 'F j, Y', $unixtime );
966 $time = wp_date( 'H:i:s', $unixtime );
967 } else {
968 $date = date_i18n( 'F j, Y', $unixtime );
969 $time = date_i18n( 'H:i:s', $unixtime );
970 }
971 ?>
972 <tr class="datatable-tr">
973 <td class="datatable-td"><?php
974 echo esc_html( $entry['ip_address'] );
975 ?><br /><?php
976 echo esc_html( $entry['username'] );
977 ?></td>
978 <td class="datatable-td"><?php
979 echo esc_html( $entry['fail_count'] );
980 ?><br /><?php
981 echo esc_html( $entry['lockout_count'] );
982 ?></td>
983 <td class="datatable-td"><span class="unixtime"><?php
984 echo esc_html( $entry['unixtime'] );
985 ?></span><?php
986 echo esc_html( $date );
987 ?><br /><?php
988 echo esc_html( $time );
989 ?></td>
990 </tr>
991 <?php
992 }
993 ?>
994 </tbody>
995 </table>
996 <?php
997 echo '<input type="hidden" id="' . esc_attr( $field_name ) . '" class="asenha-subfield-datatable" name="' . esc_attr( $field_name ) . '" value="' . esc_attr( $field_option_value ) . '">';
998 }
999
1000 /**
1001 * Render checks and status for AVIF support
1002 *
1003 * @link https://php.watch/versions/8.1/gd-avif
1004 * @since 5.7.0
1005 */
1006 public function render_avif_support_status() {
1007 // Check status of GD extension and it's AVIF support
1008 if ( extension_loaded( 'gd' ) && function_exists( 'gd_info' ) ) {
1009 $is_gd_enabled = true;
1010 $gd_info = gd_info();
1011 $gd_version = $gd_info['GD Version'];
1012 $gd_avif_support = ( isset( $gd_info['AVIF Support'] ) ? isset( $gd_info['AVIF Support'] ) : false );
1013 if ( $gd_avif_support ) {
1014 $gd_status = $gd_version . ' <span class="supported">' . __( 'with AVIF support', 'admin-site-enhancements' ) . '</span>';
1015 } else {
1016 $gd_status = $gd_version . ' <span class="unsupported">' . __( 'without AVIF support', 'admin-site-enhancements' ) . '</span>';
1017 }
1018 } else {
1019 $is_gd_enabled = false;
1020 $gd_avif_support = false;
1021 $gd_status = __( 'Not available', 'admin-site-enhancements' );
1022 }
1023 // Check status of ImageMagick library and it's AVIF support
1024 if ( extension_loaded( 'imagick' ) && class_exists( 'Imagick' ) ) {
1025 $is_imagick_enabled = true;
1026 $imagick_version = \Imagick::getVersion();
1027 if ( preg_match( '/((?:[0-9]+\\.?)+)/', $imagick_version['versionString'], $matches ) ) {
1028 $imagick_version = $matches[0];
1029 } else {
1030 $imagick_version = $imagick_version['versionString'];
1031 }
1032 if ( version_compare( $imagick_version, '7.0.25', '>=' ) ) {
1033 $imagick_avif_support = true;
1034 $imagick_status = $imagick_version . ' <span class="supported">with AVIF support</span>';
1035 } else {
1036 $imagick_avif_support = false;
1037 $imagick_status = $imagick_version . ' <span class="unsupported">without AVIF support</span>';
1038 }
1039 } else {
1040 $is_imagick_enabled = false;
1041 $imagick_avif_support = false;
1042 $imagick_status = __( 'Not available', 'admin-site-enhancements' );
1043 }
1044 echo '<div class="asenha-subfield-status">';
1045 echo '<div class="status-title">' . __( 'AVIF Support Status', 'admin-site-enhancements' ) . '</div>';
1046 echo '<div class="status-body">';
1047 echo '<div class="status-item"><span class="status-item-title">PHP</span> : ' . wp_kses_post( phpversion() ) . '</div>';
1048 echo '<div class="status-item"><span class="status-item-title">GD</span> : ' . wp_kses_post( $gd_status ) . '</div>';
1049 echo '<div class="status-item"><span class="status-item-title">ImageMagick</span> : ' . wp_kses_post( $imagick_status ) . '</div>';
1050 echo '</div>';
1051 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://web.archive.org/web/20240104012918/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://web.archive.org/web/20231207174740/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>';
1052 echo '</div>';
1053 }
1054
1055 }
1056