*' : '' ); if ( array_key_exists( $field['id'], $field_check_errors ) ) $error_mark = ''; $readonly = ( ( $form_location == 'edit_profile' ) ? ' disabled="disabled"' : '' ); $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location ); $output = ' '; if( !empty( $item_description ) ) $output .= ''.$item_description.''; } return apply_filters( 'wppb_'.$form_location.'_username', $output, $form_location, $field, $user_id, $field_check_errors, $request_data ); } add_filter( 'wppb_output_form_field_default-username', 'wppb_username_handler', 10, 6 ); /* handle field validation */ function wppb_check_username_value( $message, $field, $request_data, $form_location ){ global $wpdb; if( $field['required'] == 'Yes' ){ if( ( isset( $request_data['username'] ) && ( trim( $request_data['username'] ) == '' ) ) || ( $form_location == 'register' && !isset( $request_data['username'] ) ) ){ return wppb_required_field_error($field["field-title"]); } } if( !empty( $request_data['username'] ) ){ if( $form_location == 'register' ) { if( username_exists($request_data['username'] ) ){ return __('This username already exists.', 'profile-builder') . '
' . __('Please try a different one!', 'profile-builder'); } if (!validate_username($request_data['username'])) { return __('This username is invalid because it uses illegal characters.', 'profile-builder') . '
' . __('Please enter a valid username.', 'profile-builder'); } } $wppb_generalSettings = get_option('wppb_general_settings'); if ( $wppb_generalSettings['emailConfirmation'] == 'yes' ){ if( is_multisite() && $request_data['username'] != preg_replace( '/\s+/', '', $request_data['username'] ) ){ return __( 'This username is invalid because it uses illegal characters.', 'profile-builder' ) .'
'. __( 'Please enter a valid username.', 'profile-builder' ); } $userSignup = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM ".$wpdb->prefix."signups WHERE user_login = %s", $request_data['username'] ) ); if ( !empty( $userSignup ) ){ return __( 'This username is already reserved to be used soon.', 'profile-builder') .'
'. __( 'Please try a different one!', 'profile-builder' ); } } } return $message; } add_filter( 'wppb_check_form_field_default-username', 'wppb_check_username_value', 10, 4 ); /* handle field save */ function wppb_userdata_add_username( $userdata, $global_request ){ if ( isset( $global_request['username'] ) ) $userdata['user_login'] = sanitize_user( trim( $global_request['username'] ) ); return $userdata; } add_filter( 'wppb_build_userdata', 'wppb_userdata_add_username', 10, 2 );