WordPress.org

Forums

Send Email Notifications When User Role Changes With Role Name (1 post)

  1. Hardeep Asrani
    Member
    Posted 1 year ago #

    This script sends user an email when their some changes their role. It would be more accurate to send the role name (now it sends the slug). Any one knows how to send the role name, instead of slug.

    Here's the code:

    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);

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic