0

In a multisite network, when you change the main email address in Settings / General, Wordpress sends an email that must be confirmed by the new email recipient.

I need to avoid or customize the message that is being sent but can't figure out how.

The function responsible for sending this email is not pluggable, as show bellow:

/**
 * Sends an email when a site administrator email address is changed.
 *
 * @since 3.0.0
 *
 * @param string $old_value The old email address. Not currently used.
 * @param string $value     The new email address.
 */
function update_option_new_admin_email( $old_value, $value ) {
    if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
        return;

    $hash = md5( $value. time() .mt_rand() );
    $new_admin_email = array(
        'hash' => $hash,
        'newemail' => $value
    );
    update_option( 'adminhash', $new_admin_email );

    $email_text = __( 'Dear user,

You recently requested to have the administration email address on
your site changed.
If this is correct, please click on the following link to change it:
###ADMIN_URL###

You can safely ignore and delete this email if you do not want to
take this action.

This email has been sent to ###EMAIL###

Regards,
All at ###SITENAME###
###SITEURL###' );

This function continues and have a few filters to change some vars, but no way to customise the message itself.

Do you know any way to avoid this notification from being necessary in multisite, or at least to be able to override the message it sends?

  • 1
    Have you even looked at the docs for this function? It tells you exactly how to do what you have asked... – David Gard Mar 4 '15 at 13:51
  • Boy how upset I got by your comment but you're absolutely right, not sure how i've missed that but I probably by the many tabs I had open at the time, including some related to other email notification functions. Thanks calling me to reason on this. Cheers. – Luis Martins Mar 4 '15 at 14:16
  • Turns out the documentation is incorrect or outdated. It is marked with "needs update" and after trying the solution mentioned there I confirmed it actually doesn't work. – Luis Martins Mar 6 '15 at 10:24
  • I've edited your answer and it should now work. The example from the Codex had omitted the $priority and $accepted_args parameters, which are required if instance of do_action() passes more than two parameters. – David Gard Mar 6 '15 at 11:00
  • Thanks again David,the review seems to be delayed. If you want to add your own answer I would be more than happy to give you the stackexchange "karma" by accepting it as correct. – Luis Martins Mar 6 '15 at 16:33
1

It seems that my edit to your answer was declined, so here you go.

All that was missing was the $priority and $accepted_args parameters for the add_action() calls, and the the fixed code below should accomplish what you require.

remove_action( 'add_option_new_admin_email', 'update_option_new_admin_email' );
remove_action( 'update_option_new_admin_email', 'update_option_new_admin_email' );

/**
 * Disable the confirmation notices when an administrator
 * changes their email address.
 *
 * @see http://codex.wordpress.com/Function_Reference/update_option_new_admin_email
 */
function wpdocs_update_option_new_admin_email( $old_value, $value ) {

    update_option( 'admin_email', $value );
}
add_action( 'add_option_new_admin_email', 'wpdocs_update_option_new_admin_email', 10, 2 );
add_action( 'update_option_new_admin_email', 'wpdocs_update_option_new_admin_email', 10, 2 );
0

As indicated by @David Gard, this can easily be done:

<?php

remove_action( 'add_option_new_admin_email', 'update_option_new_admin_email' );
remove_action( 'update_option_new_admin_email', 'update_option_new_admin_email' );

/**
 * Disable the confirmation notices when an administrator
 * changes their email address.
 *
 * @see http://codex.wordpress.com/Function_Reference/update_option_new_admin_email
 */
function wpdocs_update_option_new_admin_email( $old_value, $value ) {

    update_option( 'admin_email', $value );
}
add_action( 'add_option_new_admin_email', 'wpdocs_update_option_new_admin_email' );
add_action( 'update_option_new_admin_email', 'wpdocs_update_option_new_admin_email' );

?>

EDIT: The Codex documentation is marked as "Needs Update" and I've confirmed it doesn't work in the current form.

  • My edit is just being reviewed and should be available to you shortly. I am trying to update the Codex as well, but apparently I don't have permission to do that. – David Gard Mar 6 '15 at 11:24
  • I was able to update the codex info, you might need to check what's going with your wordpress account. – Luis Martins Mar 7 '15 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.