Creating a Hook: Admin Notification User Profile Change

Hello,

I allow myself to come here because I can not find an answer to my problem even after scouring the internet.
I’m on S2member Pro
And I would like to create a hook to send mail notifications when a user makes a change on his profile.

I found this solution which is old, I do not know if it is still current with the recent update of S2member.

Reference link of the hook on which I base myself : http://www.primothemes.com/forums/viewtopic.php?f=4&t=2193

I manage to put the hook, it works. Only I can not display the customized fields in the mail:

I use this code:

    <?php
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']);

    wp_mail ('me@mydomain.com', 'Profile update - ' . $user->user_login, '
        First Name: ' . $user->first_name . '
        Last Name: ' . $user->last_name . '
        Address: ' . $user->mysite_wp_s2member_custom_fields['street_address_1'] . '
                 ' . $user->mysite_wp_s2member_custom_fields['street_address_2'] . '
        City: ' . $user->mysite_wp_s2member_custom_fields['city'] . '
        And so on...');
}
?>

Do you find some things that are wrong

I am only a novice in website …

Thanks in advance to the community

Maybe “mysite_wp_s2member_custom_fields” is changed, try this as mail body: print_r($user, true)

You should get a list with all the user’s info, and will be possible to see the changed variable.

Thank you for your answer, unfortunately my level does not allow me to do what you ask me …

I saw on another topic of this forum that you were working on a plug-in that could do that. I began to monitor this subject in order to be present when you will release it :slight_smile:

Cordialy

Thanks for your trust :slight_smile: Hope I will have time to finish it shortly.

krumch:

Thanks for your tip about “print_r($user, true)”

I am in need of an Email to Admin whenever custom profile fields are changed, with recording old versus new (in the email).

When I tried what you suggested (above), and it resulted in showing me some info, none of the info pertained to custom profile fields. I got this (below). Any other advice?

All user data: ( print_r($user, true) ):

WP_User Object
(
[data] => stdClass Object
(
[ID] => 14
[user_login] => joseph-doug
[user_pass] => ( hashed encrypted content removed }
[user_nicename] => joseph-doug
[user_email] => ( my email removed )
[user_url] => http://dougjoseph.net
[user_registered] => 2010-05-26 10:11:23
[user_activation_key] =>
[user_status] => 0
[display_name] => Doug Joseph
[spam] => 0
[deleted] => 0
)

[ID] => 14
[caps] => Array
(
[s2member_level3] => 1
[manage_esa_options] => 1
)

[cap_key] => wv_wp3_3_capabilities
[roles] => Array
(
[0] => s2member_level3
)

[allcaps] => Array
(
[read] => 1
[level_0] => 1
[access_s2member_level0] => 1
[access_s2member_level1] => 1
[access_s2member_level2] => 1
[access_s2member_level3] => 1
[s2member_level3] => 1
[manage_esa_options] => 1
)

[filter] =>
)

I had a similar printout from print_r($user, true) as dougjoseph - I didn’t get any information. Has there been any update on this / the plugin krumch was making?

I am not very experienced in PhP, so I couldn’t get this to work in a pretty way, and I’m not sure if there are any other issues with how I implemented this - but maybe someone else can help me out.

I ended up using print_r($vars, true) to try and figure out what was going on, and then just asked the email notification to print the parts of the $vars array that I needed, which were:

Updated fields: ‘. print_r($vars[‘fields’], true) .’

Previous data: ‘. print_r($vars[’_existing_fields’], true) .’

Which prints something like this:

Updated fields:
Array
(
[user_full_address] => Sample User Address 2
[user_title_position] => Sample User Title 2
[user_employer_class] => Sample Employer Class 2
)

Previous data:
Array
(
[user_full_address] => Sample User Address 1
[user_title_position] => Sample User Title 1
[user_employer_class] => Sample Employer Class 1
)

Not very elegant, but gets the job done for my purposes.