As mentioned in the ticket #16470 this confirmation feature:
prevents accidental or erroneous email address changes from
potentially locking users out of their account.
so it’s good to keep that in mind before removing this feature.
Here’s a little proof of concept for (single site) test installs.
We still want to run send_confirmation_on_profile_email()
because it contains various email validations and error reportings, but we want to stop it from sending a confirmation email. Instead we set the generated _new_email
meta value from that function as the new user email during the current user profile saving.
Here we unhook send_confirmation_on_profile_email()
and rehook it within our wpse409429_update_profile_email()
wrapper with our modifications:
add_action ( 'admin_init', function() {
remove_action(
'personal_options_update',
'send_confirmation_on_profile_email'
);
add_action(
'personal_options_update',
'wpse409429_update_profile_email'
);
} );
where our wrapper is:
function wpse409429_update_profile_email( $user_id ) {
// Stop confirmation email when running
// send_confirmation_on_profile_email().
add_filter( 'pre_wp_mail', '__return_false' );
send_confirmation_on_profile_email();
remove_filter( 'pre_wp_mail', '__return_false' );
// Get new email that is already validated and saved
// as _new_email within send_confirmation_on_profile_email().
$new_email = get_user_meta( $user_id, '_new_email', true );
if ( ! empty( $new_email['newemail'] ) && is_email( $new_email['newemail'] ) ) {
// Core uses this output! escaping during saving, so we do the same!
$newemail = esc_html( trim( $new_email['newemail'] ) );
wp_update_user( array(
'ID' => $user_id,
'user_email' => $newemail
) );
// Core modifies the _POST value for email,
// with the old email value, so we need to
// override that with the new one.
$_POST['email'] = $newemail;
// Delete post meta to avoid confirmation messages.
delete_user_meta( $user_id, '_new_email' );
}
}
Further one can add extra error reportings if meta value is corrupted and hide the text under the email field:
If you change this, an email will be sent at your new address to
confirm it. The new address will not become active until confirmed.
with CSS.