hooks - How to get user profile information before update?

admin2025-06-04  5

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 = "[email protected]";
$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?

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 = "[email protected]";
$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?

Share Improve this question edited Jan 11, 2019 at 15:13 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Jan 11, 2019 at 14:00 user158811user158811 1 1
  • 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 Commented Jan 11, 2019 at 14:39
Add a comment  | 

1 Answer 1

Reset to default 0

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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749014557a315628.html

最新回复(0)