There are many great code snippets in their Gitlab. You might find more on their…
Change Email w/o notification
function change_user_email_without_confirmation($user_id, $new_email) {
// Sanitize user ID and new email
$user_id = intval($user_id);
$new_email = sanitize_email($new_email);
// Make sure it's a valid email address
if (!is_email($new_email)) {
return new WP_Error('invalid_email', __('Invalid email address.'));
}
// Get the user data
$user = get_userdata($user_id);
if (!$user) {
return new WP_Error('invalid_user', __('Invalid user ID.'));
}
// Directly update the user email in the database without triggering a confirmation email
global $wpdb;
$wpdb->update(
$wpdb->users,
array('user_email' => $new_email),
array('ID' => $user_id)
);
// Clear the user cache
clean_user_cache($user_id);
// Optionally, you can add additional actions here, like logging the change or notifying an admin
return true;
}
$user_id = 5; // create service provider email for the forms
$new_email = 'noreply@example.com';
$result = change_user_email_without_confirmation($user_id, $new_email);
if (is_wp_error($result)) {
echo 'Fehler: ' . $result->get_error_message();
} else {
echo 'Adresse bereit.';
}
Dieser Beitrag hat 0 Kommentare