wp mail – How can admins to be notified of changes when users change their WP profiles?

Question

I’m using the code below that I found in another thread and it works as a notification that something has been changed. I’d like to amend this so that we can be notified which fields (Name, email, phone, etc) have been changed. Is there a simple way to achieve this?

I’m pretty new to php and coding i general so please explain like I’m dumb. Thank you so much

add_action( 'personal_options_update', 'notify_admin_on_update' );
add_action( 'edit_user_profile_update','notify_admin_on_update');
function notify_admin_on_update(){
    global $current_user;
    get_currentuserinfo();

    if (!current_user_can( 'administrator' )){// avoid sending emails when admin is updating user profiles
        $to = 'email@email.com';
        $subject="user updated profile";
        $message = "the user : " .$current_user->display_name . " has updated his profile with:n";
        foreach($_POST as $key => $value){
            $message .= $key . ": ". $value ."n";
        }
        wp_mail( $to, $subject, $message);
    }
}

0
Manny 1 month 2021-10-18T13:29:20-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse