| 1 |
<?php |
| 2 |
/** |
| 3 |
* Returns the register form fields. |
| 4 |
* |
| 5 |
* @return array Form fields. |
| 6 |
* @package userswp |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 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 |
} |
| 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 |
|
| 39 |
/** |
| 40 |
* Returns the register form validate-able fields. |
| 41 |
* |
| 42 |
* @param int $form_id Form ID Default 1. |
| 43 |
* |
| 44 |
* @return array Validate-able fields. |
| 45 |
* @since 1.0.0 |
| 46 |
* @package userswp |
| 47 |
* |
| 48 |
*/ |
| 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 ); |
| 55 |
|
| 56 |
return $fields; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Returns the change password form validate-able fields. |
| 61 |
* |
| 62 |
* @return array Validate-able fields |
| 63 |
* @package userswp |
| 64 |
* |
| 65 |
* @since 1.0.0 |
| 66 |
*/ |
| 67 |
function get_change_validate_form_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; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Returns the account form fields. |
| 86 |
* |
| 87 |
* @param string $extra_where Extra where query. |
| 88 |
* |
| 89 |
* @return array Form fields. |
| 90 |
* @since 1.0.0 |
| 91 |
* @package userswp |
| 92 |
* |
| 93 |
*/ |
| 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; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Returns the change password form fields. |
| 111 |
* |
| 112 |
* @return array Form fields. |
| 113 |
* @package userswp |
| 114 |
* |
| 115 |
* @since 1.0.0 |
| 116 |
*/ |
| 117 |
function get_change_form_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; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* Validates the submitted form data. |
| 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. |
| 143 |
* @since 1.0.0 |
| 144 |
* @package userswp |
| 145 |
* |
| 146 |
*/ |
| 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 ); |
| 151 |
} |
| 152 |
|
| 153 |
/** |
| 154 |
* Returns form field label. If empty returns the field title. |
| 155 |
* |
| 156 |
* @param object $field Field info. |
| 157 |
* |
| 158 |
* @return string Label. |
| 159 |
* @since 1.0.0 |
| 160 |
* @package userswp |
| 161 |
* |
| 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. |
| 175 |
* |
| 176 |
* @param object $field Field info. |
| 177 |
* |
| 178 |
* @return string Label. |
| 179 |
*/ |
| 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…', '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 ); |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Returns description for field. |
| 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 |
* |
| 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 |
| 335 |
* @package userswp |
| 336 |
* |
| 337 |
* @param string $value Field icon value. |
| 338 |
* @return string Field icon element. |
| 339 |
*/ |
| 340 |
function uwp_get_field_icon( $value ) { |
| 341 |
$field_icon = $value; |
| 342 |
|
| 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 |
} |
| 350 |
|
| 351 |
return apply_filters( 'uwp_get_field_icon', $field_icon, $value ); |
| 352 |
} |
| 353 |
|
| 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 |
); |
| 360 |
|
| 361 |
return apply_filters( 'uwp_registration_status_options', $registration_options ); |
| 362 |
} |
| 363 |
|
| 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 |
} |
| 595 |
|