Yesterday I shared a code which sends an email to the user when the user updates their profile. Today I have something similar, but a bit different. This code sends an email the user when the user's role has changed.
It's a great way to let a member know about the role changes that you'll make. It's also a great trick if you're running a WordPress site with bbPress forum or multiple wirters & contributors.
Just add following to your functions.php:
That's it.
It's a great way to let a member know about the role changes that you'll make. It's also a great trick if you're running a WordPress site with bbPress forum or multiple wirters & contributors.
Just add following to your functions.php:
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);
That's it.