Advertisement
Aurangajeb

Send email to admin if user updated his profile - Expand version

Jul 10th, 2021
1,477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. /**
  2. @ Send email to admin if user updated his profile - Expand version
  3. @
  4. **/
  5.  
  6.  
  7. function wpuf_user_profile_update_notification( $user_id ) {
  8.  
  9.     if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
  10.  
  11.     $user_info = get_userdata( $user_id );
  12.  
  13.     $to = get_option( 'admin_email' ) .", ".$user_info->user_email;
  14.     $subject = $user_info->display_name . " Profile Updated";
  15.  
  16.     //Get user custom Meta
  17.     $phone = get_user_meta( $user_id, 'phone', true );
  18.     $address_field = get_user_meta( $user_id, 'address_field', true );
  19.  
  20.     // Message body
  21.     $message .= "The user (". $user_info->display_name. ") has updated his profile with:". "\n\n";
  22.    
  23.     // Show user meta which you want to show on the email message
  24.  
  25.     $message .= 'Phone: ' . $phone . "\n";
  26.     // $message .= 'Address: ' . $address_field['street_address'] .", ". $address_field['street_address2'] .", ". $address_field['city_name'] . ", ". $address_field['zip'] . ", ". $address_field['state'] . ", ". $address_field['country_select'] . "\n";
  27.    
  28.     $message .= 'Address:'. "\n";
  29.     $message .= 'Street 1- ' . $address_field['street_address'] . "\n";
  30.     $message .= 'Street 2- ' . $address_field['street_address2'] . "\n";
  31.     $message .= 'City- ' . $address_field['city_name'] . "\n";
  32.     $message .= 'Post/Zip- ' . $address_field['zip'] . "\n\n";
  33.  
  34.     $message .= 'Site Address: ' . get_bloginfo('wpurl') . "\n";
  35.  
  36.     wp_mail( $to, $subject, $message);
  37.  
  38.     }
  39.  
  40. }
  41. add_action( 'wpuf_update_profile', 'wpuf_user_profile_update_notification', 10, 3 ); //This action fire while  WPUF Profile form update
  42. add_action( 'profile_update', 'wpuf_user_profile_update_notification', 10, 2); //This action fire while default WordPress profile update
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement