Im Ordner wp-content/mu-plugins/ (“must use” plugins) wird eine Datei s2-role-change-handler.php angelegt.
/wp-content/mu-plugins/s2-role-change-handler.php
In diese Datei wird folgender Code eingetragen:
<?php add_action('init', 's2_role_change_event_handler::init', 1); class s2_role_change_event_handler { public static $user_id; public static $user_old_role; public static function init() { global $pagenow; if (!is_admin()) { return; // Not applicable. } if ($pagenow !== 'user-edit.php') { return; // Not applicable. } if (empty($_REQUEST['user_id'])) { return; // Not applicable. } if (!current_user_can('edit_users')) { return; // Not applicable. } $user = new WP_User((int) $_REQUEST['user_id']); static::$user_id = $user->ID; static::$user_old_role = reset($user->roles); add_action('set_user_role', 's2_role_change_event_handler::event', 10, 2); } public static function event($user_id, $new_role) { if ($user_id === static::$user_id && $new_role !== static::$user_old_role) { if (($user = new WP_User($user_id)) && $user->exists()) { // Replace $subject, $message, $headers with your information $subject = 'User Role Update'; $message = 'Hello '.$user->first_name.'!'."\r\n"."\r\n".'This is to notify you that your User Role has been changed to "'.$new_role.'".'; $headers = 'From: Awesome Site <hello@awesomesite.com>'; wp_mail($user->user_email, $subject, $message, $headers); } } } }
Quelle: https://s2member.com/kb-article/how-do-i-send-an-email-when-the-membership-level-is-changed/
Schreibe einen Kommentar