Email Notification on Approval

Hi,

By default, new members have s2memberlevel0 capabilities, we have to manually update their user profile to level1 if they’re approved.

Is there a way to automaltically notify a member that thier account has been upgraded/approved?

Cheers,

Add this as an mu-plugin:

<?php
function kts_user_role_approve_email( $user_id, $old_user_data ) {
	$site_url = site_url();
	
	// get old user info
	$old_roles = $old_user_data->roles;
	 	
	// get new user info
	$user_info = get_userdata( $user_id );
	$new_roles = $user_info->roles;
	
	// send email when membership is first approved, i.e. from subscriber to s2member_level1
	if( in_array( 'subscriber', $old_roles ) && in_array( 's2member_level1', $new_roles ) ) {
		$to = $user_info->user_email;
		$subject = 'Welcome to the ' . get_bloginfo ( 'name' ) . ' website!';
		$message = 'Hello, ' . $user_info->display_name . '!' "\r\n\r\n";
		$message = 'Your membership registration has now been approved on the ' .$site_url. ' website.' "\r\n";
		wp_mail( $to, $subject, $message );
	}
}
add_action( 'profile_update', 'kts_user_role_approve_email', 10, 2 );

thanks for the reply, im a little bit unfamiliar with must use plugin, can i also have that pasted inside the functions file?

Yes, just remove the <?php tag at the beginning.

But I hope you’re using a child theme, otherwise this will get overwritten when you update your theme.

Will try this out! Yeap, im using a child theme. I’ll learn how to use muplugins too. thanks for the info!

Hi, i did try this and added the code without the opening php tag inside my fucntions.php , i got 500 error right after i hit update.

Where did you put it in that file. If you put it at the top, then you would still need the tag. I assumed you would just be adding it at the bottom.

Hi,

have a look at our addon: s2Emails

And our website:
https://s2plugins.com
https://s2plugins.com/s2emails-plugin/

With this addon you can also send automated emails when user’s role has changed. Might be useful for you.

*flies away *

Hi Sorry, i just saw your reply. will that work on FREE version of s2member plugin?

Hi,

can i get the working code provided above, all i need is a simple functionality. nothing complex, 30 pounds is just a little bit pricey to me. please.