PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Email Notification of profile updates

s2Member Plugin. A Membership plugin for WordPress®.

Email Notification of profile updates

Postby man-O-media » February 10th, 2011, 12:11 am

So I searched the forum for notification AND profile but got nothing really useful so...

Is it possible to have S2Member or S2Member Pro send an email notification whenever a member updates their profile information?
And in more detail... Is it possible to have S2Member or S2Member Pro send an email notification whenever a member updates certain fields of their profile information, for example if they change their contact phone number or email address?

Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby man-O-media » February 18th, 2011, 9:16 am

Soooo, I realize that everyone is busy, that I am new here and less knowledgeable than many so am perhaps not as interesting as others but I am not impressed with the support.

The basic s2 version does a lot of what I need, seems to work well and is pretty easy so I am very interested in buying the pro version if it adds what I need.
I have posted questions in two threads that have had multiple views but no replies. Thats OK, I accept that "these forums are NOT an official support channel" as they say in the header.

So starting 8 days ago I also sent emails with pre-sales questions to Primo support (primothemes@websharks-inc.com) as they request on the support page and not a single reply.

Primo Guys & Gals... without answers, I am NOT going to spend my money!


DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Jason Caldwell » March 14th, 2011, 9:50 pm

Thanks for the excellent question; and thanks for your patience.
man-O-media wrote:So I searched the forum for notification AND profile but got nothing really useful so...

Is it possible to have S2Member or S2Member Pro send an email notification whenever a member updates their profile information?
And in more detail... Is it possible to have S2Member or S2Member Pro send an email notification whenever a member updates certain fields of their profile information, for example if they change their contact phone number or email address?

Thanks, DP

I'm sorry. This is not something that is built into s2Member by default. However, you could certainly accomplish this with s2Member's Hook on Profile updates.

Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php

Inside the file, you could do something like this:
Code: Select all
<?php
add_action 
("ws_plugin__s2member_during_handle_profile_modifications", "my_function");
function my_function ($vars = array ())
    {
        $user = new WP_User ($vars["user_id"]);
        wp_mail ("admin@example.com", "Subject ( " . $user->user_login . " just updated their Profile )", "Message Body goes here.");
    }
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Email Notification of profile updates

Postby man-O-media » March 17th, 2011, 9:09 am

Hi Jason, Thanks for the reply...

Indeed, I can make that work however, what I still don't understand is how to also send some of the s2 custom field data stored in the JSON Array.

For example, lets say I have the following two text fields;
my_street-1
my_city

How do I include that data in the body of the email?

Many thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 17th, 2011, 12:25 pm

You could run a test to see what you have in the $_REQUEST array, see if they are there.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 17th, 2011, 12:53 pm

Hi Cristian,

I wish I knew what you were talking about when you say "You could run a test to see what you have in the $_REQUEST array, see if they are there"
Not that it would really help me but is the $_REQUEST a constant?

In any case, I know the data is there, in fact I can use the following to get all of the data from the array and dump it onto the screen

