PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.2.21
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.2.21
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 1.2.2.21, at admin/settings/class-settings.php

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