PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / trunk
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP vtrunk
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / admin / settings / class-settings.php

class-settings.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP trunk, at admin/settings/class-settings.php

1,097 lines 35.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The admin-specific functionality of the plugin.
4 *
5 * @link http://wpgeodirectory.com
6 * @since 1.0.0
7 *
8 * @package userswp
9 * @subpackage userswp/admin/settings
10 */
11
12 /**
13 * The admin-specific functionality of the plugin.
14 *
15 * Defines the plugin name, version, and two examples hooks for how to
16 * enqueue the admin-specific stylesheet and JavaScript.
17 *
18 * @package userswp
19 * @subpackage userswp/admin/settings
20 * @author GeoDirectory Team <info@wpgeodirectory.com>
21 */
22 class UsersWP_Admin_Settings {
23
24 /**
25 * Setting pages.
26 *
27 * @var array
28 */
29 private static $settings = array();
30
31 /**
32 * Error messages.
33 *
34 * @var array
35 */
36 private static $errors = array();
37
38 /**
39 * Update messages.
40 *
41 * @var array
42 */
43 private static $messages = array();
44
45 public function __construct() {
46
47 }
48
49 /**
50 * Include the settings page classes.
51 */
52 public static function get_settings_pages() {
53 if ( empty( self::$settings ) ) {
54 $settings = array();
55
56 $settings[] = include 'class-uwp-settings-general.php';
57 $settings[] = include 'class-uwp-settings-redirects.php';
58 $settings[] = include 'class-uwp-settings-emails.php';
59 $settings[] = include 'class-uwp-settings-import-export.php';
60 $settings[] = include 'class-uwp-settings-addons.php';
61 $settings[] = include 'class-uwp-settings-uninstall.php';
62
63 self::$settings = apply_filters( 'uwp_get_settings_pages', $settings );
64 }
65
66 return self::$settings;
67 }
68
69 /**
70 * Save the settings.
71 */
72 public static function save() {
73 global $current_tab;
74
75 if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'userswp-settings' ) ) {
76 die( esc_html__( 'Action failed. Please refresh the page and retry.', 'userswp' ) );
77 }
78
79 // Trigger actions
80 do_action( 'uwp_settings_save_' . $current_tab );
81 do_action( 'uwp_update_options_' . $current_tab );
82 do_action( 'uwp_update_options' );
83
84 self::add_message( __( 'Your settings have been saved.', 'userswp' ) );
85
86 // Clear flush rules
87 wp_schedule_single_event( time(), 'uwp_flush_rewrite_rules' );
88
89 do_action( 'uwp_settings_saved' );
90 }
91
92 /**
93 * Add a message.
94 * @param string $text
95 */
96 public static function add_message( $text ) {
97 self::$messages[] = $text;
98 }
99
100 /**
101 * Add an error.
102 * @param string $text
103 */
104 public static function add_error( $text ) {
105 self::$errors[] = $text;
106 }
107
108 /**
109 * Output messages + errors.
110 */
111 public static function show_messages() {
112 if ( sizeof( self::$errors ) > 0 ) {
113 foreach ( self::$errors as $error ) {
114 echo '<div id="message" class="error inline"><p><strong>' . esc_html( $error ) . '</strong></p></div>';
115 }
116 } elseif ( sizeof( self::$messages ) > 0 ) {
117 foreach ( self::$messages as $message ) {
118 echo '<div id="message" class="updated inline"><p><strong>' . esc_html( $message ) . '</strong></p></div>';
119 }
120 }
121 }
122
123 /**
124 * Settings page.
125 *
126 * Handles the display of the main userswp settings page in admin.
127 */
128 public static function output( $tab = '' ) {
129 global $current_section, $current_tab;
130
131 do_action( 'uwp_settings_start' );
132
133 // Include settings pages
134 self::get_settings_pages();
135
136 // Get current tab/section
137 if ( $tab ) {
138 $current_tab = sanitize_title( $tab );
139
140 } else {
141 $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
142
143 }
144 $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
145
146 // Save settings if data has been posted
147 if ( ! empty( $_POST ) ) {
148 self::save();
149 }
150
151 // Add any posted messages
152 if ( ! empty( $_GET['uwp_error'] ) ) {
153 self::add_error( stripslashes( $_GET['uwp_error'] ) );
154 }
155
156 if ( ! empty( $_GET['uwp_message'] ) ) {
157 self::add_message( stripslashes( $_GET['uwp_message'] ) );
158 }
159
160 // Get tabs for the settings page
161 $tabs = apply_filters( 'uwp_settings_tabs_array', array() );
162
163 include USERSWP_PATH . '/admin/views/html-admin-settings.php';
164 }
165
166 /**
167 * Output admin fields.
168 *
169 * Loops though the userswp options array and outputs each field.
170 *
171 * @param array $options Opens array to output
172 */
173 public static function output_fields( $options ) {
174 foreach ( $options as $value ) {
175 if ( ! isset( $value['type'] ) ) {
176 continue;
177 }
178 if ( ! isset( $value['id'] ) ) {
179 $value['id'] = '';
180 }
181 if ( ! isset( $value['title'] ) ) {
182 $value['title'] = isset( $value['name'] ) ? $value['name'] : '';
183 }
184 if ( ! isset( $value['class'] ) ) {
185 $value['class'] = '';
186 }
187 if ( ! isset( $value['css'] ) ) {
188 $value['css'] = '';
189 }
190 if ( ! isset( $value['default'] ) ) {
191 $value['default'] = '';
192 }
193 if ( ! isset( $value['desc'] ) ) {
194 $value['desc'] = '';
195 }
196 if ( ! isset( $value['desc_tip'] ) ) {
197 $value['desc_tip'] = false;
198 }
199 if ( ! isset( $value['placeholder'] ) ) {
200 $value['placeholder'] = '';
201 }
202
203 // Custom attribute handling
204 $custom_attributes = array();
205
206 if ( ! empty( $value['custom_attributes'] ) && is_array( $value['custom_attributes'] ) ) {
207 foreach ( $value['custom_attributes'] as $attribute => $attribute_value ) {
208 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
209 }
210 }
211
212 $wrap_class = $value['id'] . '-wrap';
213
214 // Description handling
215 $field_description = self::get_field_description( $value );
216 $tooltip_html = $field_description['tooltip_html'] ? $field_description['tooltip_html'] : '';
217 $description = $field_description['description'] ? $field_description['description'] : '';
218
219 // Switch based on type
220 switch ( $value['type'] ) {
221
222 // Section Titles
223 case 'title':
224 if ( ! empty( $value['title'] ) ) {
225 echo '<h2 class="uwp-settings-title">';
226 echo esc_html( $value['title'] );
227 if ( ! empty( $value['title_html'] ) ) {
228 echo $value['title_html'];} // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
229 if ( isset( $value['desc_tip'] ) && $value['desc_tip'] ) {
230 echo $tooltip_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
231 }
232 echo '</h2>';
233 }
234
235 if ( ! empty( $value['desc'] ) && ( ! isset( $value['desc_tip'] ) || ! $value['desc_tip'] ) ) {
236 echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
237 }
238
239 echo '<table class="form-table">' . "\n\n";
240 if ( ! empty( $value['id'] ) ) {
241 do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) );
242 }
243 break;
244
245 // Section Ends
246 case 'sectionend':
247 if ( ! empty( $value['id'] ) ) {
248 do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) . '_end' );
249 }
250 echo '</table>';
251 if ( ! empty( $value['id'] ) ) {
252 do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) . '_after' );
253 }
254 break;
255
256 // Standard text inputs and subtypes like 'number'
257 case 'text':
258 case 'email':
259 case 'number':
260 case 'url':
261 case 'password':
262 if ( isset( $value['value'] ) ) {
263 $option_value = $value['value'];
264 } else {
265 $option_value = self::get_option( $value['id'], $value['default'] );
266 }
267 ?><tr valign="top" class="
268 <?php
269 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
270 echo 'uwp-advanced-setting';}
271 ?>
272 ">
273 <th scope="row" class="titledesc">
274 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
275 <?php echo wp_kses_post( $tooltip_html ); ?>
276 </th>
277 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
278 <input
279 name="<?php echo esc_attr( $value['id'] ); ?>"
280 id="<?php echo esc_attr( $value['id'] ); ?>"
281 type="<?php echo esc_attr( $value['type'] ); ?>"
282 style="<?php echo esc_attr( $value['css'] ); ?>"
283 value="<?php echo esc_attr( $option_value ); ?>"
284 class="regular-text <?php echo esc_attr( $value['class'] ); ?>"
285 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
286 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
287 <?php
288 if ( ! empty( $value['disabled'] ) && true == $value['disabled'] ) {
289 echo 'disabled="disabled"'; }
290 ?>
291 <?php
292 if ( ! empty( $value['readonly'] ) && true == $value['readonly'] ) {
293 echo 'readonly="readonly"'; }
294 ?>
295 <?php
296 if ( $value['type'] == 'number' ) {
297 echo "lang='EN'";} // HTML5 number input can change number format depending on browser language, we don't want that
298 ?>
299 /> <?php echo wp_kses_post( $description ); ?>
300 </td>
301 </tr>
302 <?php
303 break;
304
305 // Color picker.
306 case 'color':
307 if ( isset( $value['value'] ) ) {
308 $option_value = $value['value'];
309 } else {
310 $option_value = self::get_option( $value['id'], $value['default'] );
311 }
312
313 ?>
314 <tr valign="top" class="uwp-row-color-picker
315 <?php
316 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
317 echo 'uwp-advanced-setting';}
318 ?>
319 ">
320 <th scope="row" class="titledesc">
321 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
322 <?php echo wp_kses_post( $tooltip_html ); ?>
323 </th>
324 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
325 <input
326 name="<?php echo esc_attr( $value['id'] ); ?>"
327 id="<?php echo esc_attr( sanitize_key( $value['id'] ) ); ?>"
328 type="text"
329 dir="ltr"
330 value="<?php echo esc_attr( $option_value ); ?>"
331 class="uwp-color-picker"
332 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
333 data-default-color="<?php echo esc_attr( $value['default'] ); ?>
334 <?php echo esc_attr( implode( ' ', $custom_attributes ) ); ?> "/>&lrm; <?php echo wp_kses_post( $description ); ?>
335 </td>
336 </tr>
337 <?php
338 break;
339
340 // Color picker.
341 case 'image':
342 // add required scripts
343 add_thickbox();
344 wp_enqueue_script( 'media-upload' );
345 wp_enqueue_media();
346
347 if ( isset( $value['value'] ) ) {
348 $option_value = $value['value'];
349 } else {
350 $option_value = self::get_option( $value['id'], $value['default'] );
351 }
352 $image_size = ! empty( $value['image_size'] ) ? $value['image_size'] : 'thumbnail';
353
354 if ( $option_value ) {
355 $remove_class = '';
356 if ( strpos( $option_value, 'dashicons-' ) === 0 ) {
357 $show_img = '<div class="dashicons-before ' . esc_attr( $option_value ) . '"></div>';
358 } else {
359 $show_img = wp_get_attachment_image( $option_value, $image_size );
360 }
361 } else {
362 $remove_class = 'hidden';
363 $show_img = '<img src="' . admin_url( 'images/media-button-image.gif' ) . '" />';
364 }
365
366 ?>
367 <tr valign="top" class="
368 <?php
369 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
370 echo 'uwp-advanced-setting';}
371 ?>
372 ">
373 <th scope="row" class="titledesc">
374 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
375 <?php echo wp_kses_post( $tooltip_html ); ?>
376 </th>
377 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
378
379 <div class="uwp-upload-img" data-field="<?php echo esc_attr( $value['id'] ); ?>">
380 <div class="uwp-upload-display uwp-img-size-<?php echo esc_attr( $image_size ); ?> thumbnail"><div class="centered"><?php echo $show_img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div></div>
381 <div class="uwp-upload-fields">
382 <input type="hidden" id="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>" value="<?php echo esc_attr( $option_value ); ?>" />
383 <button type="button" class="uwp_upload_image_button button"><?php esc_html_e( 'Upload Image', 'userswp' ); ?></button>
384 <button type="button" class="uwp_remove_image_button button <?php echo esc_attr( $remove_class ); ?>"><?php esc_html_e( 'Remove Image', 'userswp' ); ?></button>
385 </div>
386 </div>
387 </td>
388 </tr>
389 <?php
390 break;
391
392 // Textarea
393 case 'textarea':
394 if ( isset( $value['value'] ) ) {
395 $option_value = $value['value'];
396 } else {
397 $option_value = self::get_option( $value['id'], $value['default'] );
398 }
399
400 $rows = ! empty( $value['size'] ) ? absint( $value['size'] ) : 5;
401
402 ?>
403 <tr valign="top" class="
404 <?php
405 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
406 echo 'uwp-advanced-setting';}
407 ?>
408 ">
409 <th scope="row" class="titledesc">
410 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
411 <?php echo wp_kses_post( $tooltip_html ); ?>
412 </th>
413 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
414 <?php echo wp_kses_post( $description ); ?>
415
416 <textarea
417 name="<?php echo esc_attr( $value['id'] ); ?>"
418 id="<?php echo esc_attr( $value['id'] ); ?>"
419 style="<?php echo esc_attr( $value['css'] ); ?>"
420 class="large-text <?php echo esc_attr( $value['class'] ); ?>"
421 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
422 rows="<?php echo esc_attr( $rows ); ?>"
423 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
424 ><?php echo esc_textarea( stripslashes( $option_value ) ); ?></textarea>
425 <?php if ( ! empty( $value['custom_desc'] ) ) { ?>
426 <span class="uwp-custom-desc"><?php echo wp_kses_post( $value['custom_desc'] ); ?></span>
427 <?php } ?>
428 </td>
429 </tr>
430 <?php
431 break;
432 // Editor
433 case 'editor':
434 global $wp_version;
435 if ( isset( $value['value'] ) ) {
436 $option_value = $value['value'];
437 } else {
438 $option_value = self::get_option( $value['id'] );
439 }
440 if ( empty( $option_value ) && empty( $value['allow_blank'] ) ) {
441 $option_value = isset( $value['default'] ) ? $value['default'] : '';
442 }
443
444 $rows = ! empty( $value['size'] ) ? absint( $value['size'] ) : 20;
445 ?>
446 <tr valign="top" class="<?php echo ( ! empty( $value['advanced'] ) ? 'uwp-advanced-setting' : '' ); ?>">
447 <th scope="row" class="titledesc">
448 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
449 <?php echo wp_kses_post( $tooltip_html ); ?>
450 </th>
451 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
452 <?php echo wp_kses_post( $description ); ?>
453 <?php
454 if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
455 wp_editor(
456 stripslashes( $option_value ),
457 $value['id'],
458 array(
459 'textarea_name' => esc_attr( $value['id'] ),
460 'textarea_rows' => $rows,
461 'media_buttons' => false,
462 'editor_class' => 'uwp-wp-editor',
463 'editor_height' => 16 * $rows,
464 )
465 );
466 } else {
467 ?>
468 <textarea
469 name="<?php echo esc_attr( $value['id'] ); ?>"
470 id="<?php echo esc_attr( $value['id'] ); ?>"
471 style="<?php echo esc_attr( $value['css'] ); ?>"
472 class="large-text <?php echo esc_attr( $value['class'] ); ?>"
473 placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
474 rows="<?php echo esc_attr( $rows ); ?>"
475 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
476 ><?php echo esc_textarea( stripslashes( $option_value ) ); ?></textarea>
477 <?php } ?>
478 <?php if ( ! empty( $value['custom_desc'] ) ) { ?>
479 <span class="uwp-custom-desc"><?php echo wp_kses_post( $value['custom_desc'] ); ?></span>
480 <?php } ?>
481 </td>
482 </tr>
483 <?php
484 break;
485
486 // Select boxes
487 case 'select':
488 case 'multiselect':
489 if ( isset( $value['value'] ) ) {
490 $option_value = $value['value'];
491 } else {
492 $option_value = self::get_option( $value['id'], $value['default'] );
493 }
494
495 if ( ! empty( $value['type'] ) && 'multiselect' == $value['type'] && ! is_array( $option_value ) ) {
496 $option_value = str_replace( ' ', '', $option_value );
497 $option_value = explode( ',', $option_value );
498 }
499
500 ?>
501 <tr valign="top" class="
502 <?php
503 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
504 echo 'uwp-advanced-setting';}
505 ?>
506 ">
507 <th scope="row" class="titledesc">
508 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
509 <?php echo wp_kses_post( $tooltip_html ); ?>
510 </th>
511 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
512 <select
513 name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
514 id="<?php echo esc_attr( $value['id'] ); ?>"
515 style="<?php echo esc_attr( $value['css'] ); ?>"
516 class="regular-text aui-select2 <?php echo esc_attr( $value['class'] ); ?>"
517 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
518 <?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
519 <?php echo ! empty( $value['sortable'] ) ? ' data-sortable="true"' : ''; ?>
520 <?php echo ! empty( $value['placeholder'] ) ? ' data-placeholder="' . esc_attr( $value['placeholder'] ) . '"' : ''; ?>
521 >
522 <?php
523 foreach ( $value['options'] as $key => $val ) {
524 if ( stripos( strrev( $key ), strrev( 'optgroup-open' ) ) === 0 ) {
525 echo '<optgroup label="' . esc_attr( $val ) . '">';
526 } elseif ( stripos( strrev( $key ), strrev( 'optgroup-close' ) ) === 0 ) {
527 echo '</optgroup>';
528 } else {
529 ?>
530 <option value="<?php echo esc_attr( $key ); ?>"
531 <?php
532
533 if ( is_array( $option_value ) ) {
534 selected( in_array( $key, $option_value ), true );
535 } else {
536 selected( $option_value, $key );
537 }
538
539 ?>
540 ><?php echo esc_html( $val ); ?></option>
541 <?php
542 }
543 }
544 ?>
545 </select> <?php echo wp_kses_post( $description ); ?>
546 </td>
547 </tr>
548 <?php
549 break;
550
551 // Radio inputs
552 case 'radio':
553 if ( isset( $value['value'] ) ) {
554 $option_value = $value['value'];
555 } else {
556 $option_value = self::get_option( $value['id'], $value['default'] );
557 }
558
559 ?>
560 <tr valign="top" class="<?php echo esc_attr( $wrap_class ); ?>
561 <?php
562 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
563 echo ' uwp-advanced-setting';}
564 ?>
565 ">
566 <th scope="row" class="titledesc">
567 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
568 <?php echo wp_kses_post( $tooltip_html ); ?>
569 </th>
570 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
571 <fieldset>
572 <?php echo wp_kses_post( $description ); ?>
573 <ul>
574 <?php
575 foreach ( $value['options'] as $key => $val ) {
576 ?>
577 <li>
578 <label><input
579 name="<?php echo esc_attr( $value['id'] ); ?>"
580 value="<?php echo esc_attr( $key ); ?>"
581 type="radio"
582 style="<?php echo esc_attr( $value['css'] ); ?>"
583 class="<?php echo esc_attr( $value['class'] ); ?>"
584 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
585 <?php checked( $key, $option_value ); ?>
586 /> <?php echo esc_html( $val ); ?></label>
587 </li>
588 <?php
589 }
590 ?>
591 </ul>
592 </fieldset>
593 </td>
594 </tr>
595 <?php
596 break;
597
598 // Checkbox input
599 case 'checkbox':
600 if ( isset( $value['value'] ) ) {
601 $option_value = $value['value'];
602 } else {
603 $option_value = self::get_option( $value['id'], $value['default'] );
604 }
605 $visibility_class = array();
606
607 if ( ! isset( $value['hide_if_checked'] ) ) {
608 $value['hide_if_checked'] = false;
609 }
610 if ( ! isset( $value['show_if_checked'] ) ) {
611 $value['show_if_checked'] = false;
612 }
613 if ( 'yes' == $value['hide_if_checked'] || 'yes' == $value['show_if_checked'] ) {
614 $visibility_class[] = 'hidden_option';
615 }
616 if ( 'option' == $value['hide_if_checked'] ) {
617 $visibility_class[] = 'hide_options_if_checked';
618 }
619 if ( 'option' == $value['show_if_checked'] ) {
620 $visibility_class[] = 'show_options_if_checked';
621 }
622
623 if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
624 ?>
625 <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?> <?php
626 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
627 echo 'uwp-advanced-setting';}
628 ?>
629 " >
630 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
631 <td class="forminp forminp-checkbox">
632 <fieldset>
633 <?php
634 } else {
635 ?>
636 <fieldset class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
637 <?php
638 }
639
640 if ( ! empty( $value['title'] ) ) {
641 ?>
642 <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
643
644 <?php
645 }
646
647 ?>
648 <label for="<?php echo esc_attr( $value['id'] ); ?>">
649 <input
650 name="<?php echo esc_attr( $value['id'] ); ?>"
651 id="<?php echo esc_attr( $value['id'] ); ?>"
652 type="checkbox"
653 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
654 value="1"
655 <?php checked( $option_value, '1' ); ?>
656 <?php checked( $option_value, 'yes' ); ?>
657 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
658 /> <?php echo wp_kses_post( $description ); ?>
659 </label> <?php echo wp_kses_post( $tooltip_html ); ?>
660 <?php
661
662 if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
663 ?>
664 </fieldset>
665 </td>
666 </tr>
667 <?php
668 } else {
669 ?>
670 </fieldset>
671 <?php
672 }
673 break;
674
675 // Checkbox input
676 case 'multicheckbox':
677 if ( isset( $value['value'] ) ) {
678 $option_value = $value['value'];
679 } else {
680 $option_value = self::get_option( $value['id'], $value['default'] );
681 }
682
683 ?>
684 <tr valign="top" class="
685 <?php
686 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
687 echo 'uwp-advanced-setting';}
688 ?>
689 " >
690 <th scope="row" class="titledesc">
691 <label><?php echo esc_html( $value['title'] ); ?></label>
692 <?php echo wp_kses_post( $tooltip_html ); ?>
693 </th>
694 <td class="forminp forminp-checkbox">
695 <div class="uwp-mcheck-rows uwp-mcheck-<?php echo sanitize_key( $value['id'] ); ?>">
696 <?php
697 foreach ( $value['options'] as $key => $title ) {
698 if ( ! empty( $option_value ) && is_array( $option_value ) && in_array( $key, $option_value ) ) {
699 $checked = true;
700 } else {
701 $checked = false;
702 }
703 ?>
704 <div class="uwp-mcheck-row">
705 <input
706 name="<?php echo esc_attr( $value['id'] ); ?>[<?php echo esc_attr( $key ); ?>]"
707 id="<?php echo esc_attr( $value['id'] . '-' . sanitize_key( $key ) ); ?>"
708 type="checkbox"
709 class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
710 value="<?php echo esc_attr( $key ); ?>"
711 <?php checked( $checked, true ); ?>
712 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
713 /> <label for="<?php echo esc_attr( $value['id'] . '-' . sanitize_key( $key ) ); ?>"><?php echo esc_html( $title ); ?></label></div>
714 <?php } ?>
715 <?php echo wp_kses_post( $description ); ?>
716 </div>
717 </td>
718 </tr>
719 <?php
720 break;
721
722 // Single page selects
723 case 'single_select_page':
724 if ( isset( $value['value'] ) ) {
725 $option_value = $value['value'];
726 } else {
727 $option_value = self::get_option( $value['id'] );
728 }
729
730 $args = array(
731 'name' => $value['id'],
732 'id' => $value['id'],
733 'sort_column' => 'menu_order',
734 'sort_order' => 'ASC',
735 'show_option_none' => ' ',
736 'class' => ' regular-text aui-select2 ' . $value['class'],
737 'echo' => false,
738 'selected' => (int) $option_value > 0 ? (int) $option_value : -1,
739 );
740
741 if ( isset( $value['args'] ) ) {
742 $args = wp_parse_args( $value['args'], $args );
743 }
744
745 ?>
746 <tr valign="top" class="single_select_page
747 <?php
748 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
749 echo 'uwp-advanced-setting';}
750 ?>
751 ">
752 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></th>
753 <td class="forminp">
754 <?php echo str_replace( ' id=', " data-placeholder='" . esc_attr__( 'Select a page&hellip;', 'userswp' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> <?php echo wp_kses_post( $description ); ?>
755
756 <?php if ( isset( $args['selected'] ) && $args['selected'] > 0 ) { ?>
757 <a href="<?php echo esc_url( get_edit_post_link( $args['selected'] ) ); ?>" class="button uwp-page-setting-edit"><?php esc_html_e( 'Edit Page', 'userswp' ); ?></a>
758
759 <?php if ( empty( $value['is_template_page'] ) ) { ?>
760 <a href="<?php echo esc_url( get_permalink( $args['selected'] ) ); ?>" class="button uwp-page-setting-view"><?php esc_html_e( 'View Page', 'userswp' ); ?></a>
761 <?php
762 }
763 }
764
765 ?>
766
767 </td>
768 </tr>
769 <?php
770 break;
771
772 case 'import_export_users':
773 ?>
774
775 <tr valign="top" class="
776 <?php
777 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
778 echo 'uwp-advanced-setting';}
779 ?>
780 ">
781 <td class="forminp" colspan="2">
782 <?php
783 /**
784 * Contains template for import/export users.
785 *
786 */
787 include_once USERSWP_PATH . '/admin/views/html-admin-settings-import-export-users.php';
788 ?>
789 </td>
790 </tr>
791
792 <?php
793
794 break;
795
796 case 'import_export_settings':
797 ?>
798
799 <tr valign="top" class="
800 <?php
801 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
802 echo 'uwp-advanced-setting';}
803 ?>
804 ">
805 <td class="forminp" colspan="2">
806 <?php
807 /**
808 * Contains template for import/export settings.
809 *
810 */
811 include_once USERSWP_PATH . '/admin/views/html-admin-settings-import-export-settings.php';
812 ?>
813 </td>
814 </tr>
815
816 <?php
817
818 break;
819
820 case 'hidden':
821 if ( isset( $value['value'] ) ) {
822 $option_value = $value['value'];
823 } else {
824 $option_value = self::get_option( $value['id'], $value['default'] );
825 }
826 ?>
827 <tr valign="top" style="display:none!important">
828 <th scope="row" class="titledesc">
829 <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
830 </th>
831 <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
832 <input
833 name="<?php echo esc_attr( $value['id'] ); ?>"
834 id="<?php echo esc_attr( $value['id'] ); ?>"
835 type="hidden"
836 value="<?php echo esc_attr( $option_value ); ?>"
837 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
838 /> <?php echo wp_kses_post( $description ); ?>
839 </td>
840 </tr>
841 <?php
842 break;
843
844 case 'select_font_awesome':
845 if ( isset( $value['value'] ) ) {
846 $option_value = $value['value'];
847 } else {
848 $option_value = uwp_get_option( 'uwp_verified_badge_icon', 'fas fa-check-circle' );
849 if ( empty( $option_value ) ) {
850 $option_value = 'fas fa-check-circle';
851 }
852 }
853
854 $uwp_fa_obj = new UWP_Font_Awesome_Settings();
855 $get_icons = $uwp_fa_obj->get_icons();
856 ?>
857 <tr valign="top" class="select_font_awesome
858 <?php
859 if ( isset( $value['advanced'] ) && $value['advanced'] ) {
860 echo 'uwp-advanced-setting'; }
861 ?>
862 ">
863 <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></th>
864 <td class="forminp">
865 <select
866 name="<?php echo esc_attr( $value['id'] ); ?>"
867 id="<?php echo esc_attr( $value['id'] ); ?>"
868 style="<?php echo esc_attr( $value['css'] ); ?>"
869 class="regular-text aui-fa-select2 <?php echo esc_attr( $value['class'] ); ?>"
870 <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
871 <?php echo ! empty( $value['sortable'] ) ? ' data-sortable="true"' : ''; ?>
872 <?php echo ! empty( $value['placeholder'] ) ? ' data-placeholder="' . esc_attr( $value['placeholder'] ) . '"' : ''; ?>
873 >
874
875 <?php
876 if ( ! empty( $get_icons ) && is_array( $get_icons ) ) {
877 foreach ( $get_icons as $key => $icon ) {
878 ?>
879 <option <?php selected( $option_value, $key ); ?> value="<?php echo esc_attr( $key ); ?>" data-fa-icon="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $key ); ?></option>
880 <?php
881 }
882 }
883 ?>
884 </select>
885 </td>
886 </tr>
887 <?php
888 break;
889
890 // Default: run an action
891 default:
892 do_action( 'uwp_admin_field_' . $value['type'], $value );
893 break;
894 }
895 }
896 }
897
898 /**
899 * Helper function to get the formatted description and tip HTML for a
900 * given form field. Plugins can call this when implementing their own custom
901 * settings types.
902 *
903 * @param array $value The form field value array
904 * @return array The description and tip as a 2 element array
905 */
906 public static function get_field_description( $value ) {
907 $description = '';
908 $tooltip_html = '';
909
910 if ( true === $value['desc_tip'] ) {
911 $tooltip_html = $value['desc'];
912 } elseif ( ! empty( $value['desc_tip'] ) ) {
913 $description = $value['desc'];
914 $tooltip_html = $value['desc_tip'];
915 } elseif ( ! empty( $value['desc'] ) ) {
916 $description = $value['desc'];
917 }
918
919 if ( ! empty( $value['docs'] ) ) {
920
921 $docs_link = "<a class='uwp-docs-link' href='" . esc_url( $value['docs'] ) . "' target='_blank'>" . __( 'Documentation', 'userswp' ) . ' <i class="fas fa-external-link-alt" aria-hidden="true" aria-hidden="true"></i></a>';
922
923 if ( in_array( $value['type'], array( 'checkbox' ) ) ) {
924 $description .= $docs_link;
925 } else {
926 $tooltip_html .= $docs_link;
927 }
928 }
929
930 if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
931 $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
932 } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
933 $description = wp_kses_post( $description );
934 } elseif ( $description ) {
935 $description = '<span class="description uwp-custom-desc">' . wp_kses_post( $description ) . '</span>';
936 }
937
938 if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ) ) ) {
939 $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
940 } elseif ( $tooltip_html ) {
941 $tooltip_html = uwp_help_tip( $tooltip_html );
942 }
943
944 return array(
945 'description' => $description,
946 'tooltip_html' => $tooltip_html,
947 );
948 }
949
950 public function uwp_get_settings() {
951
952 $settings = get_option( 'uwp_settings' );
953
954 if ( empty( $settings ) ) {
955
956 // Update old settings with new single option
957
958 $general_settings = is_array( get_option( 'uwp_settings_general' ) ) ? get_option( 'uwp_settings_general' ) : array();
959 $ext_settings = is_array( get_option( 'uwp_settings_extensions' ) ) ? get_option( 'uwp_settings_extensions' ) : array();
960
961 $settings = array_merge( $general_settings, $ext_settings );
962
963 update_option( 'uwp_settings', $settings );
964
965 }
966 return apply_filters( 'uwp_get_settings', $settings );
967 }
968
969 /**
970 * Save admin fields.
971 *
972 * Loops though the userswp options array and outputs each field.
973 *
974 * @param array $options Options array to output
975 * @param array $data Optional. Data to use for saving. Defaults to $_POST.
976 * @return bool
977 */
978 public static function save_fields( $options, $data = null ) {
979 if ( is_null( $data ) ) {
980 $data = $_POST;
981 }
982 if ( empty( $data ) ) {
983 return false;
984 }
985
986 // Options to update will be stored here and saved later.
987 $update_options = array();
988
989 // Loop options and get values to save.
990 foreach ( $options as $option ) {
991 if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
992 continue;
993 }
994
995 // Get posted value.
996 if ( strstr( $option['id'], '[' ) ) {
997 parse_str( $option['id'], $option_name_array );
998 $option_name = current( array_keys( $option_name_array ) );
999 $setting_name = key( $option_name_array[ $option_name ] );
1000 $raw_value = isset( $data[ $option_name ][ $setting_name ] ) ? wp_unslash( $data[ $option_name ][ $setting_name ] ) : null;
1001 } else {
1002 $option_name = $option['id'];
1003 $setting_name = '';
1004 $raw_value = isset( $data[ $option['id'] ] ) ? wp_unslash( $data[ $option['id'] ] ) : null;
1005 }
1006
1007 // Format the value based on option type.
1008 switch ( $option['type'] ) {
1009 case 'checkbox':
1010 $value = '1' === $raw_value ? 1 : 0;
1011 break;
1012 case 'textarea':
1013 case 'editor':
1014 $value = wp_kses_post( trim( $raw_value ) );
1015 break;
1016 case 'multiselect':
1017 case 'multi_select_countries':
1018 $value = array_filter( array_map( 'uwp_clean', (array) $raw_value ) );
1019 break;
1020 case 'multicheckbox':
1021 $value = array_map( 'uwp_clean', (array) $raw_value );
1022 break;
1023 case 'image_width':
1024 $value = array();
1025 if ( isset( $raw_value['width'] ) ) {
1026 $value['width'] = uwp_clean( $raw_value['width'] );
1027 $value['height'] = uwp_clean( $raw_value['height'] );
1028 $value['crop'] = isset( $raw_value['crop'] ) ? 1 : 0;
1029 } else {
1030 $value['width'] = $option['default']['width'];
1031 $value['height'] = $option['default']['height'];
1032 $value['crop'] = $option['default']['crop'];
1033 }
1034 break;
1035 case 'select':
1036 $allowed_values = empty( $option['options'] ) ? array() : array_keys( $option['options'] );
1037 if ( empty( $option['default'] ) && empty( $allowed_values ) ) {
1038 $value = null;
1039 break;
1040 }
1041 $default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] );
1042 $value = in_array( $raw_value, $allowed_values ) ? $raw_value : $default;
1043 break;
1044 default:
1045 $value = uwp_clean( $raw_value );
1046 break;
1047 }
1048
1049 /**
1050 * Sanitize the value of an option.
1051 */
1052 $value = apply_filters( 'uwp_admin_settings_sanitize_option', $value, $option, $raw_value );
1053
1054 /**
1055 * Sanitize the value of an option by option name.
1056 */
1057 $value = apply_filters( "uwp_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value );
1058
1059 if ( is_null( $value ) ) {
1060 continue;
1061 }
1062
1063 // Check if option is an array and handle that differently to single values.
1064 if ( $option_name && $setting_name ) {
1065 if ( ! isset( $update_options[ $option_name ] ) ) {
1066 $update_options[ $option_name ] = self::get_option( $option_name, array() );
1067 }
1068 if ( ! is_array( $update_options[ $option_name ] ) ) {
1069 $update_options[ $option_name ] = array();
1070 }
1071 $update_options[ $option_name ][ $setting_name ] = $value;
1072 } else {
1073 $update_options[ $option_name ] = $value;
1074 }
1075 }
1076
1077 // Save all options in our array.
1078 foreach ( $update_options as $name => $value ) {
1079 uwp_update_option( $name, $value );
1080 }
1081
1082 return true;
1083 }
1084
1085 /**
1086 * Get a setting from the settings API.
1087 *
1088 * @param mixed $option_name
1089 * @param mixed $default
1090 * @return string
1091 */
1092 public static function get_option( $option_name, $default = '' ) {
1093 return uwp_get_option( $option_name, $default );
1094 }
1095
1096 }
1097