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

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