PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.73
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.73
1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 All 173 releases
← All changes | admin/settings/class-settings.php +975 -737 1.0.211.2.73 View file →
@@ -20,839 +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 - <?php do_action('uwp_before_general_shortcodes_content'); ?>
136 + // Get current tab/section
137 + if ( $tab ) {
138 + $current_tab = sanitize_title( $tab );
144 139
145 - <tr valign="top">
146 - <th scope="row"><?php echo __( 'User Profile Shortcode', 'userswp' ); ?></th>
147 - <td>
148 - <span class="short_code">[uwp_profile]</span>
149 - <span class="description"><?php echo __( 'This is the shortcode for the front end user\'s profile.', 'userswp' ); ?></span>
150 - </td>
151 - </tr>
140 + } else {
141 + $current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( $_GET['tab'] );
152 142
153 - <tr valign="top">
154 - <th scope="row"><?php echo __( 'Register Form Shortcode', 'userswp' ); ?></th>
155 - <td>
156 - <span class="short_code">[uwp_register]</span>
157 - <span class="description"><?php echo __( 'This is the shortcode for the front end register form.', 'userswp' ); ?></span>
158 - </td>
159 - </tr>
143 + }
144 + $current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( $_REQUEST['section'] );
160 145
161 - <tr valign="top">
162 - <th scope="row"><?php echo __( 'Login Form Shortcode', 'userswp' ); ?></th>
163 - <td>
164 - <span class="short_code">[uwp_login]</span>
165 - <span class="description"><?php echo __( 'This is the shortcode for the front end login form.', 'userswp' ); ?></span>
166 - </td>
167 - </tr>
146 + // Save settings if data has been posted
147 + if ( ! empty( $_POST ) ) {
148 + self::save();
149 + }
168 150
169 - <tr valign="top">
170 - <th scope="row"><?php echo __( 'Account Form Shortcode', 'userswp' ); ?></th>
171 - <td>
172 - <span class="short_code">[uwp_account]</span>
173 - <span class="description"><?php echo __( 'This is the shortcode for the front end account form.', 'userswp' ); ?></span>
174 - </td>
175 - </tr>
151 + // Add any posted messages
152 + if ( ! empty( $_GET['uwp_error'] ) ) {
153 + self::add_error( stripslashes( $_GET['uwp_error'] ) );
154 + }
176 155
177 - <tr valign="top">
178 - <th scope="row"><?php echo __( 'Forgot Password Form Shortcode', 'userswp' ); ?></th>
179 - <td>
180 - <span class="short_code">[uwp_forgot]</span>
181 - <span class="description"><?php echo __( 'This is the shortcode for the front end forgot password form.', 'userswp' ); ?></span>
182 - </td>
183 - </tr>
156 + if ( ! empty( $_GET['uwp_message'] ) ) {
157 + self::add_message( stripslashes( $_GET['uwp_message'] ) );
158 + }
184 159
185 - <tr valign="top">
186 - <th scope="row"><?php echo __( 'Change Password Form Shortcode', 'userswp' ); ?></th>
187 - <td>
188 - <span class="short_code">[uwp_change]</span>
189 - <span class="description"><?php echo __( 'This is the shortcode for the front end change password form.', 'userswp' ); ?></span>
190 - </td>
191 - </tr>
160 + // Get tabs for the settings page
161 + $tabs = apply_filters( 'uwp_settings_tabs_array', array() );
192 162
193 - <tr valign="top">
194 - <th scope="row"><?php echo __( 'Reset Password Form Shortcode', 'userswp' ); ?></th>
195 - <td>
196 - <span class="short_code">[uwp_reset]</span>
197 - <span class="description"><?php echo __( 'This is the shortcode for the front end reset password form.', 'userswp' ); ?></span>
198 - </td>
199 - </tr>
163 + include USERSWP_PATH . '/admin/views/html-admin-settings.php';
164 + }
200 165
201 - <tr valign="top">
202 - <th scope="row"><?php echo __( 'Users List Shortcode', 'userswp' ); ?></th>
203 - <td>
204 - <span class="short_code">[uwp_users]</span>
205 - <span class="description"><?php echo __( 'This is the shortcode for the front end users list.', 'userswp' ); ?></span>
206 - </td>
207 - </tr>
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 + }
208 202
209 - <?php do_action('uwp_after_general_shortcodes_content'); ?>
203 + // Custom attribute handling
204 + $custom_attributes = array();
210 205
211 - </table>
212 - <?php
213 - }
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 + }
214 211
215 - //subtabs
216 - public function get_general_general_content() {
217 - echo uwp_display_form();
218 - }
212 + $wrap_class = $value['id'] . '-wrap';
219 213
220 - public function display_form_title($title, $page, $active_tab) {
221 - if ($page == 'userswp' && $active_tab == 'main') {
222 - $title = __('General Options', 'userswp');
223 - }
224 - return $title;
225 - }
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'] : '';
226 218
227 - public function get_general_info_content() {
228 - ?>
229 - <h3><?php echo __( 'Welcome to UsersWP', 'userswp' ); ?></h3>
230 - <h4><?php echo sprintf(__( 'Version %s', 'userswp' ), USERSWP_VERSION); ?></h4>
219 + // Switch based on type
220 + switch ( $value['type'] ) {
231 221
232 - <h3><?php echo __( 'Flexible, Lightweight and Fast', 'userswp' ); ?></h3>
233 - <p><?php echo __( 'UsersWP allows you to add a customizable register and login form to your website.
234 - It also adds an extended profile page that override the default author page.
235 - UsersWP has been built to be lightweight and fast', '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 + }
236 234
237 - <h3><?php echo __( 'Less options, more hooks', 'userswp' ); ?></h3>
238 - <p><?php echo __( 'We cut down the options to the bare minimum and you will not find any fancy
239 - styling options in this plugin as we believe they belong in your theme.
240 - This doesn\'t mean that you cannot customize the plugin behaviour.
241 - To do this we provided a long list of Filters and Actions for any developer
242 - to extend UsersWP to fit their needs.', 'userswp' ); ?></p>
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 + }
243 238
244 - <h3><?php echo __( 'Override Templates', 'userswp' ); ?></h3>
245 - <p><?php echo sprintf(__( 'If you need to change the look and feel of any UsersWP templates,
246 - simply create a folder named userswp inside your active child theme
247 - and copy the template you wish to modify in it. You can now modify the template.
248 - The plugin will use your modified version and you don\'t have to worry about plugin or theme updates.
249 - %s Click here for examples %s', 'userswp' ), '<a href="https://userswp.io/docs/override-templates/">', '</a>'); ?></p>
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;
250 244
251 - <h3><?php echo __( 'Add-ons', 'userswp' ); ?></h3>
252 - <p><?php echo sprintf(__( 'We have a long list of free and premium add-ons that will help you extend users management on your website.
253 - %s Click here for our official free and premium add-ons %s', 'userswp' ), '<a href="https://userswp.io/downloads/category/addons/">', '</a>'); ?></p>
254 - <?php
255 - }
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;
256 255
257 - public function get_form_builder_tabs() {
258 - $tab = 'account';
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;
259 304
260 - if (isset($_GET['tab'])) {
261 - $tab = $_GET['tab'];
262 - }
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 + }
263 312
264 - ?>
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;
265 339
266 - <div class="wp-filter" style="margin-top: 0;margin-bottom: 5px">
267 - <ul class="filter-links">
268 - <li id="uwp-form-builder-account-li">
269 - <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>
270 - </li>
271 - <li id="uwp-form-builder-register-li">
272 - <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>
273 - </li>
274 - <?php do_action('uwp_form_builder_tab_items', $tab); ?>
275 - </ul>
276 - </div>
277 - <?php
278 - }
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 - public function get_form_builder_content() {
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';
281 353
282 - $tab = 'account';
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 + }
283 365
284 - if (isset($_GET['tab'])) {
285 - $tab = $_GET['tab'];
286 - }
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'] ) ); ?>">
287 378
288 - $tab_content = $this->form_builder->uwp_form_builder($tab);
289 - if ($tab == 'account') {
290 - ?>
291 - <h3 class=""><?php echo __( 'Manage Account Form Fields', 'userswp' ); ?></h3>
292 - <?php
293 - echo $tab_content;
294 - } elseif ($tab == 'register') {
295 - ?>
296 - <h3 class=""><?php echo __( 'Manage Register Form Fields', 'userswp' ); ?></h3>
297 - <?php
298 - echo $tab_content;
299 - }
300 -
301 - do_action('uwp_extra_form_builder_content', $tab, $tab_content);
302 - }
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;
303 391
304 - public function generic_display_form() {
305 - echo uwp_display_form();
306 - }
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 + }
307 399
308 - public function get_recaptcha_content() {
309 - echo uwp_display_form();
310 - }
400 + $rows = ! empty( $value['size'] ) ? absint( $value['size'] ) : 5;
311 401
312 - public function get_geodirectory_content() {
313 - echo uwp_display_form();
314 - }
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 ); ?>
315 415
316 - public function get_notifications_content() {
317 - ?>
318 - <h3 class=""><?php echo __( 'Email Notifications', 'userswp' ); ?></h3>
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 + }
319 443
320 - <table class="uwp-form-table">
321 - <tbody>
322 - <tr valign="top">
323 - <th scope="row" class="titledesc"><?php echo __( 'List of usable shortcodes', 'userswp' ); ?></th>
324 - <td class="forminp">
325 - <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>
326 - </td>
327 - </tr>
328 - </tbody>
329 - </table>
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;
330 485
331 - <?php
332 - echo uwp_display_form();
333 - }
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 + }
334 494
335 - public function uwp_register_settings() {
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 + }
336 499
337 - if ( false == get_option( 'uwp_settings' ) ) {
338 - add_option( 'uwp_settings' );
339 - }
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 - $callback = new UsersWP_Callback();
533 + if ( is_array( $option_value ) ) {
534 + selected( in_array( $key, $option_value ), true );
535 + } else {
536 + selected( $option_value, $key );
537 + }
342 538
343 - foreach( $this->uwp_get_registered_settings() as $tab => $settings ) {
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;
344 550
345 - foreach ( $settings as $key => $opt ) {
346 - add_settings_section(
347 - 'uwp_settings_' . $tab .'_'.$key,
348 - __return_null(),
349 - '__return_false',
350 - 'uwp_settings_' . $tab .'_'.$key
351 - );
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 + }
352 558
353 - foreach ($opt as $option) {
354 - $name = isset( $option['name'] ) ? $option['name'] : '';
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;
355 597
356 - add_settings_field(
357 - 'uwp_settings[' . $option['id'] . ']',
358 - $name,
359 - method_exists($callback, 'uwp_' . $option['type'] . '_callback') ? array($callback, 'uwp_' . $option['type'] . '_callback') : array($callback, 'uwp_missing_callback'),
360 - 'uwp_settings_' . $tab .'_'.$key,
361 - 'uwp_settings_' . $tab .'_'.$key,
362 - array(
363 - 'section' => $tab,
364 - 'id' => isset( $option['id'] ) ? $option['id'] : null,
365 - 'class' => isset( $option['class'] ) ? $option['class'] : null,
366 - 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '',
367 - 'name' => isset( $option['name'] ) ? $option['name'] : null,
368 - 'size' => isset( $option['size'] ) ? $option['size'] : null,
369 - 'options' => isset( $option['options'] ) ? $option['options'] : '',
370 - 'std' => isset( $option['std'] ) ? $option['std'] : '',
371 - 'min' => isset( $option['min'] ) ? $option['min'] : null,
372 - 'max' => isset( $option['max'] ) ? $option['max'] : null,
373 - 'step' => isset( $option['step'] ) ? $option['step'] : null,
374 - 'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null,
375 - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
376 - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
377 - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false,
378 - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false,
379 - 'global' => isset( $setting['global'] ) ? $setting['global'] : true,
380 - 'multiple' => isset( $option['multiple'] ) ? $option['multiple'] : false,
381 - )
382 - );
383 - }
384 - }
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();
385 606
386 - }
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 + }
387 622
388 - // Creates our settings in the options table
389 - register_setting( 'uwp_settings', 'uwp_settings', array($this, 'uwp_settings_sanitize') );
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 + }
390 639
391 - }
640 + if ( ! empty( $value['title'] ) ) {
641 + ?>
642 + <legend class="screen-reader-text"><span><?php echo esc_html( $value['title'] ); ?></span></legend>
392 643
393 - public function uwp_get_registered_settings() {
394 -
395 - $file_obj = new UsersWP_Files();
644 + <?php
645 + }
396 646
397 - /**
398 - * 'Whitelisted' uwp settings, filters are provided for each settings
399 - * section to allow extensions and other plugins to add their own settings
400 - */
401 - $uwp_settings = array(
402 - /** General Settings */
403 - 'userswp' => array(
404 - 'main' => apply_filters( 'uwp_settings_general_main',
405 - array(
406 - 'profile_page' => array(
407 - 'id' => 'profile_page',
408 - 'name' => __( 'User Profile Page', 'userswp' ),
409 - 'desc' => __( 'This is the front end user\'s profile page. This page automatically overrides the default WordPress author page.', 'userswp' ),
410 - 'type' => 'select',
411 - 'options' => uwp_get_pages(),
412 - 'chosen' => true,
413 - 'placeholder' => __( 'Select a page', 'userswp' ),
414 - 'class' => 'uwp_label_block',
415 - ),
416 - 'register_page' => array(
417 - 'id' => 'register_page',
418 - 'name' => __( 'Register Page', 'userswp' ),
419 - 'desc' => __( 'This is the front end register page. This is where users create their account.', 'userswp' ),
420 - 'type' => 'select',
421 - 'options' => uwp_get_pages(),
422 - 'chosen' => true,
423 - 'placeholder' => __( 'Select a page', 'userswp' ),
424 - 'class' => 'uwp_label_block',
425 - ),
426 - 'login_page' => array(
427 - 'id' => 'login_page',
428 - 'name' => __( 'Login Page', 'userswp' ),
429 - 'desc' => __( 'This is the front end login page. This is where users will login after creating their account.', 'userswp' ),
430 - 'type' => 'select',
431 - 'options' => uwp_get_pages(),
432 - 'chosen' => true,
433 - 'placeholder' => __( 'Select a page', 'userswp' ),
434 - 'class' => 'uwp_label_block',
435 - ),
436 - 'account_page' => array(
437 - 'id' => 'account_page',
438 - 'name' => __( 'Account Page', 'userswp' ),
439 - 'desc' => __( 'This is the front end account page. This is where users can edit their account.', 'userswp' ),
440 - 'type' => 'select',
441 - 'options' => uwp_get_pages(),
442 - 'chosen' => true,
443 - 'placeholder' => __( 'Select a page', 'userswp' ),
444 - 'class' => 'uwp_label_block',
445 - ),
446 - 'change_page' => array(
447 - 'id' => 'change_page',
448 - 'name' => __( 'Change Password Page', 'userswp' ),
449 - 'desc' => __( 'This is the front end Change Password page.', 'userswp' ),
450 - 'type' => 'select',
451 - 'options' => uwp_get_pages(),
452 - 'chosen' => true,
453 - 'placeholder' => __( 'Select a page', 'userswp' ),
454 - 'class' => 'uwp_label_block',
455 - ),
456 - 'forgot_page' => array(
457 - 'id' => 'forgot_page',
458 - 'name' => __( 'Forgot Password Page', 'userswp' ),
459 - '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' ),
460 - 'type' => 'select',
461 - 'options' => uwp_get_pages(),
462 - 'chosen' => true,
463 - 'placeholder' => __( 'Select a page', 'userswp' ),
464 - 'class' => 'uwp_label_block',
465 - ),
466 - 'reset_page' => array(
467 - 'id' => 'reset_page',
468 - 'name' => __( 'Reset Password Page', 'userswp' ),
469 - 'desc' => __( 'This is the front end Reset Password page. This is the page where users can reset their password when they lose it.', 'userswp' ),
470 - 'type' => 'select',
471 - 'options' => uwp_get_pages(),
472 - 'chosen' => true,
473 - 'placeholder' => __( 'Select a page', 'userswp' ),
474 - 'class' => 'uwp_label_block',
475 - ),
476 - 'users_page' => array(
477 - 'id' => 'users_page',
478 - 'name' => __( 'Users List Page', 'userswp' ),
479 - 'desc' => __( 'This is the front end Users List page. This is the page where all registered users of the websites are listed.', 'userswp' ),
480 - 'type' => 'select',
481 - 'options' => uwp_get_pages(),
482 - 'chosen' => true,
483 - 'placeholder' => __( 'Select a page', 'userswp' ),
484 - 'class' => 'uwp_label_block',
485 - ),
486 - 'profile_no_of_items' => array(
487 - 'id' => 'profile_no_of_items',
488 - 'name' => __( 'Number of Items', 'userswp' ),
489 - 'type' => 'text',
490 - 'std' => '',
491 - 'desc' => __( 'Enter number of items to display in profile tabs.', 'userswp' ),
492 - ),
493 - )
494 - ),
495 - 'register' => apply_filters( 'uwp_settings_general_register', uwp_settings_general_register_fields()),
496 - 'login' => apply_filters( 'uwp_settings_general_login', uwp_settings_general_loginout_fields()),
497 - 'profile' => apply_filters( 'uwp_settings_general_profile',
498 - array(
499 - 'enable_profile_header' => array(
500 - 'id' => 'enable_profile_header',
501 - 'name' => __( 'Display Header in Profile', 'userswp' ),
502 - 'desc' => '',
503 - 'type' => 'checkbox',
504 - 'std' => '1',
505 - 'class' => 'uwp_label_inline',
506 - ),
507 - 'profile_avatar_size' => array(
508 - 'id' => 'profile_avatar_size',
509 - 'name' => __( 'Profile Avatar max file size', 'userswp' ),
510 - 'desc' => sprintf(__( '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 (%s) will be used.', 'userswp' ), '<b>'.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).'</b>'),
511 - 'type' => 'number',
512 - 'std' => '',
513 - 'size' => 'regular',
514 - 'placeholder' => __( 'Enter Profile Avatar max file size.', 'userswp' ),
515 - ),
516 - 'profile_banner_size' => array(
517 - 'id' => 'profile_banner_size',
518 - 'name' => __( 'Profile Banner max file size', 'userswp' ),
519 - 'desc' => sprintf(__( '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 (%s) will be used.', 'userswp' ), '<b>'.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).'</b>'),
520 - 'type' => 'number',
521 - 'std' => '',
522 - 'size' => 'regular',
523 - 'placeholder' => __( 'Enter Profile Banner max file size.', 'userswp' ),
524 - ),
525 - 'profile_banner_width' => array(
526 - 'id' => 'profile_banner_width',
527 - 'name' => __( 'Profile banner width', 'userswp' ),
528 - 'desc' => '',
529 - 'type' => 'number',
530 - 'std' => '1000',
531 - 'size' => 'regular',
532 - 'placeholder' => __( 'Enter Profile banner width in Pixels', 'userswp' ),
533 - ),
534 - 'profile_default_banner' => array(
535 - 'id' => 'profile_default_banner',
536 - 'name' => __( 'Default banner image', 'userswp' ),
537 - 'desc' => __( 'Recommended image size: 1000x300', 'userswp'),
538 - 'type' => 'media',
539 - 'std' => '',
540 - 'placeholder' => USERSWP_PLUGIN_URL."public/assets/images/banner.png"
541 - ),
542 - 'profile_default_profile' => array(
543 - 'id' => 'profile_default_profile',
544 - 'name' => __( 'Default profile image', 'userswp' ),
545 - 'desc' => __( 'Recommended image size: 150x150', 'userwp'),
546 - 'type' => 'media',
547 - 'std' => '',
548 - 'placeholder' => USERSWP_PLUGIN_URL."public/assets/images/no_profile.png"
549 - ),
550 - 'enable_profile_body' => array(
551 - 'id' => 'enable_profile_body',
552 - 'name' => __( 'Display Body in Profile', 'userswp' ),
553 - 'desc' => '',
554 - 'type' => 'checkbox',
555 - 'std' => '1',
556 - 'class' => 'uwp_label_inline',
557 - ),
558 - 'enable_profile_tabs' => array(
559 - 'id' => 'enable_profile_tabs',
560 - 'name' => __( 'Choose the tabs to display in Profile', 'userswp' ),
561 - 'desc' => __( 'Choose the tabs to display in UsersWP Profile', 'userswp' ),
562 - 'multiple' => true,
563 - 'chosen' => true,
564 - 'type' => 'select_order',
565 - 'options' => $this->uwp_available_tab_items(),
566 - 'placeholder' => __( 'Select Tabs', 'userswp' )
567 - ),
568 - )
569 - ),
570 - 'users' => apply_filters( 'uwp_settings_general_profile',
571 - array(
572 - 'users_default_layout' => array(
573 - 'id' => 'users_default_layout',
574 - 'name' => __( 'Users default layout', 'userswp' ),
575 - 'desc' => __( 'Choose the default layout for Users Page - Users List', 'userswp' ),
576 - 'type' => 'select',
577 - 'options' => $this->uwp_available_users_layout(),
578 - 'placeholder' => __( 'Select Layout', 'userswp' )
579 - ),
580 - 'users_excluded_from_list' => array(
581 - 'id' => 'users_excluded_from_list',
582 - 'name' => __( 'Users to exclude', 'userswp' ),
583 - 'type' => 'text',
584 - 'std' => '',
585 - 'desc' => __( 'Enter comma separated ids of users to exclude from users listing.', 'userswp' ),
586 - ),
587 - )
588 - ),
589 - 'change' => apply_filters( 'uwp_settings_general_change',
590 - array(
591 - 'change_enable_old_password' => array(
592 - 'id' => 'change_enable_old_password',
593 - 'name' => __( 'Enabled Old Password?', 'userswp' ),
594 - 'desc' => 'This option adds an extra layer of security. User need to enter their old password before changing the password.',
595 - 'type' => 'checkbox',
596 - 'std' => '1',
597 - 'class' => 'uwp_label_inline',
598 - ),
599 - 'change_disable_password_nag' => array(
600 - 'id' => 'change_disable_password_nag',
601 - 'name' => __( 'Disable system generated password notice.', 'userswp' ),
602 - 'desc' => 'This option will disable system generated password notice if user has not changed default password after registration.',
603 - 'type' => 'checkbox',
604 - 'std' => '0',
605 - 'class' => 'uwp_label_inline',
606 - ),
607 - )
608 - ),
609 - 'uninstall' => apply_filters( 'uwp_settings_general_uninstall',
610 - array(
611 - 'uninstall_erase_data' => array(
612 - 'id' => 'uninstall_erase_data',
613 - 'name' => __( 'UsersWP', 'userswp' ),
614 - 'desc' => __( 'Remove all data when deleted?', 'userswp' ),
615 - 'type' => 'checkbox',
616 - 'std' => '1',
617 - 'class' => 'uwp_label_inline',
618 - ),
619 - )
620 - ),
621 - ),
622 - 'uwp_notifications' => array(
623 - 'main' => apply_filters( 'uwp_settings_notifications_main',
624 - array(
625 - 'registration_activate_email_subject' => array(
626 - 'id' => 'registration_activate_email_subject',
627 - 'name' => __( 'Registration activate email', 'userswp' ),
628 - 'desc' => "",
629 - 'type' => 'text',
630 - 'size' => 'regular',
631 - 'placeholder' => __( 'Enter Registration activate email Subject', 'userswp' )
632 - ),
633 - 'registration_activate_email_content' => array(
634 - 'id' => 'registration_activate_email_content',
635 - 'name' => "",
636 - 'desc' => "",
637 - 'type' => 'textarea',
638 - 'placeholder' => __( 'Enter Registration activate email Content', 'userswp' )
639 - ),
640 - 'registration_success_email_subject' => array(
641 - 'id' => 'registration_success_email_subject',
642 - 'name' => __( 'Registration success email', 'userswp' ),
643 - 'desc' => "",
644 - 'type' => 'text',
645 - 'size' => 'regular',
646 - 'placeholder' => __( 'Enter Registration success email Subject', 'userswp' )
647 - ),
648 - 'registration_success_email_content' => array(
649 - 'id' => 'registration_success_email_content',
650 - 'name' => "",
651 - 'desc' => "",
652 - 'type' => 'textarea',
653 - 'placeholder' => __( 'Enter Registration success email Content', 'userswp' )
654 - ),
655 - 'forgot_password_email_subject' => array(
656 - 'id' => 'forgot_password_email_subject',
657 - 'name' => __( 'Forgot password email', 'userswp' ),
658 - 'desc' => "",
659 - 'type' => 'text',
660 - 'size' => 'regular',
661 - 'placeholder' => __( 'Enter forgot password email Subject', 'userswp' )
662 - ),
663 - 'forgot_password_email_content' => array(
664 - 'id' => 'forgot_password_email_content',
665 - 'name' => "",
666 - 'desc' => "",
667 - 'type' => 'textarea',
668 - 'placeholder' => __( 'Enter forgot password email Content', 'userswp' )
669 - ),
670 - 'change_password_email_subject' => array(
671 - 'id' => 'change_password_email_subject',
672 - 'name' => __( 'Change password email', 'userswp' ),
673 - 'desc' => "",
674 - 'type' => 'text',
675 - 'size' => 'regular',
676 - 'placeholder' => __( 'Enter change password email Subject', 'userswp' )
677 - ),
678 - 'change_password_email_content' => array(
679 - 'id' => 'change_password_email_content',
680 - 'name' => "",
681 - 'desc' => "",
682 - 'type' => 'textarea',
683 - 'placeholder' => __( 'Enter change password email Content', 'userswp' )
684 - ),
685 - 'reset_password_email_subject' => array(
686 - 'id' => 'reset_password_email_subject',
687 - 'name' => __( 'Reset password email', 'userswp' ),
688 - 'desc' => "",
689 - 'type' => 'text',
690 - 'size' => 'regular',
691 - 'placeholder' => __( 'Enter reset password email Subject', 'userswp' )
692 - ),
693 - 'reset_password_email_content' => array(
694 - 'id' => 'reset_password_email_content',
695 - 'name' => "",
696 - 'desc' => "",
697 - 'type' => 'textarea',
698 - 'placeholder' => __( 'Enter reset password email Content', 'userswp' )
699 - ),
700 - 'enable_account_update_notification' => array(
701 - 'id' => 'enable_account_update_notification',
702 - 'name' => __( 'Account update email', 'userswp' ),
703 - 'desc' => 'Enable account update notification',
704 - 'type' => 'checkbox',
705 - 'std' => '0',
706 - 'class' => 'uwp_label_inline',
707 - ),
708 - 'account_update_email_subject' => array(
709 - 'id' => 'account_update_email_subject',
710 - 'name' => "",
711 - 'desc' => "",
712 - 'type' => 'text',
713 - 'size' => 'regular',
714 - 'placeholder' => __( 'Enter account update email Subject', 'userswp' )
715 - ),
716 - 'account_update_email_content' => array(
717 - 'id' => 'account_update_email_content',
718 - 'name' => "",
719 - 'desc' => "",
720 - 'type' => 'textarea',
721 - 'placeholder' => __( 'Enter account update email Content', 'userswp' )
722 - ),
723 - )
724 - ),
725 - 'admin' => apply_filters( 'uwp_settings_notifications_admin',
726 - array(
727 - 'registration_success_email_subject_admin' => array(
728 - 'id' => 'registration_success_email_subject_admin',
729 - 'name' => __( 'New account registration', 'userswp' ),
730 - 'desc' => "",
731 - 'type' => 'text',
732 - 'std' => __( 'New account registration', 'userswp' ),
733 - 'size' => 'regular',
734 - ),
735 - 'registration_success_email_content_admin' => array(
736 - 'id' => 'registration_success_email_content_admin',
737 - 'name' => "",
738 - 'desc' => "",
739 - 'type' => 'textarea',
740 - 'std' => __("A user has been registered recently on your website. [#extras#]", "userswp"),
741 - ),
742 - )
743 - ),
744 - ),
745 - );
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
746 661
747 - $uwp_settings = apply_filters( 'uwp_registered_settings', $uwp_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;
748 674
749 - return $uwp_settings;
750 - }
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 + }
751 682
752 - public function uwp_get_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;
753 721
754 - $settings = get_option( 'uwp_settings' );
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 + }
755 729
756 - if( empty( $settings ) ) {
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 + );
757 740
758 - // Update old settings with new single option
741 + if ( isset( $value['args'] ) ) {
742 + $args = wp_parse_args( $value['args'], $args );
743 + }
759 744
760 - $general_settings = is_array( get_option( 'uwp_settings_general' ) ) ? get_option( 'uwp_settings_general' ) : array();
761 - $ext_settings = is_array( get_option( 'uwp_settings_extensions' ) ) ? get_option( 'uwp_settings_extensions' ) : array();
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 ); ?>
762 755
763 - $settings = array_merge( $general_settings, $ext_settings );
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>
764 758
765 - update_option( 'uwp_settings', $settings );
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 + }
766 764
767 - }
768 - return apply_filters( 'uwp_get_settings', $settings );
769 - }
765 + ?>
770 766
771 - public function uwp_settings_sanitize( $input = array() ) {
772 - global $uwp_options;
767 + </td>
768 + </tr>
769 + <?php
770 + break;
773 771
774 - if ( empty( $_POST['_wp_http_referer'] ) ) {
775 - return $input;
776 - }
772 + case 'import_export_users':
773 + ?>
777 774
778 - $parsed_url = wp_parse_url($_POST['_wp_http_referer']);
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>
779 791
780 - if (!isset($parsed_url['query'])) {
781 - return $input;
782 - }
783 - parse_str( $parsed_url['query'], $referrer );
792 + <?php
784 793
785 - $settings = $this->uwp_get_registered_settings();
794 + break;
786 795
787 - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'main';
788 - $page = isset( $referrer['page'] ) ? $referrer['page'] : 'userswp';
796 + case 'import_export_settings':
797 + ?>
789 798
790 - $input = $input ? $input : array();
791 - $input = apply_filters( 'uwp_settings_'.$page.'_' . $tab . '_sanitize', $input );
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>
792 815
793 - // Loop through each setting being saved and pass it through a sanitization filter
794 - foreach ( $input as $key => $value ) {
795 - // Get the setting type (checkbox, select, etc)
796 - $type = isset( $settings[$page][$tab][$key]['type'] ) ? $settings[$page][$tab][$key]['type'] : false;
816 + <?php
797 817
798 - if ( $type ) {
799 - // Field type specific filter
800 - $input[$key] = apply_filters( 'uwp_settings_sanitize_' . $type, $value, $key );
801 - }
818 + break;
802 819
803 - // General filter
804 - $input[$key] = apply_filters( 'uwp_settings_sanitize', $input[$key], $key );
805 - }
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;
806 843
807 - // Loop through the whitelist and unset any that are empty for the tab being saved
808 - if ( ! empty( $settings[$page][$tab] ) ) {
809 - foreach ( $settings[$page][$tab] as $key => $value ) {
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 + }
810 853
811 - // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
812 - if ( is_numeric( $key ) ) {
813 - $key = $value['id'];
814 - }
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 + >
815 874
816 - if ( empty( $input[$key] ) ) {
817 - unset( $uwp_options[$key] );
818 - }
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;
819 889
820 - }
821 - }
890 + // Default: run an action
891 + default:
892 + do_action( 'uwp_admin_field_' . $value['type'], $value );
893 + break;
894 + }
895 + }
896 + }
822 897
823 - // Merge our new settings with the existing
824 - $output = array_merge( $uwp_options, $input );
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 = '';
825 909
826 - flush_rewrite_rules();
827 - add_settings_error( 'uwp-notices', '', __( 'Settings updated.', 'userswp' ), 'updated' );
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 + }
828 918
829 - return $output;
830 - }
919 + if ( ! empty( $value['docs'] ) ) {
831 920
832 - public function uwp_available_tab_items() {
833 - $tabs_arr = array(
834 - 'more_info' => __( 'More Info', 'userswp' ),
835 - 'posts' => __( 'Posts', 'userswp' ),
836 - 'comments' => __( 'Comments', 'userswp' ),
837 - );
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>';
838 922
839 - $tabs_arr = apply_filters('uwp_available_tab_items', $tabs_arr);
923 + if ( in_array( $value['type'], array( 'checkbox' ) ) ) {
924 + $description .= $docs_link;
925 + } else {
926 + $tooltip_html .= $docs_link;
927 + }
928 + }
840 929
841 - return $tabs_arr;
842 - }
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 + }
843 937
844 - public function uwp_available_users_layout() {
845 - $tabs_arr = array(
846 - 'list' => __( 'List View', 'userswp' ),
847 - '2col' => __( 'Grid View - 2 Column', 'userswp' ),
848 - '3col' => __( 'Grid View - 3 Column', 'userswp' ),
849 - '4col' => __( 'Grid View - 4 Column', 'userswp' ),
850 - '5col' => __( 'Grid View - 5 Column', 'userswp' ),
851 - );
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 + }
852 943
853 - $tabs_arr = apply_filters('uwp_available_users_layout', $tabs_arr);
944 + return array(
945 + 'description' => $description,
946 + 'tooltip_html' => $tooltip_html,
947 + );
948 + }
854 949
855 - return $tabs_arr;
856 - }
950 + public function uwp_get_settings() {
857 951
858 -}
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 +}