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 | includes/helpers/forms.php +517 -102 1.0.101.2.74 View file →
@@ -1,179 +1,594 @@
1 1 <?php
2 2 /**
3 3 * Returns the register form fields.
4 4 *
5 - * @since 1.0.0
5 + * @return array Form fields.
6 6 * @package userswp
7 7 *
8 - * @return array Form fields.
8 + * @since 1.0.0
9 9 */
10 -function get_register_form_fields() {
11 - global $wpdb;
12 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
13 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
14 - $fields = $wpdb->get_results($wpdb->prepare("SELECT fields.* FROM " . $table_name . " fields JOIN " . $extras_table_name . " extras ON extras.site_htmlvar_name = fields.htmlvar_name WHERE fields.form_type = %s AND fields.is_active = '1' AND fields.for_admin_use != '1' AND fields.is_register_field = '1' AND extras.form_type = 'register' ORDER BY extras.sort_order ASC", array('account')));
15 - $fields = apply_filters('uwp_get_register_form_fields', $fields);
16 - return $fields;
10 +function get_register_form_fields( $form_id = 1 ) {
11 + global $wpdb;
12 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
13 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
14 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT fields.* FROM ' . $table_name . ' fields JOIN ' . $extras_table_name . " extras ON extras.site_htmlvar_name = fields.htmlvar_name WHERE fields.form_type = %s AND fields.is_active = '1' AND fields.for_admin_use != '1' AND fields.is_register_field = '1' AND extras.form_type = 'register' AND extras.form_id=%d AND fields.form_id=%d ORDER BY extras.sort_order ASC", array( 'account', $form_id, $form_id ) ) );
15 + $fields = apply_filters( 'uwp_get_register_form_fields', $fields, $form_id );
16 + return $fields;
17 17 }
18 18
19 +function check_register_form_field( $var ) {
20 + if ( ! $var ) {
21 + return false;
22 + }
23 +
24 + global $wpdb;
25 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
26 +
27 + $fields = $wpdb->get_results(
28 + $wpdb->prepare(
29 + 'select * from ' . $extras_table_name . ' where form_type = %s AND site_htmlvar_name = %s order by sort_order asc',
30 + array( 'register', $var )
31 + )
32 + );
33 +
34 + $fields = apply_filters( 'uwp_check_register_form_field', $fields );
35 +
36 + return $fields;
37 +}
38 +
19 39 /**
20 40 * Returns the register form validate-able fields.
21 41 *
42 + * @param int $form_id Form ID Default 1.
43 + *
44 + * @return array Validate-able fields.
22 45 * @since 1.0.0
23 46 * @package userswp
24 47 *
25 - * @param int $role_id Role ID from role addons. Default 0.
26 - *
27 - * @return array Validate-able fields.
28 48 */
29 -function get_register_validate_form_fields($role_id) {
30 - global $wpdb;
31 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
32 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
33 - if ($role_id == 0) {
34 - $fields = $wpdb->get_results($wpdb->prepare("SELECT fields.* FROM " . $table_name . " fields JOIN " . $extras_table_name . " extras ON extras.site_htmlvar_name = fields.htmlvar_name WHERE fields.form_type = %s AND fields.field_type != 'fieldset' AND fields.field_type != 'file' AND fields.is_active = '1' AND fields.for_admin_use != '1' AND fields.is_register_field = '1' ORDER BY extras.sort_order ASC", array('account')));
35 - } else {
36 - $slug = get_post_field( 'post_name', $role_id );
37 - $fields = $wpdb->get_results($wpdb->prepare("SELECT fields.* FROM " . $table_name . " fields JOIN " . $extras_table_name . " extras ON extras.site_htmlvar_name = fields.htmlvar_name WHERE fields.form_type = %s AND fields.field_type != 'fieldset' AND fields.field_type != 'file' AND fields.is_active = '1' AND fields.for_admin_use != '1' AND fields.is_register_field = '1' AND FIND_IN_SET(%s, fields.user_roles) ORDER BY extras.sort_order ASC", array('account', $slug)));
38 - }
49 +function get_register_validate_form_fields( $form_id = 1 ) {
50 + global $wpdb;
51 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
52 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
53 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT fields.* FROM ' . $table_name . ' fields JOIN ' . $extras_table_name . " extras ON extras.site_htmlvar_name = fields.htmlvar_name WHERE fields.form_type = %s AND extras.form_type = 'register' AND fields.field_type != 'fieldset' AND fields.field_type != 'file' AND fields.is_active = '1' AND fields.for_admin_use != '1' AND fields.is_register_field = '1' AND extras.form_id = %d AND fields.form_id = %s ORDER BY extras.sort_order ASC", array( 'account', $form_id, $form_id ) ) );
54 + $fields = apply_filters( 'uwp_get_register_validate_form_fields', $fields, $form_id );
39 55
40 - $fields = apply_filters('uwp_get_register_validate_form_fields', $fields, $role_id);
41 - return $fields;
56 + return $fields;
42 57 }
43 58
44 59 /**
45 60 * Returns the change password form validate-able fields.
46 61 *
47 - * @since 1.0.0
62 + * @return array Validate-able fields
48 63 * @package userswp
49 64 *
50 - * @return array Validate-able fields
65 + * @since 1.0.0
51 66 */
52 67 function get_change_validate_form_fields() {
53 - global $wpdb;
54 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
55 - $enable_old_password = uwp_get_option('change_enable_old_password', false);
56 - if ($enable_old_password == '1') {
57 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND field_type != 'fieldset' AND field_type != 'file' AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array('change')));
58 - } else {
59 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND field_type != 'fieldset' AND field_type != 'file' AND is_active = '1' AND for_admin_use != '1' AND htmlvar_name != 'uwp_change_old_password' ORDER BY sort_order ASC", array('change')));
60 - }
61 - return $fields;
68 + global $wpdb;
69 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
70 + $enable_old_password = uwp_get_option( 'change_enable_old_password', false );
71 + $user_id = get_current_user_id();
72 + if ( $user_id && 1 == get_user_meta( $user_id, 'is_uwp_social_login_no_password', true ) ) {
73 + $enable_old_password = 0;
74 + }
75 + if ( $enable_old_password == '1' ) {
76 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND field_type != 'fieldset' AND field_type != 'file' AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array( 'change' ) ) );
77 + } else {
78 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND field_type != 'fieldset' AND field_type != 'file' AND is_active = '1' AND for_admin_use != '1' AND htmlvar_name != 'old_password' ORDER BY sort_order ASC", array( 'change' ) ) );
79 + }
80 +
81 + return $fields;
62 82 }
63 83
64 84 /**
65 85 * Returns the account form fields.
66 86 *
87 + * @param string $extra_where Extra where query.
88 + *
89 + * @return array Form fields.
67 90 * @since 1.0.0
68 91 * @package userswp
69 92 *
70 - * @param string $extra_where Extra where query.
71 - *
72 - * @return array Form fields.
73 93 */
74 -function get_account_form_fields($extra_where = '') {
75 - global $wpdb;
76 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
77 - $include_admin_use = apply_filters('uwp_account_include_admin_use_only_fields', false);
78 - if ($include_admin_use) {
79 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND is_register_only_field = '0' " . $extra_where . " ORDER BY sort_order ASC", array('account', $extra_where)));
80 - } else {
81 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' AND is_register_only_field = '0' " . $extra_where . " ORDER BY sort_order ASC", array('account', $extra_where)));
82 - }
83 - return $fields;
94 +function get_account_form_fields( $extra_where = '' ) {
95 + global $wpdb;
96 +
97 + $form_id = uwp_get_register_form_id( get_current_user_id() );
98 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
99 + $include_admin_use = apply_filters( 'uwp_account_include_admin_use_only_fields', false );
100 + if ( $include_admin_use ) {
101 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND is_active = '1' AND is_register_only_field = '0' AND htmlvar_name != 'password' AND form_id = %s" . $extra_where . ' ORDER BY sort_order ASC', array( 'account', $form_id ) ) );
102 + } else {
103 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' AND is_register_only_field = '0' AND htmlvar_name != 'password' AND form_id = %s" . $extra_where . ' ORDER BY sort_order ASC', array( 'account', $form_id ) ) );
104 + }
105 +
106 + return $fields;
84 107 }
85 108
86 109 /**
87 110 * Returns the change password form fields.
88 111 *
89 - * @since 1.0.0
112 + * @return array Form fields.
90 113 * @package userswp
91 114 *
92 - * @return array Form fields.
115 + * @since 1.0.0
93 116 */
94 117 function get_change_form_fields() {
95 - global $wpdb;
96 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
97 - $enable_old_password = uwp_get_option('change_enable_old_password', false);
98 - if ($enable_old_password == '1') {
99 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array('change')));
100 - } else {
101 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' AND htmlvar_name != 'uwp_change_old_password' ORDER BY sort_order ASC", array('change')));
102 - }
103 - return $fields;
118 + global $wpdb;
119 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
120 + $enable_old_password = uwp_get_option( 'change_enable_old_password', false );
121 + $user_id = get_current_user_id();
122 + if ( $user_id && 1 == get_user_meta( $user_id, 'is_uwp_social_login_no_password', true ) ) {
123 + $enable_old_password = 0;
124 + }
125 + if ( $enable_old_password == '1' ) {
126 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' ORDER BY sort_order ASC", array( 'change' ) ) );
127 + } else {
128 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM ' . $table_name . " WHERE form_type = %s AND is_active = '1' AND for_admin_use != '1' AND htmlvar_name != 'old_password' ORDER BY sort_order ASC", array( 'change' ) ) );
129 + }
130 +
131 + return $fields;
104 132 }
105 133
106 134 /**
107 135 * Validates the submitted form data.
108 136 *
137 + * @param array $data Submitted form data
138 + * @param string $type Form type.
139 + * @param array|bool $fields Fields applicable for validation.
140 + * @param string $extra_where Extra where query.
141 + *
142 + * @return array|mixed|WP_Error Validated form data.
109 143 * @since 1.0.0
110 144 * @package userswp
111 145 *
112 - * @param array $data Submitted form data
113 - * @param string $type Form type.
114 - * @param array|bool $fields Fields applicable for validation.
115 - *
116 - * @return array|mixed|void|WP_Error Validated form data.
117 146 */
118 -function uwp_validate_fields($data, $type, $fields = false) {
119 - $validation = new UsersWP_Validation();
120 - return $validation->validate_fields($data, $type, $fields);
147 +function uwp_validate_fields( $data, $type, $fields = false, $extra_where = '' ) {
148 + $validation = new UsersWP_Validation();
149 +
150 + return $validation->validate_fields( $data, $type, $fields, $extra_where );
121 151 }
122 152
123 153 /**
124 154 * Returns form field label. If empty returns the field title.
125 155 *
156 + * @param object $field Field info.
157 + *
158 + * @return string Label.
126 159 * @since 1.0.0
127 160 * @package userswp
128 161 *
129 - * @param object $field Field info.
162 + */
163 +function uwp_get_form_label( $field ) {
164 + if ( isset( $field->form_label ) && ! empty( $field->form_label ) ) {
165 + $label = __( $field->form_label, 'userswp' );
166 + } else {
167 + $label = __( $field->site_title, 'userswp' );
168 + }
169 +
170 + return apply_filters( 'uwp_get_form_label', stripslashes( esc_attr( $label ) ), $field );
171 +}
172 +
173 +/**
174 + * Returns placeholder for field.
130 175 *
176 + * @param object $field Field info.
177 + *
131 178 * @return string Label.
132 179 */
133 -function uwp_get_form_label($field) {
134 - if (isset($field->form_label) && !empty($field->form_label)) {
135 - $label = __($field->form_label, 'userswp');
136 - } else {
137 - $label = __($field->site_title, 'userswp');
138 - }
139 - return $label;
180 +function uwp_get_field_placeholder( $field ) {
181 +
182 + if ( isset( $field->field_type ) && in_array( $field->field_type, array( 'select', 'multiselect' ) ) ) {
183 + if ( isset( $field->placeholder_value ) && ! empty( $field->placeholder_value ) ) {
184 + $placeholder = __( $field->placeholder_value, 'userswp' );
185 + } else {
186 + $placeholder = wp_sprintf( __( 'Choose %s&hellip;', 'userswp' ), uwp_get_form_label( $field ) );
187 + }
188 + } elseif ( isset( $field->placeholder_value ) && ! empty( $field->placeholder_value ) ) {
189 + $placeholder = __( $field->placeholder_value, 'userswp' );
190 + } else {
191 + $placeholder = uwp_get_form_label( $field );
192 + }
193 +
194 + if ( isset( $field->is_required ) && ! empty( $field->is_required ) ) {
195 + $placeholder .= ' *';
196 + }
197 +
198 + return apply_filters( 'uwp_get_field_placeholder', stripslashes( $placeholder ), $field );
140 199 }
141 200
142 201 /**
143 - * Displays admin settings form.
202 + * Returns description for field.
144 203 *
204 + * @param object $field Field info.
205 + * @param string $default Default value.
206 + *
207 + * @return string Label.
208 + */
209 +function uwp_get_field_description( $field, $default = '' ) {
210 +
211 + if ( isset( $field->help_text ) && ! empty( $field->help_text ) ) {
212 + $desc = __( $field->help_text, 'userswp' );
213 + } else {
214 + $desc = $default;
215 + }
216 +
217 + return apply_filters( 'uwp_get_field_description', stripslashes( $desc ), $field );
218 +}
219 +
220 +/**
221 + * Gets the custom field info for given key.
222 + *
223 + * @param string $htmlvar_name Custom field key.
224 + * @param string $form_type Form type.
225 + *
226 + * @return object Field info.
227 + * @package userswp
228 + *
145 229 * @since 1.0.0
230 + */
231 +function uwp_get_custom_field_info( $htmlvar_name, $form_type = 'account' ) {
232 + global $wpdb, $custom_field_info;
233 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
234 + $cache_key = $htmlvar_name . '_' . $form_type;
235 +
236 + // Return cached field data.
237 + if ( isset( $custom_field_info[ $cache_key ] ) ) {
238 + return $custom_field_info[ $cache_key ];
239 + }
240 +
241 + if ( $form_type ) {
242 + $field = $wpdb->get_row(
243 + $wpdb->prepare(
244 + 'SELECT * FROM ' . $table_name . ' WHERE htmlvar_name = %s AND form_type = %s',
245 + array(
246 + $htmlvar_name,
247 + $form_type,
248 + )
249 + )
250 + );
251 + } else {
252 + $field = $wpdb->get_row( $wpdb->prepare( 'SELECT * FROM ' . $table_name . ' WHERE htmlvar_name = %s', array( $htmlvar_name ) ) );
253 + }
254 +
255 + // Cache the field data.
256 + $custom_field_info[ $cache_key ] = $field;
257 +
258 + return $field;
259 +}
260 +
261 +function uwp_resend_activation_mail( $user_id ) {
262 +
263 + if ( ! $user_id ) {
264 + return false;
265 + }
266 +
267 + if ( 'email_unconfirmed' == get_user_meta( $user_id, 'uwp_mod', true ) ) {
268 + $user_data = get_userdata( $user_id );
269 +
270 + $activation_link = uwp_get_activation_link( $user_id );
271 +
272 + if ( $activation_link ) {
273 +
274 + $message = __( 'To activate your account, visit the following address:', 'userswp' ) . "\r\n\r\n";
275 +
276 + $message .= "<a href='" . esc_url( $activation_link ) . "' target='_blank'>" . esc_url( $activation_link ) . '</a>' . "\r\n";
277 +
278 + $activate_message = '<p><b>' . __( 'Please activate your account :', 'userswp' ) . '</b></p><p>' . $message . '</p>';
279 +
280 + $activate_message = apply_filters( 'uwp_activation_mail_message', $activate_message, $user_id );
281 +
282 + $email_vars = array(
283 + 'user_id' => $user_id,
284 + 'login_details' => $activate_message,
285 + 'activation_link' => $activation_link,
286 + );
287 +
288 + $send_result = UsersWP_Mails::send( $user_data->user_email, 'registration_activate', $email_vars );
289 +
290 + return $send_result;
291 + }
292 + }
293 +
294 + return true;
295 +}
296 +
297 +/**
298 + * Check font awesome icon or not.
299 + *
300 + * @param string $icon Font awesome icon.
301 + * @return bool True if font awesome icon.
302 + */
303 +function uwp_is_fa_icon( $icon ) {
304 + $return = false;
305 + if ( $icon != '' ) {
306 + $fa_icon = trim( $icon );
307 + if ( strpos( $fa_icon, 'fa fa-' ) === 0 || strpos( $fa_icon, 'fas fa-' ) === 0 || strpos( $fa_icon, 'far fa-' ) === 0 || strpos( $fa_icon, 'fab fa-' ) === 0 || strpos( $fa_icon, 'fa-' ) === 0 ) {
308 + $return = true;
309 + }
310 + }
311 + return apply_filters( 'uwp_is_fa_icon', $return, $icon );
312 +}
313 +
314 +/**
315 + * Check icon url.
316 + *
317 + * @param string $icon Icon url.
318 + * @return bool True if icon url.
319 + */
320 +function uwp_is_icon_url( $icon ) {
321 + $return = false;
322 + if ( $icon != '' ) {
323 + $icon = trim( $icon );
324 + if ( strpos( $icon, 'http://' ) === 0 || strpos( $icon, 'https://' ) === 0 ) {
325 + $return = true;
326 + }
327 + }
328 + return apply_filters( 'uwp_is_icon_url', $return, $icon );
329 +}
330 +
331 +/**
332 + * Get the field icon.
333 + *
334 + * @since 1.0.12
146 335 * @package userswp
147 336 *
148 - * @return string Form html.
337 + * @param string $value Field icon value.
338 + * @return string Field icon element.
149 339 */
150 -function uwp_display_form() {
340 +function uwp_get_field_icon( $value ) {
341 + $field_icon = $value;
151 342
152 - $page = isset( $_GET['page'] ) ? $_GET['page'] : 'userswp';
153 - $settings_array = uwp_get_settings_tabs();
343 + if ( ! empty( $value ) ) {
344 + if ( strpos( $value, 'http' ) === 0 ) {
345 + $field_icon = '<span class="uwp_field_icon" style="background: url(' . esc_url( $value ) . ') no-repeat left center;padding-left:14px;background-size:100% auto;margin-right:5px"></span>';
346 + } else {
347 + $field_icon = '<i class="uwp_field_icon ' . esc_attr( $value ) . '"></i>';
348 + }
349 + }
154 350
155 - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_array[$page] ) ? $_GET['tab'] : 'main';
156 - ob_start();
157 - ?>
158 - <form method="post" action="options.php">
159 - <?php
160 - $title = apply_filters('uwp_display_form_title', false, $page, $active_tab);
161 - if ($title) { ?>
162 - <h2 class="title"><?php echo $title; ?></h2>
163 - <?php } ?>
351 + return apply_filters( 'uwp_get_field_icon', $field_icon, $value );
352 +}
164 353
165 - <table class="uwp-form-table">
166 - <?php
167 - settings_fields( 'uwp_settings' );
168 - do_settings_fields( 'uwp_settings_' . $page .'_'.$active_tab, 'uwp_settings_' . $page .'_'.$active_tab );
169 - ?>
170 - </table>
171 - <?php submit_button(); ?>
172 - </form>
354 +function uwp_get_registration_form_actions() {
355 + $registration_options = array(
356 + 'auto_approve' => __( 'Auto Approve', 'userswp' ),
357 + 'auto_approve_login' => __( 'Auto Approve + Auto Login', 'userswp' ),
358 + 'require_email_activation' => __( 'Require Email Activation', 'userswp' ),
359 + );
173 360
174 - <?php
175 - $output = ob_get_contents();
176 - ob_end_clean();
361 + return apply_filters( 'uwp_registration_status_options', $registration_options );
362 +}
177 363
178 - return $output;
179 -}
364 +function uwp_get_register_forms_dropdown_options( $include_forms = array() ) {
365 +
366 + $get_register_form = uwp_get_option( 'multiple_registration_forms' );
367 +
368 + $register_forms = array();
369 +
370 + if ( ! empty( $get_register_form ) && is_array( $get_register_form ) ) {
371 + foreach ( $get_register_form as $key => $register_form ) {
372 + $form_id = ! empty( $register_form['id'] ) ? $register_form['id'] : '';
373 + if ( ! empty( $form_id ) && $form_id > 0 ) {
374 + $register_forms[ $form_id ] = ! empty( $register_form['title'] ) ? $register_form['title'] : '';
375 + }
376 + }
377 + }
378 +
379 + if ( ! empty( $register_forms ) && isset( $include_forms ) && count( $include_forms ) > 0 ) {
380 + foreach ( $register_forms as $form_id => $title ) {
381 + if ( ! in_array( $form_id, $include_forms ) ) {
382 + unset( $register_forms[ $form_id ] );
383 + }
384 + }
385 + }
386 +
387 + return $register_forms;
388 +}
389 +
390 +function uwp_get_register_form_by( $form_id, $type = 'title' ) {
391 +
392 + $form_title = '';
393 + if ( ! empty( $form_id ) && $form_id > 0 ) {
394 + $get_register_form = uwp_get_option( 'multiple_registration_forms' );
395 +
396 + if ( ! empty( $get_register_form ) && is_array( $get_register_form ) ) {
397 +
398 + foreach ( $get_register_form as $key => $register_form ) {
399 +
400 + if ( ! empty( $register_form['id'] ) && $register_form['id'] == $form_id ) {
401 +
402 + $form_title = ! empty( $register_form[ $type ] ) ? $register_form[ $type ] : '';
403 + }
404 + }
405 + }
406 + }
407 +
408 + return $form_title;
409 +}
410 +
411 +function uwp_get_form_id_by_type( $form_type ) {
412 + $form_id = 1;
413 + if ( isset( $form_type ) && ! empty( $form_type ) ) {
414 + $get_register_form = uwp_get_option( 'multiple_registration_forms' );
415 +
416 + if ( ! empty( $get_register_form ) && is_array( $get_register_form ) ) {
417 +
418 + foreach ( $get_register_form as $key => $register_form ) {
419 +
420 + if ( ! empty( $register_form['title'] ) && $form_type == sanitize_title_with_dashes( $register_form['title'] ) ) {
421 +
422 + $form_id = $register_form['id'];
423 + }
424 + }
425 + }
426 + }
427 +
428 + return $form_id;
429 +}
430 +
431 +function uwp_get_next_register_form_id() {
432 +
433 + global $wpdb;
434 +
435 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
436 + $fields = $wpdb->get_results( "SELECT MAX(`form_id`) AS last_added FROM `$extras_table_name`" );
437 + $last_added = ! empty( $fields['0']->last_added ) ? (int) $fields['0']->last_added : 1;
438 +
439 + $register_forms = uwp_get_option( 'multiple_registration_forms' );
440 + $register_form_ids = array();
441 + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
442 + foreach ( $register_forms as $key => $register_form ) {
443 + if ( ! empty( $register_form['id'] ) ) {
444 + $register_form_ids[] = $register_form['id'];
445 + }
446 + }
447 + }
448 +
449 + $form_max_id = ! empty( $register_form_ids ) ? max( $register_form_ids ) : 0;
450 +
451 + $next_form = max( $last_added, $form_max_id );
452 + $next_form = ! empty( $next_form ) ? $next_form + 1 : 0;
453 +
454 + return ! empty( $next_form ) ? $next_form : 1;
455 +}
456 +
457 +function uwp_get_register_form_id( $user_id ) {
458 +
459 + if ( empty( $user_id ) ) {
460 + return 1;
461 + }
462 +
463 + $form_id = get_user_meta( $user_id, '_uwp_register_form_id', true );
464 +
465 + return ! empty( $form_id ) ? (int) $form_id : 1;
466 +}
467 +
468 +/**
469 + * Get user regsitration form by form ID.
470 + *
471 + * @param int $form_id The ID of the registration form.
472 + * @return array|false The user type array if found, false otherwise.
473 + */
474 +function uwp_get_user_register_form( int $form_id ) {
475 + $register_forms = (array) UsersWP_User_Types::get_register_forms();
476 +
477 + foreach ( $register_forms as $register_form ) {
478 + if ( isset( $register_form['id'] ) && (int) $register_form['id'] === (int) $form_id ) {
479 + return $register_form;
480 + }
481 + }
482 +
483 + return false;
484 +}
485 +
486 +function uwp_get_register_fields_htmlvar( $form_id = 1 ) {
487 +
488 + $fields = get_register_form_fields( $form_id );
489 +
490 + $html_var = array();
491 +
492 + if ( ! empty( $fields ) && is_array( $fields ) ) {
493 +
494 + foreach ( $fields as $key => $field ) {
495 +
496 + if ( ! empty( $field->htmlvar_name ) ) {
497 +
498 + $html_var[] = $field->htmlvar_name;
499 + }
500 + }
501 + }
502 +
503 + return $html_var;
504 +}
505 +
506 +function uwp_get_unique_custom_fields( $fields, $key = 'htmlvar_name' ) {
507 + if ( empty( $fields ) ) {
508 + return array();
509 + }
510 +
511 + $temp_array = array();
512 + $i = 0;
513 + $key_array = array();
514 +
515 + foreach ( $fields as $field ) {
516 + if ( is_object( $field ) ) {
517 + $val = $field->$key;
518 + } else {
519 + $val = $field[ $key ];
520 + }
521 +
522 + if ( ! in_array( $val, $key_array ) ) {
523 + $key_array[ $i ] = $val;
524 + $temp_array[ $val ] = $field;
525 + }
526 + ++$i;
527 + }
528 +
529 + return $temp_array;
530 +}
531 +
532 +function uwp_get_default_form_data() {
533 + $fields = array();$i = 1;
534 + $user_role = get_option( 'default_role' );
535 +
536 + $account_fields = UsersWP_Activator::uwp_default_custom_fields_account();
537 + if ( ! empty( $account_fields ) ) {
538 + foreach ( $account_fields as $account_field ) {
539 + $fields[ $account_field['htmlvar_name'] ] = $i;
540 + ++$i;
541 + }
542 + }
543 +
544 + $reg_fields = get_register_form_fields();
545 +
546 + if ( ! empty( $reg_fields ) && is_array( $reg_fields ) ) {
547 + foreach ( $reg_fields as $key => $field ) {
548 + if ( isset( $field->htmlvar_name ) && ! empty( $field->htmlvar_name ) && $field->htmlvar_name == 'user_role' && ! empty( $field->option_values ) ) {
549 + $user_role = $field->option_values;
550 + $obj = new UsersWP_Form_Builder();
551 + $obj->admin_form_field_delete( $field->id, true, 1 );
552 + }
553 + }
554 + }
555 +
556 + $data = array(
557 + array(
558 + 'id' => 1,
559 + 'title' => __( 'Default', 'userswp' ),
560 + 'user_role' => $user_role,
561 + 'reg_action' => uwp_get_option( 'uwp_registration_action', 'auto_approve' ),
562 + 'redirect_to' => (int) uwp_get_option( 'register_redirect_to', - 1 ),
563 + 'custom_url' => uwp_get_option( 'register_redirect_custom_url', home_url() ),
564 + 'gdpr_page' => (int) uwp_get_option( 'register_gdpr_page', false ),
565 + 'tos_page' => (int) uwp_get_option( 'register_terms_page', false ),
566 + 'fields' => $fields,
567 + ),
568 + );
569 +
570 + return $data;
571 +}
572 +
573 +function uwp_get_upload_image_size( $type = 'avatar' ) {
574 +
575 + if ( $type == 'avatar' ) {
576 + $width = uwp_get_option( 'profile_avatar_width', 150 );
577 + $width = empty( $width ) ? 150 : $width;
578 + $value['width'] = apply_filters( 'uwp_avatar_image_width', $width );
579 +
580 + $height = uwp_get_option( 'profile_avatar_height', 150 );
581 + $height = empty( $height ) ? 150 : $height;
582 + $value['height'] = apply_filters( 'uwp_avatar_image_height', $height );
583 + } else {
584 + $width = uwp_get_option( 'profile_banner_width', 1000 );
585 + $width = empty( $width ) ? 1000 : $width;
586 + $value['width'] = apply_filters( 'uwp_banner_image_width', $width );
587 +
588 + $height = uwp_get_option( 'profile_banner_height', 300 );
589 + $height = empty( $height ) ? 300 : $height;
590 + $value['height'] = apply_filters( 'uwp_banner_image_height', $height );
591 + }
592 +
593 + return $value;
594 +}