LLMS_Person_Handler::generate_username( string $email )

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


Description Description


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 ) {

		/**
		 * Provide a custom username generation function
		 *
		 * If this filter returns a string, that string will be used for the student's username
		 * rather than the username automatically generated by LifterLMS.
		 *
		 * @since Unknown
		 *
		 * @param null|string $username A `null` value will cause a username to be generated, otherwise the value will be used as the username.
		 * @param string      $email    The user's email address.
		 */
		$custom_username = apply_filters( 'lifterlms_generate_username', null, $email );
		if ( $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++;

		}

		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.