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