We needed a feature where a user was automatically informed if their role changed on our eCommerce site. An example was that a user signs up, but we manually change their role to allow them to see different aspects of the site (such as pricing).
This code allows an automated email without the need of a plug-in
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 account has changed on " .
$site_url .
", you are now a updated customer and should be able to view pricing and place component orders, see order history and download current pricing in a PDF format. Please note that you may need to log out and then log back in.";
wp_mail($to, $subject, $message);
}
add_action("set_user_role", "user_role_update", 10, 2);