| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | |
| 11 | 11 | $input_value = ( ( trim( $input_value ) == '' ) ? $field['default-value'] : $input_value ); |
| 12 | 12 | |
| 13 | 13 | $input_value = ( isset( $request_data['username'] ) ? trim( $request_data['username'] ) : $input_value ); |
| 14 | + $input_value = apply_filters( 'wppb_form_username_field_value', $input_value, $field, $form_location ); | |
| 14 | 15 | |
| 15 | 16 | if ( $form_location != 'back_end' ){ |
| 16 | 17 | $error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' ); |
| 17 | 18 | |
| @@ -23,9 +24,9 @@ | ||
| 23 | 24 | $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); |
| 24 | 25 | |
| 25 | 26 | $output = ' |
| 26 | 27 | <label for="username">'.$item_title.$error_mark.'</label> |
| 27 | - <input class="text-input default_field_username '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" name="username" maxlength="'. apply_filters( 'wppb_maximum_character_length', 70, $field ) .'" type="text" id="username" value="'. esc_attr( $input_value ) .'" '.$readonly.' '. $extra_attr .'/>'; | |
| 28 | + <input class="text-input default_field_username '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" name="username" maxlength="'. apply_filters( 'wppb_maximum_character_length', 60, $field ) .'" type="text" id="username" value="'. esc_attr( $input_value ) .'" '.$readonly.' '. $extra_attr .'/>'; | |
| 28 | 29 | if( !empty( $item_description ) ) |
| 29 | 30 | $output .= '<span class="wppb-description-delimiter">'.$item_description.'</span>'; |
| 30 | 31 | } |
| 31 | 32 | |
| @@ -52,8 +53,12 @@ | ||
| 52 | 53 | } |
| 53 | 54 | if (!validate_username($request_data['username'])) { |
| 54 | 55 | return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '<br/>' . __('Please enter a valid username.', 'profile-builder'); |
| 55 | 56 | } |
| 57 | + // WordPress core rejects usernames longer than 60 characters in wp_insert_user(). | |
| 58 | + if ( mb_strlen( sanitize_user( trim( $request_data['username'] ) ) ) > 60 ) { | |
| 59 | + return __( 'This username is too long. It must be 60 characters or fewer.', 'profile-builder' ); | |
| 60 | + } | |
| 56 | 61 | } |
| 57 | 62 | |
| 58 | 63 | $wppb_generalSettings = get_option('wppb_general_settings'); |
| 59 | 64 | if ( isset($wppb_generalSettings['emailConfirmation']) && $wppb_generalSettings['emailConfirmation'] == 'yes' ){ |
| @@ -61,9 +66,12 @@ | ||
| 61 | 66 | if( is_multisite() && $request_data['username'] != preg_replace( '/\s+/', '', $request_data['username'] ) ){ |
| 62 | 67 | return __( 'This username is invalid because it uses illegal characters.', 'profile-builder' ) .'<br/>'. __( 'Please enter a valid username.', 'profile-builder' ); |
| 63 | 68 | } |
| 64 | 69 | |
| 65 | - $userSignup = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."signups WHERE user_login = %s", $request_data['username'] ) ); | |
| 70 | + // Only pending signup rows should reserve a username during Email Confirmation | |
| 71 | + // - activated rows can remain in the signups table after confirmation, so they must not block a new registration | |
| 72 | + // - this keeps the username reservation check aligned with the email reservation check, which also only considers pending signups | |
| 73 | + $userSignup = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."signups WHERE user_login = %s AND active = 0", $request_data['username'] ) ); | |
| 66 | 74 | if ( !empty( $userSignup ) ){ |
| 67 | 75 | return __( 'This username is already reserved to be used soon.', 'profile-builder') .'<br/>'. __( 'Please try a different one!', 'profile-builder' ); |
| 68 | 76 | } |
| 69 | 77 | } |