Hello so I’m using Ultimate Member plugin with S2member pro plugin and ultimate members has their own roles called community roles. Also S2member has their own roles called s2member_level1
i’m trying to combine those 2 that whenever s2member_level1
role has some user ultimate member community role also would change to premium for example. i’m using this code to achieve that.
global $ultimatemember;
$user_id = get_current_user_id();
if( current_user_is(s2member_level1) ) {
update_user_meta($user_id, 'role', 'premium');
} elseif ( current_user_is(s2member_level0) ){
update_user_meta($user_id, 'role', 'member');
} else {
}
It works like if some person has s2member_level1
role than it would update ultimate member role to premium and if S2member_level0
that means member is without membership or its already expired than it would change also ultimate member role back to member
which is subscriber for wordpress role.
Problem:
It works only if i refresh wordpress admin panel user section than everything updates if i don’t refresh that and user s2member role changed it does not react user can still access to only premium users section but when i refresh or access users wordpress admin panel section all roles that should update without this action updates.
Why this happens and how to fix it?
For people like me solution:
I have added
delete_option( "um_cache_userdata_{$user_id}" );
You may ask whats this, well plugin ultimate member has very stupid caching system that if you want use some custom things it does not include their cache cleaning so whenever u go to users its one of the places where ultimate member cleans cache when page is loaded, better include this code to all custom codes that u will do in future because it wont work simply because of cache problem…
I don’t undestand why they need to cache user data, anyway i got the same problem wit advanced custom field.
I use ACF to display and manage custom user field on user profile page.
But every changes on this page will not be visible on their modal info page because there is their cache.
I have deleted all old cache then i turned off:
Ultimate Member -> Settings -> Advanced -> Stop caching userâs profile data
Then they get data every time from usermeta with key submitted.