Support » Plugin: Object Sync for Salesforce » Mapping Multiple User Roles to custom SF field

  • Resolved emilyb6116



    I’m mapping contacts from SF into users in WP. I’m using the Members plugin by Justin Tadlock that extends user roles and allows users to be assigned to multiple roles. . Looks like roles are being stored in wp_usermeta as wp_capabilities. In the back end it is just checkboxes instead of a dropdown. I know you don’t claim support with 3rd party plugins but wasn’t sure where this one stood since it deals with an existing db user storing structure.

    My goal is to have a custom field in SF that syncs with the WP user role(s).

    I can set up the custom SF field whichever way makes sense (I originally thought a picklist), but I’m not sure how to map multiple points since they’re not separate.
    I assume it is in an array of some sort and that I will need to modify the data as it moves from SF to WP.

    Any idea of the best way to approach this?


Viewing 9 replies - 1 through 9 (of 9 total)
  • I got pinged on this, so I thought I’d quickly respond to the multiple role aspect.

    So, multiple user roles is not not a feature that’s exclusive to the Members plugin. It’s a standard feature of WordPress core. WordPress simply doesn’t expose the feature in the UI, which is what Members does. Therefore, any plugin that touches user roles or caps using the standard APIs should have no issues working with multiple user roles.

    Thanks for the clarification!

    Plugin Contributor Jonathan Stegall


    @emilyb6116 @greenshady yes, I think that’s accurate. Picklists should be able to map into checkboxes.

    Ok, I did some more testing and I think I’m closer!

    I have successfully passed the value of the multi-select picklist to WordPress, but now it won’t show in the checkbox list in the backend of WP user edit, or in the Users list in the Roles column (just says none for that user). However! It does show when I filter to users with that specific role. It will then correctly list the user that was updated with the new role.

    I’m mapping it to wp_capabilities, but should I also be mapping to wp_user_level?
    The meta_value for wp_capabilities is different in the database between my test user with the mapped role and another user with the same role but added in WP admin.

    Plugin Contributor Jonathan Stegall


    @emilyb6116 @greenshady I’ve done some testing with this. What it looks like (though I could be wrong) is that the members plugin is storing the capabilities data in a certain way (the role names are array keys), and that’s different than the plugin expects.

    It’s not a very big difference, or a very big lift to support it in this very specific case, so I’ve made a pull request that I think would do this. I wondered if either/both of you would want to test it.

    I’m hopeful that:

    1. It will give accurate support to the roles/capabilities feature of the members plugin
    2. It won’t cause any other issues in the plugin

    I’m pretty confident it won’t cause issues outside the plugin because I’m checking for the existence of this plugin’s function. As long as other plugins don’t use the same function, it should be okay.

    Let me know if you have a chance to test. If it seems solid, I’ll release it in the next plugin update.

    Plugin Contributor Jonathan Stegall


    I also noticed that this only works if the Salesforce field uses the array key values, rather than the more friendly names. In other words, it has to use “subscriber” instead of “Subscriber.” This is mainly a limitation of how Salesforce works.

    I just want to reiterate that Members does not store roles or caps. WordPress does this out of the box via the Roles API. Members merely provides a UI for users to do this without writing code.

    Basically, what I’m saying is that you shouldn’t look at this from the viewpoint of supporting the Members plugin. You should look at it from the viewpoint of supporting core WordPress’ user role system.

    Another good example would be to test against the bbPress plugin, which assigns additional roles to user accounts using the same Roles API.

    Anyway, just wanted to point that out in case you were building specifically against Members. You could run into similar scenarios with other role management plugins or just other plugins (like bbPress) that allow assignment of extra roles.

    Plugin Contributor Jonathan Stegall


    I see that. I’ve modified the fix so that it checks if the user is mapping the wp_capabilities field. This plugin is database field specific, so it’s not likely we’d deal with the roles API itself. But that field is, I think, totally reasonable for us to target in the way WordPress handles it, regardless of the plugin. I’ve tested it with members and with the multiple-roles plugin.

    I’ll try to release an update with this soon.

    Looks like this pull fixed everything on my end! I really appreciate the help on this.

    Agreed about the friendly names. I left the values alone but changed the API name for the picklist to match the role slugs in WP. Seemed to do the trick.

    Thanks to both of you for the support!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Mapping Multiple User Roles to custom SF field’ is closed to new replies.