noptin_generate_user_name( string $prefix = '' )
Generates a unique username for new users.
Parameters Parameters
- $prefix
(string) (Optional) The prefix to use for the generated user name.
Default value: ''
Return Return
(string.)
Source Source
File: includes/subscriber.php
function noptin_generate_user_name( $prefix = '' ) { // If prefix is an email, retrieve the part before the email. $prefix = strtolower( trim( strtok( $prefix, '@' ) ) ); // Remove whitespace. $prefix = preg_replace( '|\s+|', '_', $prefix ); // Trim to 8 characters max. $prefix = sanitize_user( $prefix ); // phpcs:ignore Generic.Commenting.DocComment.MissingShort /** @ignore */ $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() ); if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) { $prefix = 'noptin'; } $username = $prefix; if ( username_exists( $username ) ) { $prefix = $prefix . zeroise( wp_rand( 0, 9999 ), 4 ); return noptin_generate_user_name( $prefix ); } /** * Filters an autogenerated user_name. * * @since 1.2.3 * @param string $prefix A prefix for the user name. Can be any string including an email address. */ return apply_filters( 'noptin_generate_user_name', $prefix ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.2.3 | Introduced. |