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

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