0

Currently I can send an email to admin when users update their information using the following (hooking into the S2Memeber plugin):

// Email to tell us what user profile for CMM has been modified
add_action ('ws_plugin__s2member_during_handle_profile_modifications', 'email_profile_changes');
function email_profile_changes($vars = array()) {
    $user = new WP_User($vars['user_id']);

add_filter('wp_mail_content_type', 'wpdocs_set_html_mail_content_type');
$old_meta = get_user_meta($user->ID);
$to = "hello@example.com";
$subject = "Profile Update - $user->user_login";
$body = "This user has updated their CMM profile information, here is their new profile data for audit purposes: <br/>" .
        "<hr>" .
        "First Name: " . $user->first_name . "<br/>" .
        "<hr>" .
        "Last Name: " . $user->last_name . "<br/>" .
        "<hr>" .
        "Email Address: " . $user->email . "<br/>" .
        "<hr>" .
        "Address: " . $user->wp_s2member_custom_fields['company_address'] . "<br/>" .
        "<hr>" .
        "Telephone Number: " . $user->wp_s2member_custom_fields['telephone_number'] . "<br/>" .
        "<hr>" .
        "Old User Data";

wp_mail ($to, $subject, $body);
    remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
}

For audit purposes i've been asked if it's possible to show their user information before update as well as their changed data?

How would I go about modifying this to do that? I'm assuming wordpress databases just overwrite this data when it's saved and it's therefore not possible?

Any help would be appreciated to determine if it's possible or not?

  • It's hard to tell because of the plugin you're using. WP Core has a hook called profile_update which would allow you to pull the old data from the database and the new data from the POST request, but your plugin is using a different hook. You may need to contact the plugin author who is more familiar with how the plugin modifies behavior and see whether you can use one of the plugin's hooks. – WebElaine Jan 11 at 14:39
0

So, I managed to do this by using as a hook ws_plugin__s2member_before_handle_profile_modifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.