AI Verified

Name

Change admin email without sending verification emails

About

This code snippet allows you to change the admin email setting in WordPress without requiring outbound email verification. This functionality was removed in WordPress v4.9, and this snippet restores it, enabling admins to update the admin email address without needing the recipient to confirm the change via email. Features: Remove Pending Email Changes: Clears any pending email changes that might have been set before activating this snippet, ensuring that the new email is set without any pending confirmation. Disable Outbound Email for Admin Email Change: Disables the email that WordPress usually sends to the old admin email address when the admin email is changed. Verify Nonce for Security: Checks a security nonce before allowing the email change, ensuring that the request is legitimate. Admin Notices: Displays admin notices to provide feedback on actions taken, such as successfully sending a test email. Modify Options-General.php Page: Modifies the admin settings page to remove the message about email confirmation and add a "Test Email" button for verifying the new admin email. AJAX Integration for Test Email: Uses jQuery to add the "Test Email" button functionality, allowing admins to test the new email address without saving it.

Language

PHP

Rating

Voted: 0 by 0 user(s)

How to Setup Snippet

Add the Snippet: Use the Code Snippets Pro plugin to add this snippet to your WordPress site. Activate the Snippet: Activate the snippet to enable its functionality. Update Admin Email: Go to the "General Settings" page in your WordPress admin area to change the admin email without outbound email verification. Use the "Test Email" button to ensure the new email address is correct.

Codevault

lowthian

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.4

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

Website/ Profile URL:

https://www.lowthiandesign.com

History

Last modified:

16/07/2024

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Potential vulnerability found : Cross Site Scripting
Found on line : 91
Code : echo("<div class='notice {$noticeLevel} is-dismissible'><p>{$message}</p></div>")
Vulnerable line : 90
Code : $noticeLevel = !empty($option['notice-level']) ? $option['notice-level'] : 'notice-error');

Potential vulnerability found : Cross Site Scripting
Found on line : 91
Code : echo("<div class='notice {$noticeLevel} is-dismissible'><p>{$message}</p></div>")
Vulnerable line : 89
Code : $message = isset($option['message']) ? $option['message'] : false);

Potential vulnerability found : Insecure E-mail
Found on line : -1
Code : mail(= $_POST['new_admin_email'])

Found 3 vulnerabilities

Change admin email without sending verification emails

 
                    
1function change_admin_email_verify_nonce() {
2 if (!wp_verify_nonce($_POST['change-admin-email-test-email-nonce'], 'change-admin-email')) {
3 wp_die('Something is very wrong here.');
4 }
5}
6 
7function change_admin_email_remove_pending() {
8 delete_option("adminhash");
9 delete_option("new_admin_email");
10}
11 
12function change_admin_email_run() {
13 add_action('init', 'change_admin_email_remove_pending');
14 add_action('admin_notices', 'change_admin_email_display_admin_notice');
15 
16 remove_action('add_option_new_admin_email', 'update_option_new_admin_email');
17 remove_action('update_option_new_admin_email', 'update_option_new_admin_email');
18 
19 add_filter('send_site_admin_email_change_email', '__return_false', 10, 3);
20 
21 if(isset($_POST['change-admin-email-test-email-nonce'])){
22 add_action('init', 'change_admin_email_verify_nonce');
23 add_action('init', 'change_admin_email_test_email');
24 }
25 add_action('add_option_new_admin_email', 'change_admin_email_update_option', 10, 2);
26 add_action('update_option_new_admin_email', 'change_admin_email_update_option', 10, 2);
27 
28 add_action('wp_after_admin_bar_render', 'change_admin_email_modify_options_form');
29}
30 
31function change_admin_email_test_email() {
32 $email = $_POST['new_admin_email'];
33 $domain = site_url();
34 $url = "https://generalchicken.guru/wp-json/change-admin-email-plugin/v1/test-email";
35 $response = wp_remote_post($url, array(
36 'method' => 'POST',
37 'body' => array(
38 'email' => $email,
39 'domain' => $domain
40 ),
41 )
42 );
43 change_admin_email_display_success(__('Check your email inbox. A test message has been sent to you.'));
44}
45 
46function change_admin_email_update_option($old_value, $value) {
47 update_option('admin_email', $value);
48}
49 
50function change_admin_email_modify_options_form() {
51 if (function_exists('get_current_screen')) {
52 $screen = get_current_screen();
53 if($screen->base == "options-general"){
54 add_filter('gettext', 'change_admin_email_filter_text', 10, 3);
55 echo change_admin_email_return_jquery();
56 }
57 }
58}
59 
60function change_admin_email_return_jquery() {
61 $nonce = wp_create_nonce('change-admin-email');
62 $output = <<<OUTPUT
63<script>
64jQuery(document).ready(function(){
65 var insertInputButton = "<input type = 'submit' class = 'button button-primary' name = 'changeAdminEmailSubmit' id = 'changeAdminEmailSubmitButton' value = 'Test Email' />";
66 jQuery(insertInputButton).insertAfter("#new-admin-email-description");
67 
68 jQuery("#changeAdminEmailSubmitButton").click(function(event) {
69 event.preventDefault();
70 var insertThisNonce = "<input type = 'hidden' name = 'changeAdminEmailAction' value = 'changeEmail' /><input type = 'hidden' name = 'change-admin-email-test-email-nonce' value = '$nonce' />";
71 jQuery(insertThisNonce).insertAfter("#new-admin-email-description");
72 jQuery("#submit").click();
73 });
74});
75</script>
76OUTPUT;
77 return $output;
78}
79 
80function change_admin_email_filter_text($translated, $original, $domain) {
81 if ($translated == "This address is used for admin purposes. If you change this, an email will be sent to your new address to confirm it. <strong>The new address will not become active until confirmed.</strong>"){
82 $translated = __("This address is used for admin purposes.");
83 }
84 return $translated;
85}
86 
87function change_admin_email_display_admin_notice() {
88 $option = get_option('my_admin_notice_message');
89 $message = isset($option['message']) ? $option['message'] : false;
90 $noticeLevel = !empty($option['notice-level']) ? $option['notice-level'] : 'notice-error';
91 if ($message) {
92 echo "<div class='notice {$noticeLevel} is-dismissible'><p>{$message}</p></div>";
93 delete_option('my_admin_notice_message');
94 }
95}
96 
97function change_admin_email_display_error($message) {
98 change_admin_email_update_option_message($message, 'notice-error');
99}
100 
101function change_admin_email_display_warning($message) {
102 change_admin_email_update_option_message($message, 'notice-warning');
103}
104 
105function change_admin_email_display_info($message) {
106 change_admin_email_update_option_message($message, 'notice-info');
107}
108 
109function change_admin_email_display_success($message) {
110 change_admin_email_update_option_message($message, 'notice-success');
111}
112 
113function change_admin_email_update_option_message($message, $noticeLevel) {
114 update_option('my_admin_notice_message', [
115 'message' => $message,
116 'notice-level' => $noticeLevel
117 ]);
118}
119 
120change_admin_email_run();

0

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

0

Redirect user role on specific page

Added: 1 year ago

Last Updated: 1 year ago

This code will redirect a specific page based on the user role NOT being met.

WordPress Admin

AI Verified

0

Disable scroll-to-top when editing snippets

Added: 11 months ago

Last Updated: 11 months ago

When using Code Snippets 3.6.0 or later, use this snippet to prevent the automatic scroll-to-top after clicking 'save' when editing a snippet.

WordPress Admin

AI Verified

0

Password-Protect-Page-Style

Added: 2 months ago

Last Updated: 2 months ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

1

View update info on posts

Added: 3 months ago

Last Updated: 3 months ago

WordPress Admin

AI Verified

1

Link to clear Bunny CDN

Added: 6 months ago

Last Updated: 6 months ago

I wanted a way for my clients to have a one click "Clear Bunny CDN" without having to go into other settings. Worked with AI and BunnyCDN support on this.

General

AI Verified

0

Gravity to Stripe Description

Added: 11 months ago

Last Updated: 10 months ago