[buddypress-trac] [BuddyPress Trac] #7366: Send email to new email address after its change confirmed

buddypress-trac noreply at wordpress.org
Sun Jun 16 15:08:44 UTC 2024


#7366: Send email to new email address after its change confirmed
-----------------------------+-------------------------------------
 Reporter:  slaFFik          |       Owner:  (none)
     Type:  feature request  |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Contributions
Component:  Emails           |     Version:  2.5.0
 Severity:  normal           |  Resolution:
 Keywords:                   |
-----------------------------+-------------------------------------

Comment (by mrahsankhan):

 First, hook into the process where the user requests an email change.
 You'll send a confirmation link to the old email address.

 {{{

 function custom_send_confirmation_email( $user_id, $old_email ) {
     // Generate a unique confirmation key
     $confirmation_key = wp_generate_password( 20, false );

     // Save the confirmation key and the new email address as user meta
     update_user_meta( $user_id, 'new_email_confirmation_key',
 $confirmation_key );
     update_user_meta( $user_id, 'new_email_address', $_POST['email'] );

     // Prepare the email
     $email_subject = 'Confirm your new email address';
     $confirmation_url = add_query_arg( array(
         'user_id' => $user_id,
         'key' => $confirmation_key,
     ), home_url( '/confirm-email-change/' ) );
     $email_message = sprintf(
         'Please click the following link to confirm your new email
 address: %s',
         $confirmation_url
     );

     // Send the email
     wp_mail( $old_email, $email_subject, $email_message );
 }
 add_action( 'bp_core_screen_general_settings',
 'custom_send_confirmation_email', 10, 2 );
 }}}

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/7366#comment:1>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list