Skip to content

Instantly share code, notes, and snippets.

@INDIAN2020
Created February 7, 2013 16:10
Show Gist options
  • Save INDIAN2020/4731974 to your computer and use it in GitHub Desktop.
Save INDIAN2020/4731974 to your computer and use it in GitHub Desktop.
user role change email
/*
Send email notification when user role changes
Adding this snippet to the functions.php of your wordpress theme will send the member an email notification when the user’s role has changed.
*/
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment