Viewing 10 replies - 1 through 10 (of 10 total)
  • @ufo56

    You can look at this code snippet for Role change emails.

    https://github.com/MissVeronica/UM-Role-is-changed-email

    Thread Starter ufo56

    (@ufo56)

    Seems that its outdated or something has changed.

    Added some lines to log and nothing appears in debug.log

    Seems like set_user_role is not triggering.

    function custom_role_is_changed_email($user_id, $role, $old_roles) {
        error_log("Role change ID: $user_id");
    
    
        if (!empty($old_roles) && !in_array($role, $old_roles)) {
            $all_roles = UM()->roles()->get_roles();
    
            $old_role_names = array();
            foreach ($old_roles as $old_role) {
                $old_role_names[] = $all_roles[$old_role];
            }
    
            $args['tags'] = array('{role}', '{old_role}');
            $args['tags_replace'] = array($all_roles[$role], implode(',', $old_role_names));
    
            um_fetch_user($user_id);
    
            error_log("Sending email to: " . um_user('user_email'));
            UM()->mail()->send(um_user('user_email'), 'role_is_changed_email', $args);
        } else {
            error_log("No role change or role already exists for User ID: $user_id");
        }
    }
    • This reply was modified 11 months, 1 week ago by ufo56.

    @ufo56

    You can try both the set_user_role and um_set_user_role action and filter hooks.
    First one should be WP All Users page setting.

    • This reply was modified 11 months, 1 week ago by missveronica.
    • This reply was modified 11 months, 1 week ago by missveronica.
    Thread Starter ufo56

    (@ufo56)

    Still nothing,

    add_filter('um_set_user_role', 'my_set_user_role_test', 10, 3);
    function my_set_user_role_test($new_role, $user_id, $user) {
       
        error_log("User ID: $user_id, New Role: $new_role");
    
    
        return $new_role;
    }
    
    function test_set_user_role($user_id, $role, $old_roles) {
        error_log("User ID: $user_id");
        error_log("Old Roles: " . implode(', ', $old_roles));
        error_log("New Role: " . $role);
    }
    
    add_action('set_user_role', 'test_set_user_role', 10, 3);

    @ufo56

    How do you change the User role?

    Thread Starter ufo56

    (@ufo56)

    From user edit page

    @ufo56

    You can remove the code snippet and try this plugin “Role Change Email”

    https://github.com/MissVeronica/um-role-change-email

    Thread Starter ufo56

    (@ufo56)

    Still did not work, some functions just does not trigger on my site. Don’t know why…

    I used uncanny automator now.

    @ufo56

    1. Try to do a Theme/Plugin conflict test.

    https://docs.ultimatemember.com/article/96-how-to-do-a-plugin-theme-conflict-test

    2. Enable PHP error logging if the debug will give some more info about this issue.

    Read this guide: “How to enable debug logging”

    https://docs.ultimatemember.com/article/1751-enable-debug-logging

    You will probably get a PHP log file with notices and errors in this file:
    .../wp-content/debug.log

    Post the content of this file here in the Forum and we can give you the PHP error explanation. For best formatting use the Forum’s CODE format.

    Plugin Support andrewshu

    (@andrewshu)

    Hi @ufo56

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Welcome e-mail after changing role’ is closed to new replies.