Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing user role in the back-end and UM cache #946

Closed
MissVeronica opened this issue Nov 28, 2021 · 0 comments
Closed

Changing user role in the back-end and UM cache #946

MissVeronica opened this issue Nov 28, 2021 · 0 comments

Comments

@MissVeronica
Copy link

MissVeronica commented Nov 28, 2021

Is your feature request related to a problem? Please describe.
When changing user role in the back-end via WP - Users the UM cache must be updated and removed manually, which is often forgotten by the UM administrators. Implementing this feature will improve the user satisfaction with UM and reduce issues in the UM Forum.

Describe the solution you'd like
An UM action to clear UM cache for the user when user role is changed by WP.

add_action( 'set_user_role', 'my_user_role_remove_cache', 10, 3 );
function my_user_role_remove_cache( $user_id, $new_role, $old_roles ) {
    if ( defined( 'um_plugin' )) {
        if ( !UM()->options()->get( 'um_profile_object_cache_stop' ) ) {
            if ( is_numeric( $user_id ) && $user_id > 0 ) {
                delete_option( "um_cache_userdata_{$user_id}" );
            }
        }
    }
}

Additional context
UM Forum issue:
https://wordpress.org/support/topic/role-change-issue/

@MissVeronica MissVeronica changed the title Changing user role in the backend and UM cache Changing user role in the back-end and UM cache Dec 3, 2021
nikitasinelnikov added a commit that referenced this issue Dec 15, 2021
- fixed PHP notices;
@nikitasinelnikov nikitasinelnikov self-assigned this Dec 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants