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
1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 | 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.