Using WordPress ‘confirm_user_signup()’ PHP function

The confirm_user_signup() WordPress PHP function displays a message confirming that a new user has been successfully registered and is pending activation.

Usage

confirm_user_signup('johndoe', '[email protected]');

In this example, ‘johndoe’ is the username and ‘[email protected]’ is the user’s email. The function will generate a confirmation message for this user.

Parameters

  • $user_name (string) – This is the username of the new user. It’s a required parameter.
  • $user_email (string) – This is the email address of the new user. It’s also required.

More information

See WordPress Developer Resources: confirm_user_signup()
This function is part of the WordPress core and is typically used during the user registration process.

Examples

Basic usage

// Call the function with a username and email
confirm_user_signup('alice', '[email protected]');

This will display a confirmation message for the user ‘alice’ with the email ‘[email protected]’.

User signup in a registration form

// Assume we have a form submission with 'username' and 'email' fields
$username = $_POST['username'];
$email = $_POST['email'];

// Confirm the user signup
confirm_user_signup($username, $email);

This code snippet would typically be placed in the form handling part of your registration process.

Multiple user signups

// An array of users
$users = [
  ['bob', '[email protected]'],
  ['charlie', '[email protected]'],
  ['david', '[email protected]']
];

// Loop through the array and confirm each user signup
foreach ($users as $user) {
  confirm_user_signup($user[0], $user[1]);
}

This example confirms multiple user signups. It loops through an array of users, each represented as an array with a username and email, and confirms each user signup.

Conditional user signup

// Assume we have a user's username and email, and a condition
$username = 'eve';
$email = '[email protected]';
$condition = true; // This is just an example. Your condition might be different.

// Confirm the user signup only if the condition is true
if ($condition) {
  confirm_user_signup($username, $email);
}

This example shows how you can conditionally confirm a user signup.

User signup with a random username

// Function to generate a random username
function generate_random_username() {
  return 'user' . rand(1000, 9999);
}

// Generate a random username
$username = generate_random_username();

// Assume we have a user's email
$email = '[email protected]';

// Confirm the user signup
confirm_user_signup($username, $email);

This example demonstrates how you might handle user signup for a randomly generated username.