Home » Php » php – How to change main admin email address in WordPress without notification and confirmation processes

php – How to change main admin email address in WordPress without notification and confirmation processes

Posted by: admin April 23, 2020 Leave a comment

Questions:

I have created one site in staging server I want to change admin email address for that staging site.
Because I want to test something on staging site at that time, and I want that no email is being sent to client (original admin email), I want to change main admin email.

But when I change admin email I get confirmation link on to my new admin email address.

The Admin email address won’t change until I click on the link in the confirmation email.

After I click on the confirmation link, the original admin is receiving notice of Admin Email Change.

I want to disable notice of Admin Email Change and also new Admin Email Address confirmation link in WordPress.

How I do that? Could you please help me? Is there any code for this?

enter image description here

How to&Answers:

There is a ‘secret’ settings page which lets you change all of the settings in the options table.

Access it by changing the URL from /options-general.php to /options.php

Answer:

The one that you are trying to replace is actually the email in WordPress settings, not the wp user email. That one can be changed directly in database in the table wp_options where option_name is admin_email

Or with the given update query:

UPDATE `wp_options` SET `option_value` = '[email protected]' WHERE `option_name` = 'admin_email';

Answer:

There are few ways to change admin email without using a 3rd party plugin.

Also, besides admin_email, there is another value that needs to be changed.
No matter that you change admin_email value in DB, a confirmation notice will remain,
unless you change new_admin_email too.

Updating via the database:

In case of updating option via DB directly, there are two options that need to be changed: admin_email and new_admin_email.

UPDATE wp_options SET option_value = '[email protected]' WHERE 
option_name LIKE 'admin_email' 
OR 
option_name LIKE 'new_admin_email';

note: While by default every WordPress database has wp_ prefix for its tables, they can be changed, so check in wp-config.php for $table_prefix value.

Updating via options.php:

Another way without the use of some plugin is as mentioned accessing secret page /wp-admin/options.php. However, there might be too many options, and due to a number of $_POST variables limit set for each server differently, having it quite impossible to change it that way.

See more about max_input_vars
https://www.php.net/manual/en/info.configuration.php

Updating via functions.php in active theme:

You could set one time code (and delete it after) in functions.php of your active theme to update these options:

update_option( 'admin_email', '[email protected]' );

and

update_option( 'new_admin_email', '[email protected]' ); 

Put these within some admin_init action callback.

Updating via wp-cli:

Another way to update Admin email is via wp-cli ( if you have access to terminal ssh):

wp option update admin_email '[email protected]'

and

wp option update new_admin_email '[email protected]'

see more about wp option commands:

https://developer.wordpress.org/cli/commands/option/update/

Answer:

Note: Get dump and try it on local first. Don’t test in production.

Change with DB

//email
UPDATE `wp_users` SET `user_email` = "new_email_address" WHERE `wp_users`.`user_login` = "admin";

//password
UPDATE `wp_users` SET `user_pass` = MD5('new_password_here') WHERE `wp_users`.`user_login` = "admin";

Check This too

Answer:

Easier to use phpMyAdmin

wp_options > admin_email

Answer:

You have to enter mysql server

and run the following query

UPDATE `wp_options` SET `option_value` = '[email protected]' WHERE `option_id` = 6;

Answer:

Run this query, This will change the email id without any confirmation

UPDATE `wp_users` SET `user_email` = 'newemail' WHERE `user_email` = 'old_email';

Answer:

I had the same problem so I wrote a plugin to rollback the confirmation link feature. You can download it on the .org repo:

Change Admin Email Setting Without Outbound Email

Here is the code:

<?php
/*
 Plugin Name: Change Admin Email Setting Without Outbound Email
 Plugin URI: https://wp-bdd.com/change-admin-email/
 Description: Restores functionality removed since WordPress 4.9. Allows the changing of the admin email by admins in single site without outbound email or recipient email credentials.
 Version: 1.0
 Author: John Dee
 Author URI: https://wp-bdd.com/
*/

$ChangeAdminEmailPlugin = new ChangeAdminEmailPlugin;

class ChangeAdminEmailPlugin{

    public function __construct(){

        //This plugin doesn't do anything unless it's WordPres version +4.9 and single site
        if($this->isWordPressMinimiumVersion("4.9.0") && (!( is_multisite()))){
            //pulls the default actions
            remove_action( 'add_option_new_admin_email', 'update_option_new_admin_email' );
            remove_action( 'update_option_new_admin_email', 'update_option_new_admin_email' );

            //When you actually complete the change, another email gets fired to the old address
            //this filter overides this:
            add_filter('send_site_admin_email_change_email', function(){return FALSE;}, 10, 3 );

            //hooks our own custom method to update the email
            add_action( 'add_option_new_admin_email', array($this, 'updateOptionAdminEmail'), 10, 2 );
            add_action( 'update_option_new_admin_email', array($this, 'updateOptionAdminEmail'), 10, 2 );

            //this fixes the text in English. Translators wanted for other languages.
            add_action('wp_after_admin_bar_render', array($this, 'modifyOptionsGeneralPHPForm'));
        }
    }

    public function updateOptionAdminEmail( $old_value, $value ) {
        update_option( 'admin_email', $value );
    }

    public function isWordPressMinimiumVersion($version){
        global $wp_version;
        if (version_compare($wp_version, $version, ">=")) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

    //Changes the form on admin area options-general.php. Doesn't do anything unless on this page.
    public function modifyOptionsGeneralPHPForm(){
        $screen = get_current_screen();
        if($screen->base == "options-general"){
            add_filter( 'gettext', array($this, 'filterText'), 10, 3 );
        }
    }

    //Changes the English text of WP core. Inspired by https://wordpress.stackexchange.com/questions/188332/override-default-wordpress-core-translation
    public function filterText( $translated, $original, $domain ) {
        if ( $translated == "This address is used for admin purposes. If you change this we will send you an email at your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>"){
            $translated = __("This address is used for admin purposes.");
        }
        return $translated;
    }

}

Answer:

You can disable the email confirmation by just adding the following code in your theme function.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', 10, 2 );
add_action( 'update_option_new_admin_email', 'wpdocs_update_option_new_admin_email', 10, 2 );

Answer:

The network admin email is changed from wp_sitemeta table. Use following query in phpmyadmin or any mysql client in order to update the email if you are unable to change from network admin settings.

UPDATE `wp_sitemeta` SET `meta_value` = '[email protected]' WHERE `meta_value` = '[email protected]';

Note: please use the table prefix accordingly used in db if it is not wp in your case.

look at the image of wp_sitemeata table if you want to know the entries to be changed.