Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Allows users to save custom fields created in Azure to users in WP #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

peterspliid
Copy link

For example if I want a field called company, I first create the field in Azure, then I add the following code to my Wordpress plugin/functions.php file:

function custom_ms_fields($userID, $payload) {
    if (isset($payload['extension_Company']))
        update_user_meta($userID, 'company', sanitize_text_field($payload['extension_Company']));
}
add_action('b2c_new_userdata', 'custom_ms_fields', 10, 2);
add_action('b2c_update_userdata', 'custom_ms_fields', 10, 2);

This will save the information the user entered in the company field to the user meta field 'company' in Wordpress

@msftclas
Copy link

msftclas commented May 2, 2018

CLA assistant check
All CLA requirements met.

@peterspliid
Copy link
Author

peterspliid commented May 8, 2018

The new commit is needed if I have a Wordpress installation in different languages, and want the user to view the authentication site in the same language as Wordpress. With the committed changes, I have added the following to my functions file:

function npa_azure_lang($authorization_endpoint) {
    return $authorization_endpoint . '&lang=' . $_COOKIE['npa_lang'];
}
add_filter('b2c_authorization_endpoint', 'npa_azure_lang');

where $_COOKIE['npa_lang'] is the language identifier.

@ArthurDumas
Copy link

@peterspliid, I just started using this AD B2C Wordpress plugin and I like your changes for updating user meta fields from the AD B2C custom attributes.
May I ask why you require the use of an action hook rather than just calling update_user_meta() in b2c_verify_token() after the calls to wp_insert_user() and wp_update_user(). Is it so you can more easily control which AD B2C custom attributes are added to Wordpress?
Thanks for the work on this plugin!

@peterspliid
Copy link
Author

peterspliid commented Apr 10, 2019

@ArthurDumas Sorry for the late response. Yes you are correct. You might want to map fields from AD B2C to your custom wordpress fields, or process or verify the data before inserting it. It is generally good practice to use actions or filters when it comes to custom data

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants