HI kunalnagar,
could you please try this function?
add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile' );
function update_base_user_profile($user_data, $identity)
{
$temp_user = new WP_User($user_data->ID);
$temp_user->remove_role('subscriber');
xprofile_set_field_data('First Name', $user_data->ID, $identity->name->givenName);
xprofile_set_field_data('Last Name', $user_data->ID, $identity->name->familyName);
}
Thread Starter
Kunal
(@kunalnagar)
Hi Denver,
Unfortunately that isn’t working. Now I’m facing a new problem.
When I try and signup, I get a warning:
Warning: Missing argument 2 for update_base_user_profile() in \wp-content\themes\twentytwelve-child\functions-partials\redirects.php on line 95
Here is the code:
add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile' );
function update_base_user_profile($user_data, $identity) {
$temp_user = new WP_User($user_data->ID);
$temp_user->remove_role('subscriber');
echo '<pre>'; print_r($user_data); print_r($identity); echo '</pre>'; die();
xprofile_set_field_data('First Name', $user_data->ID, $identity->name->givenName);
xprofile_set_field_data('Last Name', $user_data->ID, $identity->name->familyName);
}
Line 95 is function update_base_user_profile($user_data, $identity) {
So I tried changing the add_action to add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile', 10, 2 );
And that got rid of the warning. But in the $user_data field I’m getting the User ID and in the Identity field I am getting 1.
Could you tell me which version of Social Login you are using?
Thread Starter
Kunal
(@kunalnagar)
For a minute, let’s work with what we have. I’m getting the User ID, so I can get the User Meta. I have the First Name and Last Name.
But I’m unable to save the First Name and Last Name field data for that user. So technically, it seems like a Buddypress problem? I have other xprofile fields at various stages of the signup and they are working absolutely fine. Only First Name and Last Name are not saving after Social Login.
Thread Starter
Kunal
(@kunalnagar)
Okay, so the problem is the action. I am unable to save any xprofile fields in the social login action.
add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile', 10, 2 );
Problem found!
When the hook is being called the BuddyPress table_name_fields haven’t been initialised and all Buddypress queries silently fail.
Adding do_action(‘bp_init’); solves the issue.
add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile', 10, 2 );
function update_base_user_profile($user_data, $identity)
{
do_action('bp_init');
xprofile_set_field_data('First Name', $user_data->ID, $identity->name->givenName);
xprofile_set_field_data('Last Name', $user_data->ID, $identity->name->familyName);
}
This code works in my test environnment.
Thank you for the update!
We have also added it it to the documentation:
http://docs.oneall.com/plugins/guide/social-login-wordpress/#3.2
Thread Starter
Kunal
(@kunalnagar)
No problem. Thank you for the help!
Glad you guys worked it out!
Hi Christian,
First, thanks for the plugin!
What are the actual first and last name field names?
I’m using Formidable forms and need the actual fields names so I can set the form fields to populate user input values to the fist name and last name wordpress/xprofile fields.
Thanks!
@nichelead could you start a new thread for this please? Also, a description of what you’re trying to achieve will help me understand what it is you’re after.
Cheers, Christian