LLMS_Person_Handler::generate_username( string $email )

Generate a unique login based on the user’s email address


Parameters Parameters

$email

(string) (Required) User's email address.


Top ↑

Return Return

(string)


Top ↑

Source Source

File: includes/class.llms.person.handler.php

	public static function generate_username( $email ) {

		/**
		 * Allow custom username generation
		 *
		 * @since 3.0.0
		 *
		 * @param string $custom_username The custom-generated username. If the filter returns a truthy string it will be used in favor
		 *                                of the automatically generated username.
		 * @param string $email           User's email address.
		 */
		$custom_username = apply_filters( 'lifterlms_generate_username', null, $email );
		if ( $custom_username && is_string( $custom_username ) ) {
			return $custom_username;
		}

		$username      = sanitize_user( current( explode( '@', $email ) ), true );
		$orig_username = $username;
		$i             = 1;
		while ( username_exists( $username ) ) {

			$username = $orig_username . $i;
			$i++;

		}

		/**
		 * Modify an auto-generated username before it is used
		 *
		 * @since 3.0.0
		 *
		 * @param string $username The generated user name.
		 * @param string $email    User's email address which was used to generate the username.
		 */
		return apply_filters( 'lifterlms_generated_username', $username, $email );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.19.4 Unknown.
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.