Code: Select all
function my_function(){

    $user = wp_get_current_user();
    print_r($user); to get a full list of $user data during testing.


But even after having the data in the $user variable, I could not use that variable in my email and send it.
That said, even if I could get the content of that variable to send, it is one giant string.
I would prefer only sending specific fields of data.
And if I were to send the whole string, I would still want it formatted as a simple comma delineated string.


Any suggestions you can give wold be most welcome :D

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 17th, 2011, 1:01 pm

I see what you mean.

Well, to use just those two fields you gave as an example, after you create the $user array they'd be $user['my_street-1'] and $user['my_city'], which you can use in the body of the email. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 17th, 2011, 4:18 pm

Many thanks Cristian for your putting up with me but I am back again :(

This is what I have, essentially what Jason handed over earlier...

Code: Select all
<?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"]);
       // print_r($user);
        wp_mail ('me@mydomain.net', 'Subject ( ' . $user->user_login . ' just updated their  Profile )', 'Message Body goes here.' . $user['my_phone']);
     }

?>


As noted above, if I enable the print command, all of the data is sent to the screen but the moment I add a variable such as $user['my_phone'] to the email (as I do above) the moment the code is triggered, everything stops cold.
I also tried to call print_r($user['my_phone']); but that too stops the action.

I know this isn't rocket science but it is to me at the moment...

Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 17th, 2011, 6:26 pm

print_r will work with arrays only, and $user['my_phone'] is most probably not one.

Are you sure you have 'my_phone' in user? If you print_r($user) (the line you have commented out there), do you see 'my_phone' in the output?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 17th, 2011, 7:01 pm

Ahhhh, yes and no... or better said, yes, no and yes.

You are correct, my_phone is simply one custom data field contained in the array of custom data fields so no, I can not print_r my_phone directly but yes, I can print_r($user).
In that case (I can't look at the display at the moment) but inside the collection of some 25 custom fields of data is something like my_phone => 999-999-9999

And indeed, this is where my problem is coming in, getting at just the plain text in the various fields and why I was trying to use your suggestion of $user['my_phone']


Daine
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 18th, 2011, 12:15 am

Sorry, I made a silly mistake. I confused $user with an array, but it's an object...

Instead of $user['my_phone'], try $user->my_phone.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 18th, 2011, 7:11 pm

try $user->my_phone


I wish it was that simple...
For testing, if I for example use echo $user->user_login;
I get the correct user name sent to the screen

If I use echo $user->home_phone; AND
If I use print_r($user->home_phone);
I get no data on the screen which is at least an improvement in that the statement does not cause a crash.

My guess is that I need to more specifically refer to mysite_wp_s2member_custom_fields and then the specific field name but?

It is a bunch of stuff which is why I placed it at the bottom but as you can see from the results of print_r($user), home_phone contains 999-999-9999 so there is data, it is just a mater of the right syntax:
========================================================
WP_User Object ( [data] => stdClass Object ( [ID] => 7 [user_login] => delete2 [user_pass] => $P$BGVsKUyw39djl1M7m/ja28d/lo93efy [user_nicename] => delete2 [user_email] => me@mydomain.com [user_url] => [user_registered] => 2011

-03-10 13:50:40 [user_activation_key] => [user_status] => 0 [display_name] => delete2 [first_name] => my First Name is delete [last_name] => My Last name is also delete [nickname] => delete2 [description] => [rich_editing] => true

[comment_shortcuts] => false [admin_color] => fresh [use_ssl] => 0 [aim] => [yim] => [jabber] => [mysite_wp_capabilities] => Array ( [s2member_level2] => 1 ) [mysite_wp_user_level] => 0 [mysite_wp_s2member_custom_fields] => Array (

[street_address_1] => delete Stereet Adressx [street_address_2] => [city] => Atlanta City [state] => GA [zip] => 12222 [home_phone] => 999-999-9999 [work_phone] => [cell_phone] => [wants_weekly_news] => [emergency_phone] =>

[wants_user_listing] => [directory_name] => [secondary_email] => [mail_address_1] => [mail_address_2] => [mail_city] => [mail_state] => [mail_zip] => ) [default_password_nag] => 1 [mysite_wp_s2member_notes] => Demoted by

s2Member: Fri Mar 11, 2011 12:04 am UTC Demoted by s2Member: Fri Mar 11, 2011 1:44 am UTC [mysite_wp_s2member_paid_registration_times] => Array ( [level] => 1299768460 [level2] => 1299768460 )

[mysite_wp_s2member_auto_eot_time] => 1300838400 [show_admin_bar_front] => true [show_admin_bar_admin] => false [user_level] => 0 [user_firstname] => my First Name is delete [user_lastname] => My Last name is also delete

[user_description] => ) [ID] => 7 [id] => 7 [caps] => Array ( [s2member_level2] => 1 ) [cap_key] => mysite_wp_capabilities [roles] => Array ( [0] => s2member_level2 ) [allcaps] => Array ( [read] => 1 [level_0] => 1 [access_s2member_level0] =>

1 [access_s2member_level1] => 1 [access_s2member_level2] => 1 [s2member_level2] => 1 ) [first_name] => my First Name is delete [last_name] => My Last name is also delete [filter] => [user_login] => delete2 [user_pass] => $P

$de56ws94otljs237^wl(t/hzytfd61 [user_nicename] => delete2 [user_email] => user@mysite.com [user_url] => [user_registered] => 2011-03-10 13:50:40 [user_activation_key] => [user_status] => 0 [display_name] => delete2 [nickname] =>

delete2 [description] => [rich_editing] => true [comment_shortcuts] => false [admin_color] => fresh [use_ssl] => 0 [aim] => [yim] => [jabber] => [mysite_wp_capabilities] => Array ( [s2member_level2] => 1 ) [mysite_wp_user_level] => 0

[mysite_wp_s2member_custom_fields] => Array ( [street_address_1] => delete Stereet Adressx [street_address_2] => [city] => New York City [state] => NY [zip] => 12222 [home_phone] => 999-999-9999 [work_phone] => [cell_phone] =>

[wants_weekly_news] => [emergency_phone] => [wants_user_listing] => [directory_name] => [secondary_email] => [mail_address_1] => [mail_address_2] => [mail_city] => [mail_state] => [mail_zip] => ) [default_password_nag] => 1

[mysite_wp_s2member_notes] => Demoted by s2Member: Fri Mar 11, 2011 12:04 am UTC Demoted by s2Member: Fri Mar 11, 2011 1:44 am UTC [mysite_wp_s2member_paid_registration_times] => Array ( [level] => 1299768460 [level2] =>

1299768460 ) [mysite_wp_s2member_auto_eot_time] => 1300838400 [show_admin_bar_front] => true [show_admin_bar_admin] => false [user_level] => 0 [user_firstname] => my First Name is delete [user_lastname] => My Last name is also

delete [user_description] => )
========================================================
DP
Last edited by man-O-media on October 31st, 2011, 9:54 pm, edited 1 time in total.
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 18th, 2011, 7:44 pm

I don't understand what your problem is right now. Do you want the output of print_r($user) to be in the email too?

Could you show me your code please? Put it between code tags, like this please:

[code=php]Your code here. [/code]
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 18th, 2011, 10:25 pm

First, to recap the objective...
I want wordpress to send an email to a department of the organization with most of a users info after they have updated their profile. The organization can then go in and manually update some other related documents with the new data.

In answer to your question, no, I do not want the output of print_r($user) to be in the email as it is too confusing. I included it in the last post simply to show that there really is data available. Mind you, if I try to put $user in the body, everything stops.

What I am working with right now is simply:
Code: Select all
 <?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"]);
     // print_r($user); 
     // print_r($user->home_phone);

     wp_mail ('me@mydomain.com', 'Subject ( ' . $user->user_login . ' just updated their Profile )', 'Message Body goes here.' );
}
?>

The subject properly includes the users login.
What I would like to achieve in the body is a listing of all the fields a user can access when they update their profile so for example:
First Name: user first name
Last Name: user last name
Address: user address
City: user city
etc, etc, etc.

For the time being, I am using this code;
Code: Select all
 <?php
add_action
("ws_plugin__s2member_during_handle_profile_modifications", "email_profile_changes");

function email_profile_changes(){
     global $current_user;     
     get_currentuserinfo
(); 

    wp_mail
("me@mydomain.com", $current_user->user_login  . " has updated their membership profile", " User Login: " . $current_user->user_login . "\n" .  "    User ID: " . $current_user->ID . "\n" . ' First Name: ' . $current_user->user_firstname . "\n" . '  Last Name: ' . $current_user->user_lastname . "\n" .  ' User email: ' . $current_user->user_email  );
}
?>

with it I can generate a decent enough email to clearly indicate who has just changed their profile but because all the fields are not included, it is necessary for the department people to log into wordpress and get the additional data which is what I want to avoid.

Thanks for sticking with me !!!

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 18th, 2011, 11:15 pm

Would you try this and let me know if it works?

Code: Select all
<?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->street_address_1 . '
                 '
 . $user->street_address_2 . '
        City: '
 . $user->city . '
        And so on...'
);
}
?>
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 19th, 2011, 1:03 am

