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