Advertisement
Aurangajeb

Send email to admin if the user updated his profile

Jul 10th, 2021
1,682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. /**
  2. @ Send email to admin if the user updated his profile - Method-1
  3. **/
  4.  
  5. add_action( 'personal_options_update', 'notify_admin_on_update' );
  6. add_action( 'edit_user_profile_update','notify_admin_on_update' );
  7.  
  8. function notify_admin_on_update(){
  9.     global $current_user;
  10.     get_currentuserinfo();
  11.  
  12.     if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
  13.         $to = get_option( 'admin_email' );
  14.         $subject = 'The User Profile Updated';
  15.         $message = "The user : (" .$current_user->display_name . ") has updated his profile with:\n";
  16.         foreach($_POST as $key => $value){
  17.             $message .= $key . ": ". $value ."\n";
  18.         }
  19.         wp_mail( $to, $subject, $message);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement