Using WordPress ‘new_admin_email_content’ PHP filter

new_admin_email_content is a WordPress PHP filter that modifies the content of the email sent when an attempt is made to change the site admin email address.

Note: The following strings will get replaced dynamically:

  • USERNAME### The current user’s username.
  • ADMIN_URL### The link to click on to confirm the email change.
  • EMAIL### The proposed new site admin email address.
  • SITENAME### The name of the site.
  • SITEURL### The URL to the site.

Usage

add_filter('new_admin_email_content', 'your_custom_function_name', 10, 2);

function your_custom_function_name($email_text, $new_admin_email) {
    // your custom code here
    return $email_text;
}

Parameters

  • $email_text (string) – The text content of the email.
  • $new_admin_email (array) – An array containing the new site admin email address data.
    • hash (string) – The secure hash used in the confirmation link URL.
    • newemail (string) – The proposed new site admin email address.

Examples

Change the greeting text in the email

add_filter('new_admin_email_content', 'change_greeting_text', 10, 2);

function change_greeting_text($email_text, $new_admin_email) {
    $email_text = str_replace('Hi', 'Hello', $email_text);
    return $email_text;
}

This code replaces the “Hi” greeting in the email with “Hello”.

Add a custom signature to the email

add_filter('new_admin_email_content', 'add_custom_signature', 10, 2);

function add_custom_signature($email_text, $new_admin_email) {
    $signature = "\n\nBest regards,\nYour Team";
    $email_text .= $signature;
    return $email_text;
}

This code appends a custom signature to the email.

Add a timestamp to the email

add_filter('new_admin_email_content', 'add_timestamp_to_email', 10, 2);

function add_timestamp_to_email($email_text, $new_admin_email) {
    $timestamp = "\n\nTimestamp: " . date('Y-m-d H:i:s');
    $email_text .= $timestamp;
    return $email_text;
}

This code adds a timestamp at the end of the email.

add_filter('new_admin_email_content', 'change_confirmation_link_text', 10, 2);

function change_confirmation_link_text($email_text, $new_admin_email) {
    $old_text = 'Click here to confirm the change';
    $new_text = 'Confirm your new email address by clicking here';
    $email_text = str_replace($old_text, $new_text, $email_text);
    return $email_text;
}

This code changes the confirmation link text in the email.

Add a custom message based on the new email domain

add_filter('new_admin_email_content', 'add_custom_message', 10, 2);

function add_custom_message($email_text, $new_admin_email) {
    $new_email_domain = substr(strrchr($new_admin_email['newemail'], "@"), 1);
    if ($new_email_domain == 'example.com') {
        $message = "\n\nP.S. We noticed you're using an example.com email address!";
        $email_text .= $message;
    }
    return $email_text;
}

This code adds a custom message to the email if the new email address has a specific domain (e.g., example.com).