Page 1 of 1

Send email when role changed manually

PostPosted: December 1st, 2011, 9:46 am
by cforant
Can this system be setup/configured to send an email to the user when i manually change their role to level 1 from a subscriber.

Thanks.

Craig

Free version 111105

Re: Send email when role changed manually

PostPosted: December 1st, 2011, 9:43 pm
by Raam Dev
Hi Craig,

If you want to modify the email sent by s2Member when an existing user is being upgraded/downgraded, take a look at this: viewtopic.php?f=4&t=10368&p=33365&hilit=basic+transactional#p33365

If you want to send an email when you manually change the user role, you'll need to modify the behavior of WordPress by adding a function like the following to your theme's functions.php file:

Code: Select all
function user_role_update( $user_id, $new_role ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = "Role changed: ".$site_url."";
        $message = "Hello " .$user_info->display_name . " your role has changed on ".$site_url.", congratulations you are now an " . $new_role;
        wp_mail($to, $subject, $message);
}
add_action( 'set_user_role', 'user_role_update', 10, 2);
 


If you only want to send an email when changing the user role to "Free Subscriber", you'll need to adjust the function code to check $new_role and only proceed with sending the email if it equals "subscriber".