PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.74
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.74
1.2.74 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 All 174 releases
← All changes | admin/settings/class-settings.php +977 -689 1.0.101.2.74 View file →
@@ -20,789 +20,1077 @@
20 20 * @author GeoDirectory Team <info@wpgeodirectory.com>
21 21 */
22 22 class UsersWP_Admin_Settings {
23 23
24 - private $form_builder;
25 -
26 - public function __construct($form_builder) {
24 + /**
25 + * Setting pages.
26 + *
27 + * @var array
28 + */
29 + private static $settings = array();
27 30
28 - $this->form_builder = $form_builder;
29 -
30 - }
31 -
32 - public function init_settings() {
31 + /**
32 + * Error messages.
33 + *
34 + * @var array
35 + */
36 + private static $errors = array();
33 37
34 - global $uwp_options;
35 - $uwp_options = $this->uwp_get_settings();
38 + /**
39 + * Update messages.
40 + *
41 + * @var array
42 + */
43 + private static $messages = array();
36 44
37 - }
45 + public function __construct() {
38 46
39 - public function uwp_settings_page() {
47 + }
40 48
41 - $page = isset( $_GET['page'] ) ? $_GET['page'] : 'userswp';
49 + /**
50 + * Include the settings page classes.
51 + */
52 + public static function get_settings_pages() {
53 + if ( empty( self::$settings ) ) {
54 + $settings = array();
42 55
43 - $settings_array = uwp_get_settings_tabs();
44 - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_array[$page] ) ? $_GET['tab'] : 'main';
45 - ?>
46 - <div class="wrap">
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';
47 62
48 - <h1><?php echo get_admin_page_title(); ?></h1>
63 + self::$settings = apply_filters( 'uwp_get_settings_pages', $settings );
64 + }
49 65
50 - <div id="users-wp">
51 - <div class="item-list-tabs">
66 + return self::$settings;
67 + }
52 68
53 - <?php if (isset($settings_array[$page]) && count($settings_array[$page]) > 1) { ?>
69 + /**
70 + * Save the settings.
71 + */
72 + public static function save() {
73 + global $current_tab;
54 74
55 - <div class="wp-filter" style="margin-top: 0;margin-bottom: 5px">
56 - <ul class="filter-links">
57 - <?php
58 - foreach( $settings_array[$page] as $tab_id => $tab_name ) {
75 + if ( empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'userswp-settings' ) ) {
76 + die( esc_html__( 'Action failed. Please refresh the page and retry.', 'userswp' ) );
77 + }
59 78
60 - $tab_url = add_query_arg( array(
61 - 'settings-updated' => false,
62 - 'tab' => $tab_id,
63 - 'subtab' => false
64 - ) );
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' );
65 83
66 - $active = $active_tab == $tab_id ? ' current selected' : '';
67 - ?>
68 - <li id="uwp-<?php echo $tab_id; ?>-li">
69 - <a class="<?php echo $active; ?>" id="uwp-<?php echo $tab_id; ?>" href="<?php echo esc_url( $tab_url ); ?>"><?php echo esc_html( $tab_name ); ?></a>
70 - </li>
71 - <?php
72 - }
73 - ?>
74 - </ul>
75 - </div>
84 + self::add_message( __( 'Your settings have been saved.', 'userswp' ) );
76 85
77 - <?php } ?>
78 -
79 - <?php do_action($page.'_settings_'.$active_tab.'_tab_content_before'); ?>
86 + // Clear flush rules
87 + wp_schedule_single_event( time(), 'uwp_flush_rewrite_rules' );
80 88
81 - <div class="postbox">
82 - <div class="tab-content inside">
83 - <?php
84 - // {current page}_settings_{active tab}_tab_content
85 - // ex: uwp_settings_main_tab_content
86 - do_action($page.'_settings_'.$active_tab.'_tab_content', uwp_display_form());
87 - ?>
88 - </div>
89 - </div>
90 - </div>
89 + do_action( 'uwp_settings_saved' );
90 + }
91 91
92 - </div>
92 + /**
93 + * Add a message.
94 + * @param string $text
95 + */
96 + public static function add_message( $text ) {
97 + self::$messages[] = $text;
98 + }
93 99
94 - </div>
95 - <?php }
96 -
97 - public function get_general_content() {
100 + /**
101 + * Add an error.
102 + * @param string $text
103 + */
104 + public static function add_error( $text ) {
105 + self::$errors[] = $text;
106 + }
98 107
99 - $subtab = 'general';
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 + }
100 122
101 - if (isset($_GET['subtab'])) {
102 - $subtab = $_GET['subtab'];
103 - }
104 - ?>
105 - <div class="item-list-sub-tabs">
106 - <ul class="item-list-sub-tabs-ul">
107 - <li class="<?php if ($subtab == 'general') { echo "current selected"; } ?>">
108 - <a href="<?php echo add_query_arg(array('tab' => 'main', 'subtab' => 'general')); ?>"><?php echo __( 'General Settings', 'userswp' ); ?></a>
109 - </li>
110 - <li class="<?php if ($subtab == 'shortcodes') { echo "current selected"; } ?>">
111 - <a href="<?php echo add_query_arg(array('tab' => 'main', 'subtab' => 'shortcodes')); ?>"><?php echo __( 'Shortcodes', 'userswp' ); ?></a>
112 - </li>
113 - <li class="<?php if ($subtab == 'info') { echo "current selected"; } ?>">
114 - <a href="<?php echo add_query_arg(array('tab' => 'main', 'subtab' => 'info')); ?>"><?php echo __( 'Info', 'userswp' ); ?></a>
115 - </li>
116 - </ul>
117 - </div>
118 - <?php
119 - if ($subtab == 'general') {
120 - $this->get_general_general_content();
121 - } elseif ($subtab == 'shortcodes') {
122 - $this->get_general_shortcodes_content();
123 - } elseif ($subtab == 'info') {
124 - $this->get_general_info_content();
125 - }
126 - }
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;
127 130
128 - //main tabs
131 + do_action( 'uwp_settings_start' );
129 132
130 - public function uwp_get_pages_as_option($selected) {
131 - $page_options = uwp_get_pages();
132 - foreach ($page_options as $key => $page_title) {
133 - ?>
134 - <option value="<?php echo $key; ?>" <?php selected( $selected, $key ); ?>><?php echo $page_title; ?></option>
135 - <?php
136 - }
137 - }
138 -
139 - public function get_general_shortcodes_content() {
140 - ?>
141 - <table class="uwp-form-table">
133 + // Include settings pages
134 + self::get_settings_pages();
142 135
143 - <tr valign="top">
144 - <th scope="row"><?php echo __( 'User Profile Shortcode', 'userswp' ); ?></th>
145 - <td>
146 - <span class="short_code">[uwp_profile]</span>
147 - <span class="description"><?php echo __( 'This is the shortcode for the front end user\'s profile.', 'userswp' ); ?></span>
148 - </td>
149 - </tr>
136 + // Get current tab/section
137 + if ( $tab ) {
138 + $current_tab = sanitize_title( $tab );
150 139
151 - <tr valign="top">
152 - <th scope="row"><?php echo __( 'Register Form Shortcode', 'userswp' ); ?></th>
153 - <td>
154 - <span class="short_code">[uwp_register]</span>
155 - <span class="description"><?php echo __( 'This is the shortcode for the front end register form.', 'userswp' ); ?></span>
156 - </td>
157 - </tr>
140 + } else {
141 + $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
158 142
159 - <tr valign="top">
160 - <th scope="row"><?php echo __( 'Login Form Shortcode', 'userswp' ); ?></th>
161 - <td>
162 - <span class="short_code">[uwp_login]</span>
163 - <span class="description"><?php echo __( 'This is the shortcode for the front end login form.', 'userswp' ); ?></span>
164 - </td>
165 - </tr>
143 + }
144 + $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
166 145
167 - <tr valign="top">
168 - <th scope="row"><?php echo __( 'Account Form Shortcode', 'userswp' ); ?></th>
169 - <td>
170 - <span class="short_code">[uwp_account]</span>
171 - <span class="description"><?php echo __( 'This is the shortcode for the front end account form.', 'userswp' ); ?></span>
172 - </td>
173 - </tr>
146 + // Save settings if data has been posted
147 + if ( ! empty( $_POST ) ) {
148 + self::save();
149 + }
174 150
175 - <tr valign="top">
176 - <th scope="row"><?php echo __( 'Forgot Password Form Shortcode', 'userswp' ); ?></th>
177 - <td>
178 - <span class="short_code">[uwp_forgot]</span>
179 - <span class="description"><?php echo __( 'This is the shortcode for the front end forgot password form.', 'userswp' ); ?></span>
180 - </td>
181 - </tr>
151 + // Add any posted messages
152 + if ( ! empty( $_GET['uwp_error'] ) ) {
153 + self::add_error( stripslashes( $_GET['uwp_error'] ) );
154 + }
182 155
183 - <tr valign="top">
184 - <th scope="row"><?php echo __( 'Change Password Form Shortcode', 'userswp' ); ?></th>
185 - <td>
186 - <span class="short_code">[uwp_change]</span>
187 - <span class="description"><?php echo __( 'This is the shortcode for the front end change password form.', 'userswp' ); ?></span>
188 - </td>
189 - </tr>
156 + if ( ! empty( $_GET['uwp_message'] ) ) {
157 + self::add_message( stripslashes( $_GET['uwp_message'] ) );
158 + }
190 159
191 - <tr valign="top">
192 - <th scope="row"><?php echo __( 'Reset Password Form Shortcode', 'userswp' ); ?></th>
193 - <td>
194 - <span class="short_code">[uwp_reset]</span>
195 - <span class="description"><?php echo __( 'This is the shortcode for the front end reset password form.', 'userswp' ); ?></span>
196 - </td>
197 - </tr>
160 + // Get tabs for the settings page
161 + $tabs = apply_filters( 'uwp_settings_tabs_array', array() );
198 162
199 - <tr valign="top">
200 - <th scope="row"><?php echo __( 'Users List Shortcode', 'userswp' ); ?></th>
201 - <td>
202 - <span class="short_code">[uwp_users]</span>
203 - <span class="description"><?php echo __( 'This is the shortcode for the front end users list.', 'userswp' ); ?></span>
204 - </td>
205 - </tr>
163 + include USERSWP_PATH . '/admin/views/html-admin-settings.php';
164 + }
206 165
207 - </table>
208 - <?php
209 - }
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 + }
210 202
211 - //subtabs
212 - public function get_general_general_content() {
213 - echo uwp_display_form();
214 - }
203 + // Custom attribute handling
204 + $custom_attributes = array();
215 205
216 - public function display_form_title($title, $page, $active_tab) {
217 - if ($page == 'userswp' && $active_tab == 'main') {
218 - $title = __('General Options', 'userswp');
219 - }
220 - return $title;
221 - }
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 + }
222 211
223 - public function get_general_info_content() {
224 - ?>
225 - <h3><?php echo __( 'Welcome to UsersWP', 'userswp' ); ?></h3>
226 - <h4><?php echo __( 'Version 1.0.0', 'userswp' ); ?></h4>
212 + $wrap_class = $value['id'] . '-wrap';
227 213
228 - <h3><?php echo __( 'Flexible, Lightweight and Fast', 'userswp' ); ?></h3>
229 - <p><?php echo __( 'UsersWP allows you to add a customizable register and login form to your website.
230 - It also adds an extended profile page that override the default author page.
231 - UsersWP has been built to be lightweight and fast', 'userswp' ); ?></p>
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'] : '';
232 218
233 - <h3><?php echo __( 'Less options, more hooks', 'userswp' ); ?></h3>
234 - <p><?php echo __( 'We cut down the options to the bare minimum and you will not find any fancy
235 - styling options in this plugin as we believe they belong in your theme.
236 - This doesn\'t mean that you cannot customize the plugin behaviour.
237 - To do this we provided a long list of Filters and Actions for any developer
238 - to extend UsersWP to fit their needs.', 'userswp' ); ?></p>
219 + // Switch based on type
220 + switch ( $value['type'] ) {
239 221
240 - <h3><?php echo __( 'Override Templates', 'userswp' ); ?></h3>
241 - <p><?php echo __( 'If you need to change the look and feel of any UsersWP templates,
242 - simply create a folder named userswp inside your active child theme
243 - and copy the template you wish to modify in it. You can now modify the template.
244 - The plugin will use your modified version and you don\'t hve to worry about plugin or theme updates.
245 - <a href="https://userswp.io/docs/override-templates/">Click here for examples</a>', 'userswp' ); ?></p>
222 + // Section Titles
223 + case 'title':
224 + if ( ! empty( $value['title'] ) ) {
225 + echo '<h2 class="uwp-settings-title">';
226 + echo esc_html( $value['title'] );
227 + if ( ! empty( $value['title_html'] ) ) {
228 + echo $value['title_html'];} // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
229 + if ( isset( $value['desc_tip'] ) && $value['desc_tip'] ) {
230 + echo $tooltip_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
231 + }
232 + echo '</h2>';
233 + }
246 234
247 - <h3><?php echo __( 'Add-ons', 'userswp' ); ?></h3>
248 - <p><?php echo __( 'We have a long list of free and premium add-ons that will help you extend users management on your wesbsite.
249 - <a href="https://userswp.io/downloads/category/addons/">Click here for our official free and premium add-ons</a>', 'userswp' ); ?></p>
250 - <?php
251 - }
235 + if ( ! empty( $value['desc'] ) && ( ! isset( $value['desc_tip'] ) || ! $value['desc_tip'] ) ) {
236 + echo wpautop( wptexturize( wp_kses_post( $value['desc'] ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
237 + }
252 238
253 - public function get_form_builder_tabs() {
254 - $tab = 'account';
239 + echo '<table class="form-table">' . "\n\n";
240 + if ( ! empty( $value['id'] ) ) {
241 + do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) );
242 + }
243 + break;
255 244
256 - if (isset($_GET['tab'])) {
257 - $tab = $_GET['tab'];
258 - }
245 + // Section Ends
246 + case 'sectionend':
247 + if ( ! empty( $value['id'] ) ) {
248 + do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) . '_end' );
249 + }
250 + echo '</table>';
251 + if ( ! empty( $value['id'] ) ) {
252 + do_action( 'uwp_settings_' . sanitize_title( $value['id'] ) . '_after' );
253 + }
254 + break;
259 255
260 - ?>
256 + // Standard text inputs and subtypes like 'number'
257 + case 'text':
258 + case 'email':
259 + case 'number':
260 + case 'url':
261 + case 'password':
262 + if ( isset( $value['value'] ) ) {
263 + $option_value = $value['value'];
264 + } else {
265 + $option_value = self::get_option( $value['id'], $value['default'] );
266 + }
267 + ?><tr valign="top" class="
268 + <?php
269 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
270 + echo 'uwp-advanced-setting';}
271 + ?>
272 +">
273 + <th scope="row" class="titledesc">
274 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
275 + <?php echo wp_kses_post( $tooltip_html ); ?>
276 + </th>
277 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
278 + <input
279 + name="<?php echo esc_attr( $value['id'] ); ?>"
280 + id="<?php echo esc_attr( $value['id'] ); ?>"
281 + type="<?php echo esc_attr( $value['type'] ); ?>"
282 + style="<?php echo esc_attr( $value['css'] ); ?>"
283 + value="<?php echo esc_attr( $option_value ); ?>"
284 + class="regular-text <?php echo esc_attr( $value['class'] ); ?>"
285 + placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
286 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
287 + <?php
288 + if ( ! empty( $value['disabled'] ) && true == $value['disabled'] ) {
289 + echo 'disabled="disabled"'; }
290 + ?>
291 + <?php
292 + if ( ! empty( $value['readonly'] ) && true == $value['readonly'] ) {
293 + echo 'readonly="readonly"'; }
294 + ?>
295 + <?php
296 + if ( $value['type'] == 'number' ) {
297 + echo "lang='EN'";} // HTML5 number input can change number format depending on browser language, we don't want that
298 + ?>
299 + /> <?php echo wp_kses_post( $description ); ?>
300 + </td>
301 + </tr>
302 + <?php
303 + break;
261 304
262 - <div class="wp-filter" style="margin-top: 0;margin-bottom: 5px">
263 - <ul class="filter-links">
264 - <li id="uwp-form-builder-account-li">
265 - <a id="uwp-form-builder-account" class="<?php if ($tab == 'account') { echo "current selected"; } ?>" href="<?php echo add_query_arg(array('tab' => 'account')); ?>"><?php echo __( 'Account', 'userswp' ); ?></a>
266 - </li>
267 - <li id="uwp-form-builder-register-li">
268 - <a id="uwp-form-builder-register" class="<?php if ($tab == 'register') { echo "current selected"; } ?>" href="<?php echo add_query_arg(array('tab' => 'register')); ?>"><?php echo __( 'Register', 'userswp' ); ?></a>
269 - </li>
270 - <?php do_action('uwp_form_builder_tab_items', $tab); ?>
271 - </ul>
272 - </div>
273 - <?php
274 - }
305 + // Color picker.
306 + case 'color':
307 + if ( isset( $value['value'] ) ) {
308 + $option_value = $value['value'];
309 + } else {
310 + $option_value = self::get_option( $value['id'], $value['default'] );
311 + }
275 312
276 - public function get_form_builder_content() {
313 + ?>
314 + <tr valign="top" class="uwp-row-color-picker
315 + <?php
316 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
317 + echo 'uwp-advanced-setting';}
318 + ?>
319 + ">
320 + <th scope="row" class="titledesc">
321 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
322 + <?php echo wp_kses_post( $tooltip_html ); ?>
323 + </th>
324 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
325 + <input
326 + name="<?php echo esc_attr( $value['id'] ); ?>"
327 + id="<?php echo esc_attr( sanitize_key( $value['id'] ) ); ?>"
328 + type="text"
329 + dir="ltr"
330 + value="<?php echo esc_attr( $option_value ); ?>"
331 + class="uwp-color-picker"
332 + placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
333 + data-default-color="<?php echo esc_attr( $value['default'] ); ?>
334 + <?php echo esc_attr( implode( ' ', $custom_attributes ) ); ?> "/>&lrm; <?php echo wp_kses_post( $description ); ?>
335 + </td>
336 + </tr>
337 + <?php
338 + break;
277 339
278 - $tab = 'account';
340 + // Color picker.
341 + case 'image':
342 + // add required scripts
343 + add_thickbox();
344 + wp_enqueue_script( 'media-upload' );
345 + wp_enqueue_media();
279 346
280 - if (isset($_GET['tab'])) {
281 - $tab = $_GET['tab'];
282 - }
347 + if ( isset( $value['value'] ) ) {
348 + $option_value = $value['value'];
349 + } else {
350 + $option_value = self::get_option( $value['id'], $value['default'] );
351 + }
352 + $image_size = ! empty( $value['image_size'] ) ? $value['image_size'] : 'thumbnail';
283 353
284 - $tab_content = $this->form_builder->uwp_form_builder($tab);
285 - if ($tab == 'account') {
286 - ?>
287 - <h3 class=""><?php echo __( 'Manage Account Form Fields', 'userswp' ); ?></h3>
288 - <?php
289 - echo $tab_content;
290 - } elseif ($tab == 'register') {
291 - ?>
292 - <h3 class=""><?php echo __( 'Manage Register Form Fields', 'userswp' ); ?></h3>
293 - <?php
294 - echo $tab_content;
295 - }
296 -
297 - do_action('uwp_extra_form_builder_content', $tab, $tab_content);
298 - }
354 + if ( $option_value ) {
355 + $remove_class = '';
356 + if ( strpos( $option_value, 'dashicons-' ) === 0 ) {
357 + $show_img = '<div class="dashicons-before ' . esc_attr( $option_value ) . '"></div>';
358 + } else {
359 + $show_img = wp_get_attachment_image( $option_value, $image_size );
360 + }
361 + } else {
362 + $remove_class = 'hidden';
363 + $show_img = '<img src="' . admin_url( 'images/media-button-image.gif' ) . '" />';
364 + }
299 365
300 - public function generic_display_form() {
301 - echo uwp_display_form();
302 - }
366 + ?>
367 + <tr valign="top" class="
368 + <?php
369 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
370 + echo 'uwp-advanced-setting';}
371 + ?>
372 + ">
373 + <th scope="row" class="titledesc">
374 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
375 + <?php echo wp_kses_post( $tooltip_html ); ?>
376 + </th>
377 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
303 378
304 - public function get_recaptcha_content() {
305 - echo uwp_display_form();
306 - }
379 + <div class="uwp-upload-img" data-field="<?php echo esc_attr( $value['id'] ); ?>">
380 + <div class="uwp-upload-display uwp-img-size-<?php echo esc_attr( $image_size ); ?> thumbnail"><div class="centered"><?php echo $show_img; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div></div>
381 + <div class="uwp-upload-fields">
382 + <input type="hidden" id="<?php echo esc_attr( $value['id'] ); ?>" name="<?php echo esc_attr( $value['id'] ); ?>" value="<?php echo esc_attr( $option_value ); ?>" />
383 + <button type="button" class="uwp_upload_image_button button"><?php esc_html_e( 'Upload Image', 'userswp' ); ?></button>
384 + <button type="button" class="uwp_remove_image_button button <?php echo esc_attr( $remove_class ); ?>"><?php esc_html_e( 'Remove Image', 'userswp' ); ?></button>
385 + </div>
386 + </div>
387 + </td>
388 + </tr>
389 + <?php
390 + break;
307 391
308 - public function get_geodirectory_content() {
309 - echo uwp_display_form();
310 - }
392 + // Textarea
393 + case 'textarea':
394 + if ( isset( $value['value'] ) ) {
395 + $option_value = $value['value'];
396 + } else {
397 + $option_value = self::get_option( $value['id'], $value['default'] );
398 + }
311 399
312 - public function get_notifications_content() {
313 - ?>
314 - <h3 class=""><?php echo __( 'Email Notifications', 'userswp' ); ?></h3>
400 + $rows = ! empty( $value['size'] ) ? absint( $value['size'] ) : 5;
315 401
316 - <table class="uwp-form-table">
317 - <tbody>
318 - <tr valign="top">
319 - <th scope="row" class="titledesc"><?php echo __( 'List of usable shortcodes', 'userswp' ); ?></th>
320 - <td class="forminp">
321 - <span class="description">[#site_name_url#],[#site_name#],[#to_name#],[#from_name#],[#login_url#],[#user_name#],[#from_email#],[#user_login#],[#username#],[#current_date#],[#login_details#],[#reset_link#],[#activation_link#]</span>
322 - </td>
323 - </tr>
324 - </tbody>
325 - </table>
402 + ?>
403 + <tr valign="top" class="
404 + <?php
405 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
406 + echo 'uwp-advanced-setting';}
407 + ?>
408 + ">
409 + <th scope="row" class="titledesc">
410 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
411 + <?php echo wp_kses_post( $tooltip_html ); ?>
412 + </th>
413 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
414 + <?php echo wp_kses_post( $description ); ?>
326 415
327 - <?php
328 - echo uwp_display_form();
329 - }
416 + <textarea
417 + name="<?php echo esc_attr( $value['id'] ); ?>"
418 + id="<?php echo esc_attr( $value['id'] ); ?>"
419 + style="<?php echo esc_attr( $value['css'] ); ?>"
420 + class="large-text <?php echo esc_attr( $value['class'] ); ?>"
421 + placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
422 + rows="<?php echo esc_attr( $rows ); ?>"
423 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
424 + ><?php echo esc_textarea( stripslashes( $option_value ) ); ?></textarea>
425 + <?php if ( ! empty( $value['custom_desc'] ) ) { ?>
426 + <span class="uwp-custom-desc"><?php echo wp_kses_post( $value['custom_desc'] ); ?></span>
427 + <?php } ?>
428 + </td>
429 + </tr>
430 + <?php
431 + break;
432 + // Editor
433 + case 'editor':
434 + global $wp_version;
435 + if ( isset( $value['value'] ) ) {
436 + $option_value = $value['value'];
437 + } else {
438 + $option_value = self::get_option( $value['id'] );
439 + }
440 + if ( empty( $option_value ) && empty( $value['allow_blank'] ) ) {
441 + $option_value = isset( $value['default'] ) ? $value['default'] : '';
442 + }
330 443
331 - public function uwp_register_settings() {
444 + $rows = ! empty( $value['size'] ) ? absint( $value['size'] ) : 20;
445 + ?>
446 + <tr valign="top" class="<?php echo ( ! empty( $value['advanced'] ) ? 'uwp-advanced-setting' : '' ); ?>">
447 + <th scope="row" class="titledesc">
448 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
449 + <?php echo wp_kses_post( $tooltip_html ); ?>
450 + </th>
451 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
452 + <?php echo wp_kses_post( $description ); ?>
453 + <?php
454 + if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
455 + wp_editor(
456 + stripslashes( $option_value ),
457 + $value['id'],
458 + array(
459 + 'textarea_name' => esc_attr( $value['id'] ),
460 + 'textarea_rows' => $rows,
461 + 'media_buttons' => false,
462 + 'editor_class' => 'uwp-wp-editor',
463 + 'editor_height' => 16 * $rows,
464 + )
465 + );
466 + } else {
467 + ?>
468 + <textarea
469 + name="<?php echo esc_attr( $value['id'] ); ?>"
470 + id="<?php echo esc_attr( $value['id'] ); ?>"
471 + style="<?php echo esc_attr( $value['css'] ); ?>"
472 + class="large-text <?php echo esc_attr( $value['class'] ); ?>"
473 + placeholder="<?php echo esc_attr( $value['placeholder'] ); ?>"
474 + rows="<?php echo esc_attr( $rows ); ?>"
475 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
476 + ><?php echo esc_textarea( stripslashes( $option_value ) ); ?></textarea>
477 + <?php } ?>
478 + <?php if ( ! empty( $value['custom_desc'] ) ) { ?>
479 + <span class="uwp-custom-desc"><?php echo wp_kses_post( $value['custom_desc'] ); ?></span>
480 + <?php } ?>
481 + </td>
482 + </tr>
483 + <?php
484 + break;
332 485
333 - if ( false == get_option( 'uwp_settings' ) ) {
334 - add_option( 'uwp_settings' );
335 - }
486 + // Select boxes
487 + case 'select':
488 + case 'multiselect':
489 + if ( isset( $value['value'] ) ) {
490 + $option_value = $value['value'];
491 + } else {
492 + $option_value = self::get_option( $value['id'], $value['default'] );
493 + }
336 494
337 - $callback = new UsersWP_Callback();
495 + if ( ! empty( $value['type'] ) && 'multiselect' == $value['type'] && ! is_array( $option_value ) ) {
496 + $option_value = str_replace( ' ', '', $option_value );
497 + $option_value = explode( ',', $option_value );
498 + }
338 499
339 - foreach( $this->uwp_get_registered_settings() as $tab => $settings ) {
500 + ?>
501 + <tr valign="top" class="
502 + <?php
503 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
504 + echo 'uwp-advanced-setting';}
505 + ?>
506 + ">
507 + <th scope="row" class="titledesc">
508 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
509 + <?php echo wp_kses_post( $tooltip_html ); ?>
510 + </th>
511 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
512 + <select
513 + name="<?php echo esc_attr( $value['id'] ); ?><?php echo ( 'multiselect' === $value['type'] ) ? '[]' : ''; ?>"
514 + id="<?php echo esc_attr( $value['id'] ); ?>"
515 + style="<?php echo esc_attr( $value['css'] ); ?>"
516 + class="regular-text aui-select2 <?php echo esc_attr( $value['class'] ); ?>"
517 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
518 + <?php echo ( 'multiselect' == $value['type'] ) ? 'multiple="multiple"' : ''; ?>
519 + <?php echo ! empty( $value['sortable'] ) ? ' data-sortable="true"' : ''; ?>
520 + <?php echo ! empty( $value['placeholder'] ) ? ' data-placeholder="' . esc_attr( $value['placeholder'] ) . '"' : ''; ?>
521 + >
522 + <?php
523 + foreach ( $value['options'] as $key => $val ) {
524 + if ( stripos( strrev( $key ), strrev( 'optgroup-open' ) ) === 0 ) {
525 + echo '<optgroup label="' . esc_attr( $val ) . '">';
526 + } elseif ( stripos( strrev( $key ), strrev( 'optgroup-close' ) ) === 0 ) {
527 + echo '</optgroup>';
528 + } else {
529 + ?>
530 + <option value="<?php echo esc_attr( $key ); ?>"
531 + <?php
340 532
341 - foreach ( $settings as $key => $opt ) {
342 - add_settings_section(
343 - 'uwp_settings_' . $tab .'_'.$key,
344 - __return_null(),
345 - '__return_false',
346 - 'uwp_settings_' . $tab .'_'.$key
347 - );
533 + if ( is_array( $option_value ) ) {
534 + selected( in_array( $key, $option_value ), true );
535 + } else {
536 + selected( $option_value, $key );
537 + }
348 538
349 - foreach ($opt as $option) {
350 - $name = isset( $option['name'] ) ? $option['name'] : '';
539 + ?>
540 + ><?php echo esc_html( $val ); ?></option>
541 + <?php
542 + }
543 + }
544 + ?>
545 + </select> <?php echo wp_kses_post( $description ); ?>
546 + </td>
547 + </tr>
548 + <?php
549 + break;
351 550
352 - add_settings_field(
353 - 'uwp_settings[' . $option['id'] . ']',
354 - $name,
355 - method_exists($callback, 'uwp_' . $option['type'] . '_callback') ? array($callback, 'uwp_' . $option['type'] . '_callback') : array($callback, 'uwp_missing_callback'),
356 - 'uwp_settings_' . $tab .'_'.$key,
357 - 'uwp_settings_' . $tab .'_'.$key,
358 - array(
359 - 'section' => $tab,
360 - 'id' => isset( $option['id'] ) ? $option['id'] : null,
361 - 'class' => isset( $option['class'] ) ? $option['class'] : null,
362 - 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '',
363 - 'name' => isset( $option['name'] ) ? $option['name'] : null,
364 - 'size' => isset( $option['size'] ) ? $option['size'] : null,
365 - 'options' => isset( $option['options'] ) ? $option['options'] : '',
366 - 'std' => isset( $option['std'] ) ? $option['std'] : '',
367 - 'min' => isset( $option['min'] ) ? $option['min'] : null,
368 - 'max' => isset( $option['max'] ) ? $option['max'] : null,
369 - 'step' => isset( $option['step'] ) ? $option['step'] : null,
370 - 'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null,
371 - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
372 - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
373 - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false,
374 - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false,
375 - 'global' => isset( $setting['global'] ) ? $setting['global'] : true,
376 - 'multiple' => isset( $option['multiple'] ) ? $option['multiple'] : false,
377 - )
378 - );
379 - }
380 - }
551 + // Radio inputs
552 + case 'radio':
553 + if ( isset( $value['value'] ) ) {
554 + $option_value = $value['value'];
555 + } else {
556 + $option_value = self::get_option( $value['id'], $value['default'] );
557 + }
381 558
382 - }
559 + ?>
560 + <tr valign="top" class="<?php echo esc_attr( $wrap_class ); ?>
561 + <?php
562 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
563 + echo ' uwp-advanced-setting';}
564 + ?>
565 + ">
566 + <th scope="row" class="titledesc">
567 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
568 + <?php echo wp_kses_post( $tooltip_html ); ?>
569 + </th>
570 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
571 + <fieldset>
572 + <?php echo wp_kses_post( $description ); ?>
573 + <ul>
574 + <?php
575 + foreach ( $value['options'] as $key => $val ) {
576 + ?>
577 + <li>
578 + <label><input
579 + name="<?php echo esc_attr( $value['id'] ); ?>"
580 + value="<?php echo esc_attr( $key ); ?>"
581 + type="radio"
582 + style="<?php echo esc_attr( $value['css'] ); ?>"
583 + class="<?php echo esc_attr( $value['class'] ); ?>"
584 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
585 + <?php checked( $key, $option_value ); ?>
586 + /> <?php echo esc_html( $val ); ?></label>
587 + </li>
588 + <?php
589 + }
590 + ?>
591 + </ul>
592 + </fieldset>
593 + </td>
594 + </tr>
595 + <?php
596 + break;
383 597
384 - // Creates our settings in the options table
385 - register_setting( 'uwp_settings', 'uwp_settings', array($this, 'uwp_settings_sanitize') );
598 + // Checkbox input
599 + case 'checkbox':
600 + if ( isset( $value['value'] ) ) {
601 + $option_value = $value['value'];
602 + } else {
603 + $option_value = self::get_option( $value['id'], $value['default'] );
604 + }
605 + $visibility_class = array();
386 606
387 - }
607 + if ( ! isset( $value['hide_if_checked'] ) ) {
608 + $value['hide_if_checked'] = false;
609 + }
610 + if ( ! isset( $value['show_if_checked'] ) ) {
611 + $value['show_if_checked'] = false;
612 + }
613 + if ( 'yes' == $value['hide_if_checked'] || 'yes' == $value['show_if_checked'] ) {
614 + $visibility_class[] = 'hidden_option';
615 + }
616 + if ( 'option' == $value['hide_if_checked'] ) {
617 + $visibility_class[] = 'hide_options_if_checked';
618 + }
619 + if ( 'option' == $value['show_if_checked'] ) {
620 + $visibility_class[] = 'show_options_if_checked';
621 + }
388 622
389 - public function uwp_get_registered_settings() {
390 -
391 - $file_obj = new UsersWP_Files();
623 + if ( ! isset( $value['checkboxgroup'] ) || 'start' == $value['checkboxgroup'] ) {
624 + ?>
625 + <tr valign="top" class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?> <?php
626 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
627 + echo 'uwp-advanced-setting';}
628 + ?>
629 + " >
630 + <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?></th>
631 + <td class="forminp forminp-checkbox">
632 + <fieldset>
633 + <?php
634 + } else {
635 + ?>
636 + <fieldset class="<?php echo esc_attr( implode( ' ', $visibility_class ) ); ?>">
637 + <?php
638 + }
392 639
393 - /**
394 - * 'Whitelisted' uwp settings, filters are provided for each settings
395 - * section to allow extensions and other plugins to add their own settings
396 - */
397 - $uwp_settings = array(
398 - /** General Settings */
399 - 'userswp' => array(
400 - 'main' => apply_filters( 'uwp_settings_general_main',
401 - array(
402 - 'profile_page' => array(
403 - 'id' => 'profile_page',
404 - 'name' => __( 'User Profile Page', 'userswp' ),
405 - 'desc' => __( 'This is the front end user\'s profile page. This page automatically overrides the default WordPress author page.', 'userswp' ),
406 - 'type' => 'select',
407 - 'options' => uwp_get_pages(),
408 - 'chosen' => true,
409 - 'placeholder' => __( 'Select a page', 'userswp' ),
410 - 'class' => 'uwp_label_block',
411 - ),
412 - 'register_page' => array(
413 - 'id' => 'register_page',
414 - 'name' => __( 'Register Page', 'userswp' ),
415 - 'desc' => __( 'This is the front end register page. This is where users create their account.', 'userswp' ),
416 - 'type' => 'select',
417 - 'options' => uwp_get_pages(),
418 - 'chosen' => true,
419 - 'placeholder' => __( 'Select a page', 'userswp' ),
420 - 'class' => 'uwp_label_block',
421 - ),
422 - 'login_page' => array(
423 - 'id' => 'login_page',
424 - 'name' => __( 'Login Page', 'userswp' ),
425 - 'desc' => __( 'This is the front end login page. This is where users will login after creating their account.', 'userswp' ),
426 - 'type' => 'select',
427 - 'options' => uwp_get_pages(),
428 - 'chosen' => true,
429 - 'placeholder' => __( 'Select a page', 'userswp' ),
430 - 'class' => 'uwp_label_block',
431 - ),
432 - 'account_page' => array(
433 - 'id' => 'account_page',
434 - 'name' => __( 'Account Page', 'userswp' ),
435 - 'desc' => __( 'This is the front end account page. This is where users can edit their account.', 'userswp' ),
436 - 'type' => 'select',
437 - 'options' => uwp_get_pages(),
438 - 'chosen' => true,
439 - 'placeholder' => __( 'Select a page', 'userswp' ),
440 - 'class' => 'uwp_label_block',
441 - ),
442 - 'change_page' => array(
443 - 'id' => 'change_page',
444 - 'name' => __( 'Change Password Page', 'userswp' ),
445 - 'desc' => __( 'This is the front end Change Password page.', 'userswp' ),
446 - 'type' => 'select',
447 - 'options' => uwp_get_pages(),
448 - 'chosen' => true,
449 - 'placeholder' => __( 'Select a page', 'userswp' ),
450 - 'class' => 'uwp_label_block',
451 - ),
452 - 'forgot_page' => array(
453 - 'id' => 'forgot_page',
454 - 'name' => __( 'Forgot Password Page', 'userswp' ),
455 - 'desc' => __( 'This is the front end Forgot Password page. This is the page where users are sent to reset their password when they lose it.', 'userswp' ),
456 - 'type' => 'select',
457 - 'options' => uwp_get_pages(),
458 - 'chosen' => true,
459 - 'placeholder' => __( 'Select a page', 'userswp' ),
460 - 'class' => 'uwp_label_block',
461 - ),
462 - 'reset_page' => array(
463 - 'id' => 'reset_page',
464 - 'name' => __( 'Reset Password Page', 'userswp' ),
465 - 'desc' => __( 'This is the front end Reset Password page. This is the page where users can reset their password when they lose it.', 'userswp' ),
466 - 'type' => 'select',
467 - 'options' => uwp_get_pages(),
468 - 'chosen' => true,
469 - 'placeholder' => __( 'Select a page', 'userswp' ),
470 - 'class' => 'uwp_label_block',
471 - ),
472 - 'users_page' => array(
473 - 'id' => 'users_page',
474 - 'name' => __( 'Users List Page', 'userswp' ),
475 - 'desc' => __( 'This is the front end Users List page. This is the page where all registered users of the websites are listed.', 'userswp' ),
476 - 'type' => 'select',
477 - 'options' => uwp_get_pages(),
478 - 'chosen' => true,
479 - 'placeholder' => __( 'Select a page', 'userswp' ),
480 - 'class' => 'uwp_label_block',
481 - ),
482 - 'profile_no_of_items' => array(
483 - 'id' => 'profile_no_of_items',
484 - 'name' => __( 'Number of Items', 'userswp' ),
485 - 'type' => 'text',
486 - 'std' => '',
487 - 'desc' => __( 'Enter number of items to display in profile tabs.', 'userswp' ),
488 - ),
489 - )
490 - ),
491 - 'register' => apply_filters( 'uwp_settings_general_register', uwp_settings_general_register_fields()),
492 - 'login' => apply_filters( 'uwp_settings_general_login', uwp_settings_general_loginout_fields()),
493 - 'profile' => apply_filters( 'uwp_settings_general_profile',
494 - array(
495 - 'enable_profile_header' => array(
496 - 'id' => 'enable_profile_header',
497 - 'name' => __( 'Display Header in Profile', 'userswp' ),
498 - 'desc' => '',
499 - 'type' => 'checkbox',
500 - 'std' => '1',
501 - 'class' => 'uwp_label_inline',
502 - ),
503 - 'profile_avatar_size' => array(
504 - 'id' => 'profile_avatar_size',
505 - 'name' => __( 'Profile Avatar max file size', 'userswp' ),
506 - 'desc' => __( 'Enter Profile Avatar max file size in Kb. e.g. 512 for 512 kb, 1024 for 1 Mb, 2048 for 2 Mb etc. If empty WordPress default (<b>'.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).'</b>) will be used.', 'userswp' ),
507 - 'type' => 'number',
508 - 'std' => '',
509 - 'size' => 'regular',
510 - 'placeholder' => __( 'Enter Profile Avatar max file size.', 'userswp' ),
511 - ),
512 - 'profile_banner_size' => array(
513 - 'id' => 'profile_banner_size',
514 - 'name' => __( 'Profile Banner max file size', 'userswp' ),
515 - 'desc' => __( 'Enter Profile Banner max file size in Kb. e.g. 512 for 512 kb, 1024 for 1 Mb, 2048 for 2 Mb etc. If empty WordPress default (<b>'.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).'</b>) will be used.', 'userswp' ),
516 - 'type' => 'number',
517 - 'std' => '',
518 - 'size' => 'regular',
519 - 'placeholder' => __( 'Enter Profile Banner max file size.', 'userswp' ),
520 - ),
521 - 'profile_banner_width' => array(
522 - 'id' => 'profile_banner_width',
523 - 'name' => __( 'Profile banner width', 'userswp' ),
524 - 'desc' => '',
525 - 'type' => 'number',
526 - 'std' => '1000',
527 - 'size' => 'regular',
528 - 'placeholder' => __( 'Enter Profile banner width in Pixels', 'userswp' ),
529 - ),
530 - 'enable_profile_body' => array(
531 - 'id' => 'enable_profile_body',
532 - 'name' => __( 'Display Body in Profile', 'userswp' ),
533 - 'desc' => '',
534 - 'type' => 'checkbox',
535 - 'std' => '1',
536 - 'class' => 'uwp_label_inline',
537 - ),
538 - 'enable_profile_tabs' => array(
539 - 'id' => 'enable_profile_tabs',
540 - 'name' => __( 'Choose the tabs to display in Profile', 'userswp' ),
541 - 'desc' => __( 'Choose the tabs to display in UsersWP Profile', 'userswp' ),
542 - 'multiple' => true,
543 - 'chosen' => true,
544 - 'type' => 'select_order',
545 - 'options' => $this->uwp_available_tab_items(),
546 - 'placeholder' => __( 'Select Tabs', 'userswp' )
547 - ),
548 - )
549 - ),
550 - 'users' => apply_filters( 'uwp_settings_general_profile',
551 - array(
552 - 'users_default_layout' => array(
553 - 'id' => 'users_default_layout',
554 - 'name' => __( 'Users default layout', 'userswp' ),
555 - 'desc' => __( 'Choose the default layout for Users Page - Users List', 'userswp' ),
556 - 'type' => 'select',
557 - 'options' => $this->uwp_available_users_layout(),
558 - 'placeholder' => __( 'Select Layout', 'userswp' )
559 - ),
560 - )
561 - ),
562 - 'change' => apply_filters( 'uwp_settings_general_change',
563 - array(
564 - 'change_enable_old_password' => array(
565 - 'id' => 'change_enable_old_password',
566 - 'name' => __( 'Enabled Old Password?', 'userswp' ),
567 - 'desc' => 'This option adds an extra layer of security. User need to enter their old password before changing the password.',
568 - 'type' => 'checkbox',
569 - 'std' => '1',
570 - 'class' => 'uwp_label_inline',
571 - ),
572 - )
573 - ),
574 - 'uninstall' => apply_filters( 'uwp_settings_general_uninstall',
575 - array(
576 - 'uninstall_erase_data' => array(
577 - 'id' => 'uninstall_erase_data',
578 - 'name' => __( 'Remove Data on Uninstall?', 'userswp' ),
579 - 'desc' => '',
580 - 'type' => 'checkbox',
581 - 'std' => '1',
582 - 'class' => 'uwp_label_inline',
583 - ),
584 - )
585 - ),
586 - ),
587 - 'uwp_notifications' => array(
588 - 'main' => apply_filters( 'uwp_settings_notifications_main',
589 - array(
590 - 'registration_activate_email_subject' => array(
591 - 'id' => 'registration_activate_email_subject',
592 - 'name' => __( 'Registration activate email', 'userswp' ),
593 - 'desc' => "",
594 - 'type' => 'text',
595 - 'size' => 'regular',
596 - 'placeholder' => __( 'Enter Registration activate email Subject', 'userswp' )
597 - ),
598 - 'registration_activate_email_content' => array(
599 - 'id' => 'registration_activate_email_content',
600 - 'name' => "",
601 - 'desc' => "",
602 - 'type' => 'textarea',
603 - 'placeholder' => __( 'Enter Registration activate email Content', 'userswp' )
604 - ),
605 - 'registration_success_email_subject' => array(
606 - 'id' => 'registration_success_email_subject',
607 - 'name' => __( 'Registration success email', 'userswp' ),
608 - 'desc' => "",
609 - 'type' => 'text',
610 - 'size' => 'regular',
611 - 'placeholder' => __( 'Enter Registration success email Subject', 'userswp' )
612 - ),
613 - 'registration_success_email_content' => array(
614 - 'id' => 'registration_success_email_content',
615 - 'name' => "",
616 - 'desc' => "",
617 - 'type' => 'textarea',
618 - 'placeholder' => __( 'Enter Registration success email Content', 'userswp' )
619 - ),
620 - 'forgot_password_email_subject' => array(
621 - 'id' => 'forgot_password_email_subject',
622 - 'name' => __( 'Forgot password email', 'userswp' ),
623 - 'desc' => "",
624 - 'type' => 'text',
625 - 'size' => 'regular',
626 - 'placeholder' => __( 'Enter forgot password email Subject', 'userswp' )
627 - ),
628 - 'forgot_password_email_content' => array(
629 - 'id' => 'forgot_password_email_content',
630 - 'name' => "",
631 - 'desc' => "",
632 - 'type' => 'textarea',
633 - 'placeholder' => __( 'Enter forgot password email Content', 'userswp' )
634 - ),
635 - 'reset_password_email_subject' => array(
636 - 'id' => 'reset_password_email_subject',
637 - 'name' => __( 'Reset password email', 'userswp' ),
638 - 'desc' => "",
639 - 'type' => 'text',
640 - 'size' => 'regular',
641 - 'placeholder' => __( 'Enter reset password email Subject', 'userswp' )
642 - ),
643 - 'reset_password_email_content' => array(
644 - 'id' => 'reset_password_email_content',
645 - 'name' => "",
646 - 'desc' => "",
647 - 'type' => 'textarea',
648 - 'placeholder' => __( 'Enter reset password email Content', 'userswp' )
649 - ),
650 - 'enable_account_update_notification' => array(
651 - 'id' => 'enable_account_update_notification',
652 - 'name' => __( 'Account update email', 'userswp' ),
653 - 'desc' => 'Enable account update notification',
654 - 'type' => 'checkbox',
655 - 'std' => '0',
656 - 'class' => 'uwp_label_inline',
657 - ),
658 - 'account_update_email_subject' => array(
659 - 'id' => 'account_update_email_subject',
660 - 'name' => "",
661 - 'desc' => "",
662 - 'type' => 'text',
663 - 'size' => 'regular',
664 - 'placeholder' => __( 'Enter account update email Subject', 'userswp' )
665 - ),
666 - 'account_update_email_content' => array(
667 - 'id' => 'account_update_email_content',
668 - 'name' => "",
669 - 'desc' => "",
670 - 'type' => 'textarea',
671 - 'placeholder' => __( 'Enter account update email Content', 'userswp' )
672 - ),
673 - )
674 - ),
675 - 'admin' => apply_filters( 'uwp_settings_notifications_admin',
676 - array(
677 - 'registration_success_email_subject_admin' => array(
678 - 'id' => 'registration_success_email_subject_admin',
679 - 'name' => __( 'New account registration', 'userswp' ),
680 - 'desc' => "",
681 - 'type' => 'text',
682 - 'std' => __( 'New account registration', 'userswp' ),
683 - 'size' => 'regular',
684 - ),
685 - 'registration_success_email_content_admin' => array(
686 - 'id' => 'registration_success_email_content_admin',
687 - 'name' => "",
688 - 'desc' => "",
689 - 'type' => 'textarea',
690 - 'std' => __("A user has been registered recently on your website. [#extras#]", "userswp"),
691 - ),
692 - )
693 - ),
694 - ),
695 - );
640 + if ( ! empty( $value['title'] ) ) {
641 + ?>
642 + <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
696 643
697 - $uwp_settings = apply_filters( 'uwp_registered_settings', $uwp_settings );
644 + <?php
645 + }
698 646
699 - return $uwp_settings;
700 - }
647 + ?>
648 + <label for="<?php echo esc_attr( $value['id'] ); ?>">
649 + <input
650 + name="<?php echo esc_attr( $value['id'] ); ?>"
651 + id="<?php echo esc_attr( $value['id'] ); ?>"
652 + type="checkbox"
653 + class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
654 + value="1"
655 + <?php checked( $option_value, '1' ); ?>
656 + <?php checked( $option_value, 'yes' ); ?>
657 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
658 + /> <?php echo wp_kses_post( $description ); ?>
659 + </label> <?php echo wp_kses_post( $tooltip_html ); ?>
660 + <?php
701 661
702 - public function uwp_get_settings() {
662 + if ( ! isset( $value['checkboxgroup'] ) || 'end' == $value['checkboxgroup'] ) {
663 + ?>
664 + </fieldset>
665 + </td>
666 + </tr>
667 + <?php
668 + } else {
669 + ?>
670 + </fieldset>
671 + <?php
672 + }
673 + break;
703 674
704 - $settings = get_option( 'uwp_settings' );
675 + // Checkbox input
676 + case 'multicheckbox':
677 + if ( isset( $value['value'] ) ) {
678 + $option_value = $value['value'];
679 + } else {
680 + $option_value = self::get_option( $value['id'], $value['default'] );
681 + }
705 682
706 - if( empty( $settings ) ) {
683 + ?>
684 + <tr valign="top" class="
685 + <?php
686 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
687 + echo 'uwp-advanced-setting';}
688 + ?>
689 + " >
690 + <th scope="row" class="titledesc">
691 + <label><?php echo esc_html( $value['title'] ); ?></label>
692 + <?php echo wp_kses_post( $tooltip_html ); ?>
693 + </th>
694 + <td class="forminp forminp-checkbox">
695 + <div class="uwp-mcheck-rows uwp-mcheck-<?php echo sanitize_key( $value['id'] ); ?>">
696 + <?php
697 + foreach ( $value['options'] as $key => $title ) {
698 + if ( ! empty( $option_value ) && is_array( $option_value ) && in_array( $key, $option_value ) ) {
699 + $checked = true;
700 + } else {
701 + $checked = false;
702 + }
703 + ?>
704 + <div class="uwp-mcheck-row">
705 + <input
706 + name="<?php echo esc_attr( $value['id'] ); ?>[<?php echo esc_attr( $key ); ?>]"
707 + id="<?php echo esc_attr( $value['id'] . '-' . sanitize_key( $key ) ); ?>"
708 + type="checkbox"
709 + class="<?php echo esc_attr( isset( $value['class'] ) ? $value['class'] : '' ); ?>"
710 + value="<?php echo esc_attr( $key ); ?>"
711 + <?php checked( $checked, true ); ?>
712 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
713 + /> <label for="<?php echo esc_attr( $value['id'] . '-' . sanitize_key( $key ) ); ?>"><?php echo esc_html( $title ); ?></label></div>
714 + <?php } ?>
715 + <?php echo wp_kses_post( $description ); ?>
716 + </div>
717 + </td>
718 + </tr>
719 + <?php
720 + break;
707 721
708 - // Update old settings with new single option
722 + // Single page selects
723 + case 'single_select_page':
724 + if ( isset( $value['value'] ) ) {
725 + $option_value = $value['value'];
726 + } else {
727 + $option_value = self::get_option( $value['id'] );
728 + }
709 729
710 - $general_settings = is_array( get_option( 'uwp_settings_general' ) ) ? get_option( 'uwp_settings_general' ) : array();
711 - $ext_settings = is_array( get_option( 'uwp_settings_extensions' ) ) ? get_option( 'uwp_settings_extensions' ) : array();
730 + $args = array(
731 + 'name' => $value['id'],
732 + 'id' => $value['id'],
733 + 'sort_column' => 'menu_order',
734 + 'sort_order' => 'ASC',
735 + 'show_option_none' => ' ',
736 + 'class' => ' regular-text aui-select2 ' . $value['class'],
737 + 'echo' => false,
738 + 'selected' => (int) $option_value > 0 ? (int) $option_value : -1,
739 + );
712 740
713 - $settings = array_merge( $general_settings, $ext_settings );
741 + if ( isset( $value['args'] ) ) {
742 + $args = wp_parse_args( $value['args'], $args );
743 + }
714 744
715 - update_option( 'uwp_settings', $settings );
745 + ?>
746 + <tr valign="top" class="single_select_page
747 + <?php
748 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
749 + echo 'uwp-advanced-setting';}
750 + ?>
751 + ">
752 + <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></th>
753 + <td class="forminp">
754 + <?php echo str_replace( ' id=', " data-placeholder='" . esc_attr__( 'Select a page&hellip;', 'userswp' ) . "' style='" . $value['css'] . "' class='" . $value['class'] . "' id=", wp_dropdown_pages( $args ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> <?php echo wp_kses_post( $description ); ?>
716 755
717 - }
718 - return apply_filters( 'uwp_get_settings', $settings );
719 - }
756 + <?php if ( isset( $args['selected'] ) && $args['selected'] > 0 ) { ?>
757 + <a href="<?php echo esc_url( get_edit_post_link( $args['selected'] ) ); ?>" class="button uwp-page-setting-edit"><?php esc_html_e( 'Edit Page', 'userswp' ); ?></a>
720 758
721 - public function uwp_settings_sanitize( $input = array() ) {
722 - global $uwp_options;
759 + <?php if ( empty( $value['is_template_page'] ) ) { ?>
760 + <a href="<?php echo esc_url( get_permalink( $args['selected'] ) ); ?>" class="button uwp-page-setting-view"><?php esc_html_e( 'View Page', 'userswp' ); ?></a>
761 + <?php
762 + }
763 + }
723 764
724 - if ( empty( $_POST['_wp_http_referer'] ) ) {
725 - return $input;
726 - }
765 + ?>
727 766
728 - $parsed_url = wp_parse_url($_POST['_wp_http_referer']);
767 + </td>
768 + </tr>
769 + <?php
770 + break;
729 771
730 - if (!isset($parsed_url['query'])) {
731 - return $input;
732 - }
733 - parse_str( $parsed_url['query'], $referrer );
772 + case 'import_export_users':
773 + ?>
734 774
735 - $settings = $this->uwp_get_registered_settings();
775 + <tr valign="top" class="
776 + <?php
777 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
778 + echo 'uwp-advanced-setting';}
779 + ?>
780 + ">
781 + <td class="forminp" colspan="2">
782 + <?php
783 + /**
784 + * Contains template for import/export users.
785 + *
786 + */
787 + include_once USERSWP_PATH . '/admin/views/html-admin-settings-import-export-users.php';
788 + ?>
789 + </td>
790 + </tr>
736 791
737 - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'main';
738 - $page = isset( $referrer['page'] ) ? $referrer['page'] : 'userswp';
792 + <?php
739 793
740 - $input = $input ? $input : array();
741 - $input = apply_filters( 'uwp_settings_'.$page.'_' . $tab . '_sanitize', $input );
794 + break;
742 795
743 - // Loop through each setting being saved and pass it through a sanitization filter
744 - foreach ( $input as $key => $value ) {
745 - // Get the setting type (checkbox, select, etc)
746 - $type = isset( $settings[$page][$tab][$key]['type'] ) ? $settings[$page][$tab][$key]['type'] : false;
796 + case 'import_export_settings':
797 + ?>
747 798
748 - if ( $type ) {
749 - // Field type specific filter
750 - $input[$key] = apply_filters( 'uwp_settings_sanitize_' . $type, $value, $key );
751 - }
799 + <tr valign="top" class="
800 + <?php
801 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
802 + echo 'uwp-advanced-setting';}
803 + ?>
804 + ">
805 + <td class="forminp" colspan="2">
806 + <?php
807 + /**
808 + * Contains template for import/export settings.
809 + *
810 + */
811 + include_once USERSWP_PATH . '/admin/views/html-admin-settings-import-export-settings.php';
812 + ?>
813 + </td>
814 + </tr>
752 815
753 - // General filter
754 - $input[$key] = apply_filters( 'uwp_settings_sanitize', $input[$key], $key );
755 - }
816 + <?php
756 817
757 - // Loop through the whitelist and unset any that are empty for the tab being saved
758 - if ( ! empty( $settings[$page][$tab] ) ) {
759 - foreach ( $settings[$page][$tab] as $key => $value ) {
818 + break;
760 819
761 - // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
762 - if ( is_numeric( $key ) ) {
763 - $key = $value['id'];
764 - }
820 + case 'hidden':
821 + if ( isset( $value['value'] ) ) {
822 + $option_value = $value['value'];
823 + } else {
824 + $option_value = self::get_option( $value['id'], $value['default'] );
825 + }
826 + ?>
827 + <tr valign="top" style="display:none!important">
828 + <th scope="row" class="titledesc">
829 + <label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
830 + </th>
831 + <td class="forminp forminp-<?php echo esc_attr( sanitize_title( $value['type'] ) ); ?>">
832 + <input
833 + name="<?php echo esc_attr( $value['id'] ); ?>"
834 + id="<?php echo esc_attr( $value['id'] ); ?>"
835 + type="hidden"
836 + value="<?php echo esc_attr( $option_value ); ?>"
837 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
838 + /> <?php echo wp_kses_post( $description ); ?>
839 + </td>
840 + </tr>
841 + <?php
842 + break;
765 843
766 - if ( empty( $input[$key] ) ) {
767 - unset( $uwp_options[$key] );
768 - }
844 + case 'select_font_awesome':
845 + if ( isset( $value['value'] ) ) {
846 + $option_value = $value['value'];
847 + } else {
848 + $option_value = uwp_get_option( 'uwp_verified_badge_icon', 'fas fa-check-circle' );
849 + if ( empty( $option_value ) ) {
850 + $option_value = 'fas fa-check-circle';
851 + }
852 + }
769 853
770 - }
771 - }
854 + $uwp_fa_obj = new UWP_Font_Awesome_Settings();
855 + $get_icons = $uwp_fa_obj->get_icons();
856 + ?>
857 + <tr valign="top" class="select_font_awesome
858 + <?php
859 + if ( isset( $value['advanced'] ) && $value['advanced'] ) {
860 + echo 'uwp-advanced-setting'; }
861 + ?>
862 + ">
863 + <th scope="row" class="titledesc"><?php echo esc_html( $value['title'] ); ?> <?php echo wp_kses_post( $tooltip_html ); ?></th>
864 + <td class="forminp">
865 + <select
866 + name="<?php echo esc_attr( $value['id'] ); ?>"
867 + id="<?php echo esc_attr( $value['id'] ); ?>"
868 + style="<?php echo esc_attr( $value['css'] ); ?>"
869 + class="regular-text aui-fa-select2 <?php echo esc_attr( $value['class'] ); ?>"
870 + <?php echo implode( ' ', $custom_attributes ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
871 + <?php echo ! empty( $value['sortable'] ) ? ' data-sortable="true"' : ''; ?>
872 + <?php echo ! empty( $value['placeholder'] ) ? ' data-placeholder="' . esc_attr( $value['placeholder'] ) . '"' : ''; ?>
873 + >
772 874
773 - // Merge our new settings with the existing
774 - $output = array_merge( $uwp_options, $input );
875 + <?php
876 + if ( ! empty( $get_icons ) && is_array( $get_icons ) ) {
877 + foreach ( $get_icons as $key => $icon ) {
878 + ?>
879 + <option <?php selected( $option_value, $key ); ?> value="<?php echo esc_attr( $key ); ?>" data-fa-icon="<?php echo esc_attr( $key ); ?>"><?php echo esc_attr( $key ); ?></option>
880 + <?php
881 + }
882 + }
883 + ?>
884 + </select>
885 + </td>
886 + </tr>
887 + <?php
888 + break;
775 889
776 - flush_rewrite_rules();
777 - add_settings_error( 'uwp-notices', '', __( 'Settings updated.', 'userswp' ), 'updated' );
890 + // Default: run an action
891 + default:
892 + do_action( 'uwp_admin_field_' . $value['type'], $value );
893 + break;
894 + }
895 + }
896 + }
778 897
779 - return $output;
780 - }
898 + /**
899 + * Helper function to get the formatted description and tip HTML for a
900 + * given form field. Plugins can call this when implementing their own custom
901 + * settings types.
902 + *
903 + * @param array $value The form field value array
904 + * @return array The description and tip as a 2 element array
905 + */
906 + public static function get_field_description( $value ) {
907 + $description = '';
908 + $tooltip_html = '';
781 909
782 - public function uwp_available_tab_items() {
783 - $tabs_arr = array(
784 - 'more_info' => __( 'More Info', 'userswp' ),
785 - 'posts' => __( 'Posts', 'userswp' ),
786 - 'comments' => __( 'Comments', 'userswp' ),
787 - );
910 + if ( true === $value['desc_tip'] ) {
911 + $tooltip_html = $value['desc'];
912 + } elseif ( ! empty( $value['desc_tip'] ) ) {
913 + $description = $value['desc'];
914 + $tooltip_html = $value['desc_tip'];
915 + } elseif ( ! empty( $value['desc'] ) ) {
916 + $description = $value['desc'];
917 + }
788 918
789 - $tabs_arr = apply_filters('uwp_available_tab_items', $tabs_arr);
919 + if ( ! empty( $value['docs'] ) ) {
790 920
791 - return $tabs_arr;
792 - }
921 + $docs_link = "<a class='uwp-docs-link' href='" . esc_url( $value['docs'] ) . "' target='_blank'>" . __( 'Documentation', 'userswp' ) . ' <i class="fas fa-external-link-alt" aria-hidden="true" aria-hidden="true"></i></a>';
793 922
794 - public function uwp_available_users_layout() {
795 - $tabs_arr = array(
796 - 'list' => __( 'List View', 'userswp' ),
797 - '2col' => __( 'Grid View - 2 Column', 'userswp' ),
798 - '3col' => __( 'Grid View - 3 Column', 'userswp' ),
799 - '4col' => __( 'Grid View - 4 Column', 'userswp' ),
800 - '5col' => __( 'Grid View - 5 Column', 'userswp' ),
801 - );
923 + if ( in_array( $value['type'], array( 'checkbox' ) ) ) {
924 + $description .= $docs_link;
925 + } else {
926 + $tooltip_html .= $docs_link;
927 + }
928 + }
802 929
803 - $tabs_arr = apply_filters('uwp_available_users_layout', $tabs_arr);
930 + if ( $description && in_array( $value['type'], array( 'textarea', 'radio' ) ) ) {
931 + $description = '<p style="margin-top:0">' . wp_kses_post( $description ) . '</p>';
932 + } elseif ( $description && in_array( $value['type'], array( 'checkbox' ) ) ) {
933 + $description = wp_kses_post( $description );
934 + } elseif ( $description ) {
935 + $description = '<span class="description uwp-custom-desc">' . wp_kses_post( $description ) . '</span>';
936 + }
804 937
805 - return $tabs_arr;
806 - }
938 + if ( $tooltip_html && in_array( $value['type'], array( 'checkbox' ) ) ) {
939 + $tooltip_html = '<p class="description">' . $tooltip_html . '</p>';
940 + } elseif ( $tooltip_html ) {
941 + $tooltip_html = uwp_help_tip( $tooltip_html );
942 + }
807 943
808 -}
944 + return array(
945 + 'description' => $description,
946 + 'tooltip_html' => $tooltip_html,
947 + );
948 + }
949 +
950 + public function uwp_get_settings() {
951 +
952 + $settings = get_option( 'uwp_settings' );
953 +
954 + if ( empty( $settings ) ) {
955 +
956 + // Update old settings with new single option
957 +
958 + $general_settings = is_array( get_option( 'uwp_settings_general' ) ) ? get_option( 'uwp_settings_general' ) : array();
959 + $ext_settings = is_array( get_option( 'uwp_settings_extensions' ) ) ? get_option( 'uwp_settings_extensions' ) : array();
960 +
961 + $settings = array_merge( $general_settings, $ext_settings );
962 +
963 + update_option( 'uwp_settings', $settings );
964 +
965 + }
966 + return apply_filters( 'uwp_get_settings', $settings );
967 + }
968 +
969 + /**
970 + * Save admin fields.
971 + *
972 + * Loops though the userswp options array and outputs each field.
973 + *
974 + * @param array $options Options array to output
975 + * @param array $data Optional. Data to use for saving. Defaults to $_POST.
976 + * @return bool
977 + */
978 + public static function save_fields( $options, $data = null ) {
979 + if ( is_null( $data ) ) {
980 + $data = $_POST;
981 + }
982 + if ( empty( $data ) ) {
983 + return false;
984 + }
985 +
986 + // Options to update will be stored here and saved later.
987 + $update_options = array();
988 +
989 + // Loop options and get values to save.
990 + foreach ( $options as $option ) {
991 + if ( ! isset( $option['id'] ) || ! isset( $option['type'] ) ) {
992 + continue;
993 + }
994 +
995 + // Get posted value.
996 + if ( strstr( $option['id'], '[' ) ) {
997 + parse_str( $option['id'], $option_name_array );
998 + $option_name = current( array_keys( $option_name_array ) );
999 + $setting_name = key( $option_name_array[ $option_name ] );
1000 + $raw_value = isset( $data[ $option_name ][ $setting_name ] ) ? wp_unslash( $data[ $option_name ][ $setting_name ] ) : null;
1001 + } else {
1002 + $option_name = $option['id'];
1003 + $setting_name = '';
1004 + $raw_value = isset( $data[ $option['id'] ] ) ? wp_unslash( $data[ $option['id'] ] ) : null;
1005 + }
1006 +
1007 + // Format the value based on option type.
1008 + switch ( $option['type'] ) {
1009 + case 'checkbox':
1010 + $value = '1' === $raw_value ? 1 : 0;
1011 + break;
1012 + case 'textarea':
1013 + case 'editor':
1014 + $value = wp_kses_post( trim( $raw_value ) );
1015 + break;
1016 + case 'multiselect':
1017 + case 'multi_select_countries':
1018 + $value = array_filter( array_map( 'uwp_clean', (array) $raw_value ) );
1019 + break;
1020 + case 'multicheckbox':
1021 + $value = array_map( 'uwp_clean', (array) $raw_value );
1022 + break;
1023 + case 'image_width':
1024 + $value = array();
1025 + if ( isset( $raw_value['width'] ) ) {
1026 + $value['width'] = uwp_clean( $raw_value['width'] );
1027 + $value['height'] = uwp_clean( $raw_value['height'] );
1028 + $value['crop'] = isset( $raw_value['crop'] ) ? 1 : 0;
1029 + } else {
1030 + $value['width'] = $option['default']['width'];
1031 + $value['height'] = $option['default']['height'];
1032 + $value['crop'] = $option['default']['crop'];
1033 + }
1034 + break;
1035 + case 'select':
1036 + $allowed_values = empty( $option['options'] ) ? array() : array_keys( $option['options'] );
1037 + if ( empty( $option['default'] ) && empty( $allowed_values ) ) {
1038 + $value = null;
1039 + break;
1040 + }
1041 + $default = ( empty( $option['default'] ) ? $allowed_values[0] : $option['default'] );
1042 + $value = in_array( $raw_value, $allowed_values ) ? $raw_value : $default;
1043 + break;
1044 + default:
1045 + $value = uwp_clean( $raw_value );
1046 + break;
1047 + }
1048 +
1049 + /**
1050 + * Sanitize the value of an option.
1051 + */
1052 + $value = apply_filters( 'uwp_admin_settings_sanitize_option', $value, $option, $raw_value );
1053 +
1054 + /**
1055 + * Sanitize the value of an option by option name.
1056 + */
1057 + $value = apply_filters( "uwp_admin_settings_sanitize_option_$option_name", $value, $option, $raw_value );
1058 +
1059 + if ( is_null( $value ) ) {
1060 + continue;
1061 + }
1062 +
1063 + // Check if option is an array and handle that differently to single values.
1064 + if ( $option_name && $setting_name ) {
1065 + if ( ! isset( $update_options[ $option_name ] ) ) {
1066 + $update_options[ $option_name ] = self::get_option( $option_name, array() );
1067 + }
1068 + if ( ! is_array( $update_options[ $option_name ] ) ) {
1069 + $update_options[ $option_name ] = array();
1070 + }
1071 + $update_options[ $option_name ][ $setting_name ] = $value;
1072 + } else {
1073 + $update_options[ $option_name ] = $value;
1074 + }
1075 + }
1076 +
1077 + // Save all options in our array.
1078 + foreach ( $update_options as $name => $value ) {
1079 + uwp_update_option( $name, $value );
1080 + }
1081 +
1082 + return true;
1083 + }
1084 +
1085 + /**
1086 + * Get a setting from the settings API.
1087 + *
1088 + * @param mixed $option_name
1089 + * @param mixed $default
1090 + * @return string
1091 + */
1092 + public static function get_option( $option_name, $default = '' ) {
1093 + return uwp_get_option( $option_name, $default );
1094 + }
1095 +
1096 +}