User role not set with the User Synch plugin

Hi,
I have installed User Sync and I am surprised to see that when a new user register in my Master suite that this user account is automatically created in my slave site but the ROLE is not set.

Is it normal and if not, what can I do to force the role to be set ?

Thanks,
Eric

  • Michelle Shull

    Hi, Eric!

    Your synched users should have the same role on the subsite as they do on the master site, so something is going a bit wrong here. Can you try enabling debug mode, like we explain in the usage guide at the bottom, here: https://premium.wpmudev.org/project/wordpress-user-synchronization/#product-usage

    Copy the contents of the log file created here so we can see where things are going wrong.

    Thanks, Eric!

  • Eric

    Hi,
    @Ashok I could not find how to enable the debug mode on the slave, even after disabling sync and re-enabling sync, I have done further investigation to discover that the setting on the master is corrupted.

    When I first installed User Sync, the default role on the master was set to Customer from WooCommerce.

    As I do not have that role set on my slave site, the role was left blank (not set). So, I went back to the master site and I have changed the default role on it to be set as "Subscriber".

    Then, all new users on my slave site continued to be set as blank (not set).

    I have then decided to syn the users with another slave site which had WooCommerce installed on it and surprised ! All users got added as "Customer". As if the Master was still setting using the role "Master" rather than the new default setting which is "Subscriber".

    So, that look to me as a database issue with the User Sync setting.

    Is there a way to correct this in the database or somehow ?
    I would rather not have to de-install the plugin on my master and clear the db but if it is the only solution, I will do :slight_frown:

    Thanks for your help,
    Eric

  • Michelle Shull

    Hi, Eric!

    The user role is stored in the wp_usermeta table, under wp_capabilities. We're going to need to look in the wp_usermeta table for the meta value that's been added for the Customer role. Then, you can run a query to change the wp_capabilities to reflect the subscriber role, rather than Customer, like so:

    UPDATE wp_usermeta
       SET meta_value = 'a:1:{s:10:"subscriber";b:1;}'
     WHERE meta_key = 'wp_capabilities'
       AND meta_value = 'CUSTOMER ROLE VALUE GOES HERE'

    Always take a backup of your database before you make any changes or run any queries, just in case you need to restore it.

    I took a screenshot of the wp_capabilities meta value for a subscriber in PHPMyAdmin on my own server for you to use as a reference here to find the Customer meta meta value.

    Hope this helps!

  • Eric

    Hi Michelle and all,
    the problem is still the same and worse than that, I have just discovered that when I modify something, such as the password on the master, the information is not propagated from the master to all slaves.

    So far, I have tried the following:
    1) Uninstalled the plugin and clear the database, then re-install and re-configure everything
    2) Made sure that the role was set properly in the db

    Note: My MASTER is one of the site (out of 4) on my WPMU installation. Slaves are on single WP installation under sub-domains.

    I have attached logs

  • Eric

    Hi Michelle and all,
    I have done further investigations...
    It appears that it might be related to a conflict with how WooCommerce manage roles.

    My MASTER site is a WooCommerce Website and out of the 3 other sites I have as slaves, 1 of them is also using WooCommerce. And guess what... this is the only one where the role is set properly...event if on my Master, the default role is Subscriber !

    So, is there something we can do or check to solve this ?

    /Eric

  • jamie

    Eric,

    I am in almost exact scenario. I have 4 sites where one sub site is woocommerce.

    I decided to make the primary woocommerce site as well to make as much data as possible sync from master to sub. We also decided we may sell some branded products from the master, so the woocommerce was applicable for more than one reason.

    That said, I am going to finish configuring sub sites today - complete with registration redirects to master. After that I will be doing some testing to see if there is any patterns worth documenting.

    If you think about it, the roles are a dangerous bit of user meta data to be passing around site to site, due the security ramifications. Perhaps there is a feature in WP that has been implemented since this plug was last modified. I am hoping that WPMUDEV will be able to fix this up. I wouldn't mind if the role of administrator was not eligible for cross site sync, but I digress.

    As I mentioned, once I get over a couple hurdles I will be doing some testing...keep you posted.

    Talk soon,

    Jamie

  • Michael Bissett

    Hey @Eric,

    While we're waiting on @jamie's results here, a couple of questions:

    Note: My MASTER is one of the site (out of 4) on my WPMU installation. Slaves are on single WP installation under sub-domains.

    Do you mean to say that your master site is part of a Multisite install? If so, is it the main site, or a subsite on the install?

    Also, just to confirm (pays to keep the details straight), the slave installs that you're syncing to are separate single site installs (i.e. not part of a Multisite), correct?

    My MASTER site is a WooCommerce Website and out of the 3 other sites I have as slaves, 1 of them is also using WooCommerce. And guess what... this is the only one where the role is set properly...event if on my Master, the default role is Subscriber !

    What happens if WooCommerce is disabled temporarily on your Master site, does that make a difference here? By that, I mean, does the role get synced properly to the slaves that don't have WooCommerce enabled?

    Please advise,
    Michael

  • Michael Bissett

    Hey @Eric, thanks for the additional info! :slight_smile:

    I'd like to have a deeper look at your Multisite here, see how it's set up (for my own testing over here), and check out that database of yours. Could you please send in the following via our secure contact form:

    - Mark to my attention, the subject line should contain only: ATTN: Michael Bissett
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - Include WordPress admin access details (login address, username & password)
    - Include FTP log-in details (hostname, username & password)
    - Include cPanel details (will need to check out the database, so phpMyAdmin or similar)
    - Include any relevant URLs for your site

    On the contact form (linked to below), please select "I have a different question", this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thanks a bunch! :slight_smile:

    Kind Regards,
    Michael

  • Eric

    Hi Michael,
    I have created a new MASTER environment on a single WP installation and I got the exact same result.

    My new MASTER (on WP single site) is configured the exact same way as my original master site on my WPMU installation. Same theme, same plugins and using Woocommerce to handle accounts.

    Results of my test.
    1) After the first synchronization, all accounts have been created on my slave and the role was NOT set.
    2) If I modify a user password on the MASTER, via the admin interface, the new password is propagated to the slave BUT, the role is set back to "None" :slight_frown:
    3) If I modify the user password using the theme interface... nothing happen. The new password is set properly on the master but nothing is propagated to the slave.

    Please note that I have logs available.
    I will also send you connection information to both (master and slave) environment so that you can check by yourself.

  • Michael Bissett

    Hey @Eric,

    I do see what you mean regarding the user roles on your test sites, but I'm not able to reproduce this over on my own test sites, the user roles still get copied over properly for me. I tried setting up two new sites, creating test users in the master site, and having WooCommerce enabled on the main site.

    I'm curious, what if you were to try doing a test sync with only WooCommerce enabled on the master site (in addition to User Synchronization), no other plugins, and having a default theme set up on both your master & slave sites? It's possible that there's something else here throwing a wrench in the works.

    Please advise,
    Michael

  • Eric

    Hi Michael,
    thanks for your quick response.

    Have you look at my Master and Slave sites using the info I sent you ? I want to know before I start to disable all the plugins in those until I find out what is causing this issue... sorry, those issues.

    This being said, have you test modifying the user password via the process "Lost password" ? In my case, it is not working. The password is only modified on the master and is not propagated.

    /Eric

  • jamie

    Eric,

    What plugins are you using? Maybe there is a common pluging we are both using that is the culprit.

    I am travelling today, but we can compare notes on this if you like.

    Off thentop of my head, i am using theme my login, woocommmerce, wcvendors, formidablepro...

    Jose said once before that if we are not using wp_ prefix it might cause an issue. I always default to that, but i am going to double check the databases...perhaps in some migrations they were altered.

    I am also going to remove some sites from the sync, simplify to a master and a single slave. Maybe i can narrow down a single site causing the sync issue??

    Still trying...

    Jamie

  • Michael Bissett

    Hey @Eric,

    I did have a look at your sites here, but I'm not able to reproduce this behavior over on my own test sites. Setting them up like this:

    Master Site:
    - Theme: Twenty Fifteen
    - Plugins active: User Synchronization, WooCommerce, WPMU DEV Dashboard
    - Default Role: Subscriber

    Slave Site:
    - Theme: Twenty Fifteen
    - Plugins active: User Synchronization, WPMU DEV Dashboard
    - Default Role: Subscriber

    I was not only able to sync over my users (and their roles) properly, but I was able to change the password for a user on the Master site, and have it be changed on the Slave site as well.

    Regarding this comment of @jamie's though:

    Jose said once before that if we are not using wp_ prefix it might cause an issue. I always default to that, but i am going to double check the databases...perhaps in some migrations they were altered.

    I did notice that your master site does use a different prefix, I'd want to try using a default prefix, and seeing if that helps, in case the conflict testing doesn't bring up any further results.

    Kind Regards,
    Michael

  • jamie

    Back from vacation...

    I have confirmed that my master site and one sub site do NOT have the wp_ prefix. These accounts are hosted by Godaddy and they have a more robust naming convention.

    I was wondering can someone ask Jose if the problem with the wp_ nonconformity applies to both master and slave. I am wondering if I make the master site wp_ it will work...I will try in the meantime...

    Also, Can I hardcode the database prefix? I will start poking around plugin.

    I guess I found out why my install is not working.

    Jamie

  • Michael Bissett

    Hey @jamie, hope you had a pleasant vacation! :slight_smile:

    I was wondering can someone ask Jose if the problem with the wp_ nonconformity applies to both master and slave. I am wondering if I make the master site wp_ it will work

    I can ask him that, sure. It should work if the master site has a prefix for wp_, since in my own testing, at one point I also tried syncing from the master site (which had the wp_ prefix), to a subsite with a different prefix.

    Also, Can I hardcode the database prefix? I will start poking around plugin.

    Hardcode the database prefix? Not certain what the purpose of that would be, could you elaborate please?

    Kind Regards,
    Michael

  • Jose

    Hello there @Eric and @jamie,

    Apologizes for my absence in the thread for so long. Had a time off plus several critical issues to work on.

    I was wondering can someone ask Jose if the problem with the wp_ nonconformity applies to both master and slave. I am wondering if I make the master site wp_ it will work...I will try in the meantime...

    According to what I see in the code, both master and slave needs to be using the default prefix 'wp_' in order for roles to sync correctly.
    I was really confused when you said in one of your first posts that you were using the default prefix. Thanks for double checking :slight_smile:
    Hard-coding the prefix won't be an easy task -except the prefix is the same in both sites- because you need to add some logic to change the prefix for master site when reading the role and switch to the slave site prefix when writing/syncing the role.

    I'll discuss this with the lead developer and get back to you either with a proper solution or at least with a workaround to force some specific role.

    Thanks for your patience :slight_smile:

    Cheers,
    Jose

  • jamie

    My apologies for not checking all installations, Jose. I should have been more thorough.

    If i wanted to specify a prefix, i would need to isolate each write to the database. After looking around and based on your comments, it is probably not ideal to hardcode.

    Thank you for taking a look into this. In the meantime i am going to see if i can write a function to maintain roles locally on each site. Not sure about the password issue...ill have to test further.

  • jamie

    Well,

    It does not appear to be setting roles, since my original admin account is not recognized as admin. I am trying to reset the admin info on godaddy's site and their database browser doesn't see any daabases...but they are there. Are we having fun yet? :slight_smile: It's reparable, but....

    I just need to create an account on the other site with same credentials...I don't even need to continually sync. If anyone can suggest a function I can add that will register or create a user on another wordpress install, I am all ears.

    Still playing with the plugin...will continue to test once I can get back in to site.

  • jamie

    Long story short I had to reinstall wordpress with the wp_ at creation (database edits just seemed unstable) and now the roles are syncing like a charm.

    If there are plugin specific roles, those plugins need to be installed for the role to be applied - or at least add those roles to the list of options - otherwise it will have role of none.

    Still lots of testing and need to familiarize myself so I can use this effectively.

    Thanks for the help.

    Jamie

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.