• Resolved Kunal

    (@kunalnagar)


    Hi Christian,

    Thank you for this plugin.

    I am having problems saving First Name and Last Name using xprofile_set_field_data

    I originally created these two fields myself and was having saving to them as well. I am using the OA Social Login plugin to Sign Up a user using Facebook and then using their hook I am trying to save these Extended Profile Fields. Here is my code:

    add_action( 'oa_social_login_action_after_user_insert', 'update_base_user_profile' );
    function update_base_user_profile( $user_id, $user_data ) {
    	$user_display_name = $user_data->data->display_name;
    	$temp_user = new WP_User($user_id);
        $temp_user->remove_role('subscriber');
    	$temp_dn = explode(' ', $user_display_name);
    	$first_name = $temp_dn[0];
    	$last_name = $temp_dn[1];
    	xprofile_set_field_data( 'First Name', $user_id, $first_name );
        xprofile_set_field_data( 'Last Name', $user_id, $last_name );
    }

    Any insight?

    https://www.ads-software.com/plugins/bp-xprofile-wp-user-sync/

Viewing 13 replies - 1 through 13 (of 13 total)
  • 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)

    I’m using Version 4.6

    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.

    Thread Starter Kunal

    (@kunalnagar)

    It worked. Thanks! ??

    Marking as resolved.

    Thank you for the update!

    We have also added it it to the documentation:
    https://docs.oneall.com/plugins/guide/social-login-wordpress/#3.2

    Thread Starter Kunal

    (@kunalnagar)

    No problem. Thank you for the help!

    Plugin Author Christian Wach

    (@needle)

    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!

    Plugin Author Christian Wach

    (@needle)

    @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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Cannot save via xprofile_set_field_data’ is closed to new replies.