We rebranded to wildcloud; formerly known as WPCS. 

Update the WP admin E-mail without confirmation

If you’re managing multiple tenants in WordPress, changing the admin email can be time-consuming as it requires manual confirmation. However, with a simple PHP code snippet, you can automate this process and save time. In this article, we’ll show you how to update the WordPress admin email for tenants without confirmation.

Understanding the WordPress Admin Email Setting #

The WordPress admin email setting is an essential setting that specifies the email address used for error reporting and verification. This setting is crucial as it ensures that the website owner receives notifications about errors or issues with the website. In case of critical security events, this email address will be used for sending notifications as well.

The Problem of Manually Confirming Admin Email Changes for Tenants #

For those who manage multiple tenants in WordPress, updating the admin email manually for each tenant can be challenging and time-consuming. This process requires manual confirmation, which is not feasible for users who create multiple tenants every day for external clients.

Automating the Process with PHP Code Snippet #

To automate this process, a PHP code snippet can be used to update the admin_email and new_admin_email options. This code snippet can be added to the functions.php file or can be used through a PHP snippets plugin. Here is an example code snippet that can be used to update the admin email:

<?php
add_action('plugins_loaded', function() {
    $new_email = 'my-email@example.com';
    update_option('admin_email', $new_email);
    update_option('new_admin_email', $new_email);
});

After activating this snippet and refreshing a WordPress page, the admin email will be changed without requiring confirmation. This code needs to be executed on the site that you want to change the admin email for, likely a tenant site. You can deploy this code snippet to your tenants with a custom plugin or a PHP snippet plugin, depending on your use case.

Choosing the Right Hook for Updating the Admin Email #

Using the appropriate hook is essential when updating the admin email. Depending on the specific use case, you should use a hook that is appropriate for that particular situation. In the example code snippet above, the hook plugins_loaded was used. However, depending on the use case, a different hook may be more appropriate.