Automatically sync with WP roles
-
Is there a way to sync UM roles to WP roles? I have already setup the “Sync with WordPress Role” section properly, but anytime a new user registers, we have to click the “Sync/update all existing users” button before any changes are made to the new users’ accounts. Is there a way to automatically sync all user roles after a new user registers an account?
-
Hi @pigneedle,
Have you linked your role to the WordPress role in Ultimate member -> Roles -> your role and Link to WordPress role?
Do you have any security/roles plugins installed on your site?
Please make sure you have the latest 1.3.88 version of the Ultimate member installed.Regards.
As I mentioned in the original message, I have already setup the “Sync with WordPress Role” and set a WordPress role in the “Link to WordPress role” drop-down. The only plugin we have that interacts at all with Ultimate Member is the “Pricing Deals Rules” plugin from VarkTech, which I will test tonight when there is less traffic on the site. We are using the latest version of Ultimate Member (1.3.88).
-
This reply was modified 7 years, 5 months ago by
pigneedle.
Ok, I’ve done a bit of testing now that the site has less traffic on it.
1. I create a new user with a form to automatically register a user with the “PRO” role. This is set to auto-approve registration.
2. I am auto-logged in as the new user (desired functionality). On the WP Users list, I see the new user, but it has two roles assigned: “Subscriber” and “Wholesale”. The pricing deals associated with this user are not reflected in WooCommerce. I log out and then back into WP with the new user. Pricing deals are still not reflected.
3a. I go into the UM admin panel, select the “PRO” role, and click “Sync with WordPress Role”. I cannot see the pricing deals for that user’s role just by refreshing the page after I click this button.
3b. I log out and then back into WP with the new user. I can now see the pricing deals.
I have tried disabling all other plugins to isolate the issue, but I see this behavior by default. Is there a way to automatically perform the “Sync with WordPress Role” function after a user registers? Is the plugin supposed to do this by default, or is it necessary to manually click the “Sync” button every time a user registers?
In “um-actions-user.php” I changed these lines:
/*** *** @sync with WP role ***/ add_action('um_after_user_role_is_updated','um_setup_synced_wp_role', 50, 2); function um_setup_synced_wp_role( $user_id, $role ) { global $ultimatemember; $meta = $ultimatemember->query->role_data( $role ); $meta = apply_filters('um_user_permissions_filter', $meta, $user_id ); $wp_user_object = new WP_User( $user_id ); if ( isset( $meta['synced_role'] ) && $meta['synced_role'] ) { $wp_user_object->add_role( $meta['synced_role'] ); }elseif( ! $wp_user_object->roles ) { // Fallback user default role if nothing set $wp_user_object->add_role( 'subscriber' ); } }
to:
/*** *** @sync with WP role ***/ add_action('um_after_user_role_is_updated','um_setup_synced_wp_role', 50, 2); function um_setup_synced_wp_role( $user_id, $role ) { global $ultimatemember; $meta = $ultimatemember->query->role_data( $role ); $meta = apply_filters('um_user_permissions_filter', $meta, $user_id ); $wp_user_object = new WP_User( $user_id ); if ( isset( $meta['synced_role'] ) && $meta['synced_role'] ) { $wp_user_object->set_role( $meta['synced_role'] ); }elseif( ! $wp_user_object->roles ) { // Fallback user default role if nothing set $wp_user_object->set_role( 'subscriber' ); } }
It looks like roles are syncing properly now.
Hello PigNeedle ! I am wondering if this change is still working for you. I just deployed it. Looks like the primary change was to change ‘add_role’ to ‘set_role’
I am stunned there is no option to automatically sync these two role tables!! Say you are using Profile Builder which uses the WP User Roles for displaying User Lists in a directory, changing only the UM Community Role will not show any change in status if you have filtered via the USER TABLE. Sure clicking on Sync will fix it but if you have multiple user levels and PAID SUBSCRTPTIONS in WooCommerce using UM… There is a REAL NEED to have the Sync happen automatically on any change to the UM community role change.
I will be testing using the following plugins — WooCommerce + UM + Profile Builder ( for user directory listing — its the most powerful I could fine to build a custom membership directory — relies on WP User Role also creates a user directory in the user table with any default user role in WP Users) Syncing these two tables for special applications on an automated basis is essential.
Did the simple code change above really make this automatic ??
-
This reply was modified 7 years, 4 months ago by
zzb.
I tried this and made sure that the corresponding role between the two tables were selected in the User –> Sync with WordPress Roles. Still does not seem to update when a paid for UM membership level subscription is made or renewed! Only synced when manually clicking the sync button by hand.
Please…. anyone have any idea on how to have perhaps a chron job run that would run these “sync” jobs ??? I left a ticket for the UM Support team. Crossing fingers!
I’d be interested to know whether you heard anything @zzb – I’m needing the same functionality and can’t seem to get it to sync without clicking the button.
The changes I posted are still currently deployed on my site and functioning properly. @zzb I am not sure what issue you are experiencing, but this issue is resolved for me using the fix I posted above.
Note: make sure to disable caching while applying this fix. You may re-enable caching after the fix has been applied.
@pigneedle The only way I can get this to work, even after the file edit you mentioned above, is to edit the user and click the Save button. Once I do that, the roles do sync, but I can’t expect to do this for every new member who comes along. So you’re saying that, on your site, the syncing is happening automatically?
Yes. You are probably experiencing a conflict from other plugins if there is still an issue.
This is a dev site with very little installed right now other than Ultimate Member and a few of its extensions. I’ll do some more testing and see if I can get this to work. It’s possible I may need to test with a new user created AFTER the file change – I was still checking one I created prior.
did answer on wrong topic sorry
-
This reply was modified 7 years, 4 months ago by
vincent01.
Andrea — I tried using the beta UM version. The problem now is they don’t seem to have the hooks for WooCommerce done yet. I decided to revert back to Profile Builder and their subscription module. They use the standard wp_user_ role table meta data for their member roles function. Their directory display provides a fair amount of customization and I am using Stripe gateway. In fact UM removed their Sync feature in the beta version! Should work but however you still need a way to sync between UM meta data and WP role data if your directory output is using wp roles. By the way…. the direct communication and response from UM has been very poor dispite several support tickets. No response.
-
This reply was modified 7 years, 5 months ago by
- The topic ‘Automatically sync with WP roles’ is closed to new replies.