latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

role updated email sending when subscribing

Home Forums Community Forum role updated email sending when subscribing

This topic contains 4 replies, has 2 voices. Last updated by  Raam Dev 4 years, 9 months ago.

Topic Author Topic
Posted: Sunday Mar 18th, 2012 at 12:38 pm #8491
Epix Media
Username: epixmedia

Hi all, on one of my existing sites I have some code in the functions.php that emails a user when they’ve been updated from a “subscriber” to “s2Member level 1”. However I’ve just noticed its sending this approval email when they subscribe, along with the usual “thanks for registering” email…

My function looks like the following, I presume something in it is incorrect:

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 = “Account Approval: “.$site_url.””;
$message = “Hello “.$user_info->display_name .”, Thanks for registering! Your account has now been approved on “.$site_url.”. We look forward to seeing you at our next meeting.”;
wp_mail($to, $subject, $message);
}
add_action( ‘set_user_role’, ‘user_role_update’, 10, 2);

Cheers!

List Of Topic Replies

Viewing 4 replies - 1 through 4 (of 4 total)
Author Replies
Author Replies
Posted: Monday Mar 19th, 2012 at 1:43 pm #8552
Raam Dev
Username: Raam
Staff Member

Hello,

The set_user_role() function is called whenever a new user is created, so that explains why the user_role_update() function that you have in your functions.php file is being triggered when new users are created.

There’s no easy way to check “if this isn’t a new user, send the user role update email”, so I suggest trying something like this Eliminate Notify Email plugin to prevent the default email from being sent.

Posted: Tuesday Mar 20th, 2012 at 3:56 am #8584
Epix Media
Username: epixmedia

Hi Raam, I still want the user to get an email when they sign up, but I then want them to get a “account approved” email when I upgrade there role from “subscriber” to “s2member level 1″…

Is there no way of doing this?

Cheers,

Zoe

Posted: Tuesday Mar 20th, 2012 at 4:05 am #8585
Epix Media
Username: epixmedia

I’ve found a solution, as I am only using 1 s2member level I can put an if around it:

function user_role_update( $user_id, $new_role ) {
    if ($new_role == 's2member_level1') {
        $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 .", Thanks for registering! Your account has now been approved on ".$site_url.". We look forward to seeing you at our next meeting.";
        wp_mail($to, $subject, $message);
    }
}
add_action( 'set_user_role', 'user_role_update', 10, 2);
  • This reply was modified 4 years, 9 months ago by  Raam Dev. Reason: Added code tags to improve formatting
Posted: Tuesday Mar 20th, 2012 at 11:44 am #8612
Raam Dev
Username: Raam
Staff Member

Excellent! Thank you for sharing the solution. :)

Awarded user ‘Epix Media’ the Experienced badge.
Viewing 4 replies - 1 through 4 (of 4 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.