The subject and the first two fields are populated
First Name: my First Name is delete
Last Name: My Last name is also delete

The other two fields, which are part of the s2member_custom_fields, have no data
Address:
City:
And so on...


DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby man-O-media » March 19th, 2011, 10:41 am

I didn't notice yesterday as I was not posting etc., but I am now seeing that the code you asked me to test is causing a conflict in the general wp operation.
With your code active, each time I create a new post, delete a post, etc, my screen goes blank and there is no further response. If I refresh the page it remains blank and no further response.
If I go 'back' in the browser and refresh the page I can see that the previous action was successful.

If I switch back to my old code, that issue goes away.

Nothing to do with you but this bothers me a bit as I would have expected the code only to be called when a profile modification actually occurs.
I wonder if Jason is monitoring this thread?

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 19th, 2011, 12:02 pm

I will ask Jason why other actions would be affected by the code there.

About the error, I'm really sorry, due to the formatting of the print_r output I missed that street, etc., were inside an array.

Code: Select all
<?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...'
);
}
?>


Also, I'm still learning about classes and objects, so I'm not sure if the formatting when accessing an array inside an object will be 100% correct, but we'll know after you try. :P
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 19th, 2011, 3:45 pm

so, I'm still learning about classes and objects, so I'm not sure if the formatting when accessing an array inside an object will be 100% correct, but we'll know after you try.


