bp_core_validate_user_signup( string $user_name, string $user_email )
Validate a user name and email address when creating a new user.
Description
Parameters
- $user_name
-
(Required) Username to validate.
- $user_email
-
(Required) Email address to validate.
Return
(array) Results of user validation including errors, if any.
Source
File: bp-members/bp-members-functions.php
function bp_core_validate_user_signup( $user_name, $user_email ) { // Make sure illegal names include BuddyPress slugs and values. bp_core_flush_illegal_names(); // WordPress Multisite has its own validation. Use it, so that we // properly mirror restrictions on username, etc. if ( function_exists( 'wpmu_validate_user_signup' ) ) { $result = wpmu_validate_user_signup( $user_name, $user_email ); // When not running Multisite, we perform our own validation. What // follows reproduces much of the logic of wpmu_validate_user_signup(), // minus the multisite-specific restrictions on user_login. } else { $errors = new WP_Error(); /** * Filters the username before being validated. * * @since BuddyPress 1.5.5 * * @param string $user_name Username to validate. */ $user_name = apply_filters( 'pre_user_login', $user_name ); // User name can't be empty. if ( empty( $user_name ) ) { $errors->add( 'user_name', __( 'Please enter a username', 'buddyboss' ) ); } // User name can't be on the blacklist. $illegal_names = get_site_option( 'illegal_names' ); if ( in_array( $user_name, (array) $illegal_names ) ) { $errors->add( 'user_name', __( 'That username is not allowed', 'buddyboss' ) ); } // User name must pass WP's validity check. if ( ! validate_username( $user_name ) ) { $errors->add( 'user_name', __( 'Usernames can contain only letters, numbers, ., -, and @', 'buddyboss' ) ); } // Minimum of 4 characters. if ( strlen( $user_name ) < 4 ) { $errors->add( 'user_name', __( 'Username must be at least 4 characters', 'buddyboss' ) ); } // No underscores. @todo Why not? if ( false !== strpos( ' ' . $user_name, '_' ) ) { $errors->add( 'user_name', __( 'Sorry, usernames may not contain the character "_"!', 'buddyboss' ) ); } // No usernames that are all numeric. @todo Why? $match = array(); preg_match( '/[0-9]*/', $user_name, $match ); if ( $match[0] == $user_name ) { $errors->add( 'user_name', __( 'Sorry, usernames must have letters too!', 'buddyboss' ) ); } // Check into signups. $signups = BP_Signup::get( array( 'user_login' => $user_name, ) ); $signup = isset( $signups['signups'] ) && ! empty( $signups['signups'][0] ) ? $signups['signups'][0] : false; // Check if the username has been used already. if ( username_exists( $user_name ) || ! empty( $signup ) ) { $errors->add( 'user_name', __( 'Sorry, that username already exists!', 'buddyboss' ) ); } // Validate the email address and process the validation results into // error messages. $validate_email = bp_core_validate_email_address( $user_email ); bp_core_add_validation_error_messages( $errors, $validate_email ); // Assemble the return array. $result = array( 'user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors, ); // Apply WPMU legacy filter. $result = apply_filters( 'wpmu_validate_user_signup', $result ); } /** * Filters the result of the user signup validation. * * @since BuddyPress 1.2.2 * * @param array $result Results of user validation including errors, if any. */ return apply_filters( 'bp_core_validate_user_signup', $result ); }
Changelog
Version | Description |
---|---|
BuddyPress 1.2.2 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.