Using WordPress ‘admin_created_user_email()’ PHP function

The admin_created_user_email() WordPress PHP function is used to generate a notification email text for new users created by an administrator.

Usage

Here’s an example of how to use the function:

// Set up the notification text
$notification_text = "Welcome to our website! Your account has been created by our admin.";

// Use the function to generate the notification email
admin_created_user_email($notification_text);

In this example, “Welcome to our website! Your account has been created by our admin.” would be the content of the email sent to the new user.

Parameters

  • $text (string): This is the text that will be sent in the notification email to the new user.

More information

See WordPress Developer Resources: admin_created_user_email()
The admin_created_user_email() function was introduced in WordPress 5.7.0.

Examples

Basic Usage

In this example, we use the admin_created_user_email() function to create a simple welcome message for a new user.

$text = "Welcome! Your account has been successfully created by our admin.";
admin_created_user_email($text);

The output will be an email with the text: “Welcome! Your account has been successfully created by our admin.”

Including the Website Name

Here, we include the website’s name in the welcome message.

$site_name = get_bloginfo('name');
$text = "Welcome to " . $site_name . "! Your account is now active.";
admin_created_user_email($text);

The output will be an email with the text: “Welcome to [website name]! Your account is now active.”

Adding More Details

In this example, we add more details to the welcome message, such as the website’s URL.

$site_name = get_bloginfo('name');
$site_url = get_bloginfo('url');
$text = "Welcome to " . $site_name . "! You can log in at: " . $site_url;
admin_created_user_email($text);

The output will be an email with the text: “Welcome to [website name]! You can log in at: [website url]”.

Adding Personalization

Here, we add the new user’s username to personalize the welcome message.

$new_user = "John";
$text = "Hi " . $new_user . ", your account is ready for you to start exploring.";
admin_created_user_email($text);

The output will be an email with the text: “Hi John, your account is ready for you to start exploring.”

Including Contact Information

In this example, we include the admin’s contact information in case the new user has any questions.

$admin_email = get_option('admin_email');
$text = "If you have any questions, feel free to contact our admin at: " . $admin_email;
admin_created_user_email($text);

The output will be an email with the text: “If you have any questions, feel free to contact our admin at: [admin email]”.