By George... Cristián, I do believe you got it :D
Most of the data is coming in so MANY THANKS for that !

Also, there doesn't seem to be any strange behavior like blank screens so I guess calling non-existant fields like in the previous version somehow confuses WP though the fact that the function was being called at all is odd.

Anyway, there is, at least at the moment, one incomplete thing.
Most of what I have are simple text fields but I have a two True/False "check box" data fields. Previously they were not populated but I populated them and nothing is returned.
This is the output of $user for a populated field: [wants_user_listing] => 1
The field contains no data for a false condition.

Any thoughts on that ?

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 19th, 2011, 4:22 pm

I'm glad it worked! :)

About the checkboxes, 1 means it was checked, empty means that it wasn't. You need to work with that when creating the email.

Code: Select all
        Wants User Listing' . ($user->mysite_wp_s2member_custom_fields['wants_user_listing'] == 1 ? 'Yes' : 'No') . ' 
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » March 19th, 2011, 9:14 pm

Cristián Lávaque wrote:I'm glad it worked! :)

About the checkboxes, 1 means it was checked, empty means that it wasn't. You need to work with that when creating the email.

Code: Select all
        Wants User Listing: ' . ($user->mysite_wp_s2member_custom_fields['wants_user_listing'] == 1 ? 'Yes' : 'No') . ' 


Oh boy, do I feel like an idiot...
The problem I was having is that neither of my True/False fields were even showing up with a 1, they were both blank but I just discovered that somehow I mistyped both so was trying to pull a "True" value out of thin air.
Now that I have the right field names, it all works.

I had actually setup a standard if statement to set some variables which, now that the field names are correct, does the trick but what you sent is pretty cool.

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » March 19th, 2011, 10:19 pm

I'm glad you got it all sorted out. :)

(Please, don't forget to go rate s2Member over at WordPress.org! and report that your version combination works, ok? Thank you! http://wordpress.org/extend/plugins/s2member/)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » August 18th, 2011, 1:16 pm

Hi Cristián,

My implementation of this code is not working any more.
Cristián Lávaque wrote:
Code: Select all
<?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, '
        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...'
);
}
?>


Did something change in the way one must reference s2member custom fields in a recent s2 update?

Thanks, DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Re: Email Notification of profile updates

Postby Cristián Lávaque » August 18th, 2011, 3:21 pm

I don't really know. You probably just need to re-apply your modifications because they got lost after the update.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Email Notification of profile updates

Postby man-O-media » August 18th, 2011, 5:11 pm

Hmmmm, once again I find that I just am not quite there...

I have several databases on this server so I was using the full name as in
$user->atlymca_wrdp1_wp_s2member_custom_fields['street_address_1']

While all I need is:
$user->wp_s2member_custom_fields['street_address_1']

I didn't think about it but the rest is not needed as the correct database is already loaded :oops:

DP
User avatar
man-O-media
Experienced User
Experienced User
 
Posts: 117
Joined: February 10, 2011

Next

Return to s2Member Plugin

Who is online

Users browsing this forum: No registered users and 0 guests

cron