Hello,
I am using Authorizer (https://wordpress.org/plugins/authorizer/) to authenticate users from a CAS server.
I have also created a custom post type that holds information about the logged in users.
My question is... Is there a way to assign fields from the SSO server to the created custom post fields ?
Thank you.
Is there a way to assign fields from the SSO server to the created custom post fields ?
Hi, I'm not really familiar with these 3rd-party systems CAS, SSO, and Authenticator, so I'm not sure what they offer in terms of an API. There is no built-in integration with Toolset that I'm aware of. The other end of the system is unknown, but I can show you on our end of the system how to set Types custom field values with PHP. In general, you would create your desired custom fields in Types and assign those field groups to the post type you're using as a proxy for logged-in users. To set those field values when someone logs in, you would need to know how to trigger some PHP code when that login process is complete. That's what I mean by an API for their system, you would need to know how to set up listeners for those events, and you would need to know how to access the logged-in user's information in the CAS system, as well as the corresponding proxy post ID, during those login events.
Let's assume they offer an API that provides all that information, including the user's age. You want to copy the user's age into the Types custom field you created. The Types custom field has a slug of "toolset-age" in wp-admin. You have access to the user's age from the other system in a variable called $cas_age. You have access to the user's proxy post ID in a variable $proxy_id. The code to set the custom field value would look something like this:
update_post_meta( $proxy_id, 'wpcf-toolset-age', $cas_age );
You use WP's native update_post_meta function to update the Types custom field toolset-age for post with ID $proxy_id, and set the value to $cas_age. Note that the wpcf- prefix is required here, prepended to the slug you chose for this field in wp-admin.
Again, this is just an example showing the Toolset side of things. I have no idea how you would tie in the proxy post ID, or how you would trigger this code using some 3rd-party API. That would require some assistance from their support team. Let me know if you have questions about this, or if you need more information to facilitate that discussion with their team.
Documentation for update_post_meta: https://developer.wordpress.org/reference/functions/update_post_meta/
I finally decided not to make a custom post type ofr the logged in users and use the native wordrpess users to keep these information. I added some extra custom user fields to hold information for the registered users.
I also have a custom post type that holds information about the services provided to the registered users.
So my new question now is, could i create many to many relationship between wordpress users and the custom post type "services"?
Many users can be provided a service, and many services can be provided to a user, therefor a many-to-many relationship is needed.
Toolset's relationships are designed for relating posts to other posts, not to Users. A proxy post type is required to manage this type of relationship. Also, it is not possible to create front-end parametric search Views for Users so if you plan to implement front-end searches filtering by these fields, a proxy post type is required anyway. The custom fields should be stored in the proxy post type so you can use them in a custom search filter for the proxy post type. We have more information about setting up a proxy post type to facilitate post relationships and User search available here: https://toolset.com/documentation/post-relationships/how-to-create-custom-searches-and-relationships-for-users/
My issue is resolved now. Thank you!