• Resolved sharju

    (@sharju)


    I am trying to map a custom (picklist) field from Salesforce to WordPress User Role field (wp_capabilities).

    I know the User Role on WordPress’s side uses the wp_capabilities field in the mapping drop down, and in the WordPress database I have found that the formatting of the data needs to be “serialized” – one of my rolls for example is listed as “a:1:{s:11:”boardmember”;b:1;}” in the WordPress database (specifically the wp_usermeta table, meta_value field).

    In Salesforce I have set up a picklist with the different user rolls, and they use simple text in the data that gets sent from Salesforce to WordPress. Examples – “boardmember” or “report_member”

    When the data gets sent to WordPress it is sent to the correct field in the database, it just doesn’t format the data correctly in the “serial” format. So, WordPress lists “No role for this site” in the User Role field on the front end. In the database I can see the example entry as plain text “boardmember” listed for wp_capabilities.

    I have tried setting up the “serialized” version of the data as the data that gets sent from Salesforce – for example I set the data that gets sent as “a:1:{s:11:”boardmember”;b:1;}” (without the first and last quotes) – but when WordPress receives it, it adds extra serial data it so in the database it shows “s:29:\”a:1:{s:11:”boardmember”;b:1;}\”;”

    I am looking for help to get the correct formatting that I need to add to Salesforce in order for WordPress to receive the data and list it properly in the database. Or, are there settings I need to change in WordPress, or the Object Sync for Salesforce plugin to accommodate the communication of the User Role data in the correct format?

    Thank you for any help.

    • This topic was modified 2 years, 9 months ago by sharju.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jonathan Stegall

    (@jonathanstegall)

    I think I’ve seen this done in a couple of ways. I’ll describe what I’m aware of and maybe that can put you in a good direction.

    1. Store the roles in Salesforce in a Multi-Select Picklist instead of a single picklist. This allows the plugin to receive the value as an array (even if there is actually only one value selected). WordPress is pretty good at serializing arrays on its own so this works well with how WordPress already handles the capabilities field.

    2. In a way that requires code in either your theme or in an add-on plugin, you could also use a developer hook to populate the roles as individual items. In other words, detect the single value that is coming from Salesforce and assign it with the add_role method in WordPress. At MinnPost we do this to set a membership level for donors. You can see how that works on GitHub. This is maybe more complicated but if your Salesforce structure is not flexible, it is doable.

    Thread Starter sharju

    (@sharju)

    Thank you for the very quick response.

    I had actually tried your first solution just before submitting this support ask, and WordPress still added the items database without serializing it. I sent multiple roles, and it listed the data as “boardmember” “report_member”

    But, I hadn’t cleared the plugin cache, and I guess I needed to wait longer, because the change to the Multi-Select pick list finally worked.

    The Multi-Select picklist was the answer.

    Thanks again for the help and quick response!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘User Role (wp_capabilities) mapping correct formatting’ is closed to new replies.