admin_created_user_email( string $text ): string

Parameters

$textstringrequired

Return

string

Source

function admin_created_user_email( $text ) {
	$roles = get_editable_roles();
	$role  = $roles[ $_REQUEST['role'] ];

	if ( '' !== get_bloginfo( 'name' ) ) {
		$site_title = wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
	} else {
		$site_title = parse_url( home_url(), PHP_URL_HOST );
	}

	return sprintf(
		/* translators: 1: Site title, 2: Site URL, 3: User role. */
		__(
			'Hi,
You\'ve been invited to join \'%1$s\' at
%2$s with the role of %3$s.
If you do not want to join this site please ignore
this email. This invitation will expire in a few days.

Please click the following link to activate your user account:
%%s'
		),
		$site_title,
		home_url(),
		wp_specialchars_decode( translate_user_role( $role['name'] ) )
	);
}

Changelog

VersionDescription
MU (3.0.0)Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The admin_created_user_email function appears to be designed to generate the content for an email that is sent to a user when they are invited to join a WordPress site with a specific user role. Here’s what this function does in more detail:

    It retrieves a list of editable user roles on the WordPress site using the get_editable_roles() function and stores them in the $roles variable.

    It extracts the specific user role information based on a role key provided in the $_REQUEST array. This allows you to specify the user role when sending the invitation. The role information is stored in the $role variable.

    It determines the site title ($site_title) that will be included in the email. If the site has a name, it uses that name (decoded to handle special characters). If the site does not have a name, it uses the host part of the site’s URL.

    It constructs an email message template using sprintf() and the __() function for internationalization and translation purposes. The message includes placeholders for the site title, site URL, and user role.

    %1$s is a placeholder for the site title ($site_title).
    %2$s is a placeholder for the site’s URL (retrieved using home_url() ).
    %3$s is a placeholder for the user’s role name (after decoding special characters using wp_specialchars_decode() ) and translating the role name using translate_user_role() .
    The function returns the formatted email message as a string.

    It’s important to note that this function is responsible for generating the email content only; it doesn’t send the email itself. The actual sending of the email is typically handled elsewhere in your WordPress application, using functions like wp_mail() or a similar email sending mechanism. This function is intended to be used as part of a larger process for inviting users to your WordPress site with specific roles.

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