WordPress Send email notification when user role is changed |
X

Congrats, You are Subscribed to Receive Updates.

WordPress Send email notification when user role is changed


Hi, you are here to notify your users automatically, when  you change their user role(here i considered you as the site owner or the admin of your WordPress CMS).  So add the following function on your, WordPress, theme’s functions.php or your plugin’s main file. It will hook the function automatically.

kv_user_role_change_email

function kv_user_role_change_mail( $user_id, $new_role ) {
        $site_url = get_bloginfo('wpurl');
        $user_info = get_userdata( $user_id );
        $to = $user_info->user_email;
        $subject = $site_url." Role has been  changed ";
        $message = "Hi,  " . $user_info->display_name .PHP_EOL. " Recently, your role has changed on ".$site_url.", congratulations you are now an " . $new_role."!".PHP_EOL. "Login and check your Privileges". PHP_EOL.  wp_login_url(). "" ;
        wp_mail($to, $subject, $message);
}
add_action( 'set_user_role', 'kv_user_role_change_mail', 10, 2);

If you have any problem with it. comment below. I will help you.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

2 comments

  1. commenter

    How can I get the notification on site footer? Have any codex?

Reply to Varadharaj V Cancel reply

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar