send_confirmation_on_profile_email

Sends an email when an email address change is requested.

Description

send_confirmation_on_profile_email(); 

Usage

  1. if ( !function_exists( 'send_confirmation_on_profile_email' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = send_confirmation_on_profile_email(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function send_confirmation_on_profile_email() { 
  2. global $errors, $wpdb; 
  3. $current_user = wp_get_current_user(); 
  4. if ( ! is_object($errors) ) 
  5. $errors = new WP_Error(); 
  6.  
  7. if ( $current_user->ID != $_POST['user_id'] ) 
  8. return false; 
  9.  
  10. if ( $current_user->user_email != $_POST['email'] ) { 
  11. if ( !is_email( $_POST['email'] ) ) { 
  12. $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) ); 
  13. return; 
  14.  
  15. if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) { 
  16. $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) ); 
  17. delete_user_meta( $current_user->ID, '_new_email' ); 
  18. return; 
  19.  
  20. $hash = md5( $_POST['email'] . time() . mt_rand() ); 
  21. $new_user_email = array( 
  22. 'hash' => $hash,  
  23. 'newemail' => $_POST['email'] 
  24. ); 
  25. update_user_meta( $current_user->ID, '_new_email', $new_user_email ); 
  26.  
  27. $switched_locale = switch_to_locale( get_user_locale() ); 
  28.  
  29. /** translators: Do not translate USERNAME, ADMIN_URL, EMAIL, SITENAME, SITEURL: those are placeholders. */ 
  30. $email_text = __( 'Howdy ###USERNAME###,  
  31.  
  32. You recently requested to have the email address on your account changed. 
  33.  
  34. If this is correct, please click on the following link to change it: 
  35. ###ADMIN_URL### 
  36.  
  37. You can safely ignore and delete this email if you do not want to 
  38. take this action. 
  39.  
  40. This email has been sent to ###EMAIL### 
  41.  
  42. Regards,  
  43. All at ###SITENAME### 
  44. ###SITEURL###' ); 
  45.  
  46. /** 
  47. * Filters the email text sent when a user changes emails. 
  48. * The following strings have a special meaning and will get replaced dynamically: 
  49. * ###USERNAME### The current user's username. 
  50. * ###ADMIN_URL### The link to click on to confirm the email change. 
  51. * ###EMAIL### The new email. 
  52. * ###SITENAME### The name of the site. 
  53. * ###SITEURL### The URL to the site. 
  54. * @since MU 
  55. * @param string $email_text Text in the email. 
  56. * @param string $new_user_email New user email that the current user has changed to. 
  57. */ 
  58. $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); 
  59.  
  60. $content = str_replace( '###USERNAME###', $current_user->user_login, $content ); 
  61. $content = str_replace( '###ADMIN_URL###', esc_url( self_admin_url( 'profile.php?newuseremail=' . $hash ) ), $content ); 
  62. $content = str_replace( '###EMAIL###', $_POST['email'], $content); 
  63. $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); 
  64. $content = str_replace( '###SITEURL###', network_home_url(), $content ); 
  65.  
  66. wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); 
  67. $_POST['email'] = $current_user->user_email; 
  68.  
  69. if ( $switched_locale ) {