xprofile_sync_wp_profile( int $user_id,  $field_id = null )

Sync xprofile data to the standard built in WordPress profile data.

Description

Parameters

$user_id

(Required) ID of the user to sync.

Return

(bool)

Source

File: bp-xprofile/bp-xprofile-functions.php

879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
function xprofile_sync_wp_profile( $user_id = 0, $field_id = null ) {
 
    // Bail if profile syncing is disabled.
    if ( bp_disable_profile_sync() ) {
        return true;
    }
 
    if ( empty( $user_id ) ) {
        $user_id = bp_loggedin_user_id();
    }
 
    if ( empty( $user_id ) ) {
        return false;
    }
 
    $firstname_id = bp_xprofile_firstname_field_id();
    $lastname_id  = bp_xprofile_lastname_field_id();
    $nickname_id  = bp_xprofile_nickname_field_id();
 
    if ( ! $field_id || $field_id == $firstname_id ) {
        $firstname = xprofile_get_field_data( bp_xprofile_firstname_field_id(), $user_id );
        bp_update_user_meta( $user_id, 'first_name', $firstname );
    }
 
    if ( ! $field_id || $field_id == $lastname_id ) {
        $lastname = xprofile_get_field_data( bp_xprofile_lastname_field_id(), $user_id );
        bp_update_user_meta( $user_id, 'last_name', $lastname );
    }
 
    if ( ! $field_id || $field_id == $nickname_id ) {
        $nickname = xprofile_get_field_data( bp_xprofile_nickname_field_id(), $user_id );
        bp_update_user_meta( $user_id, 'nickname', $nickname );
    }
 
    bp_xprofile_update_display_name( $user_id );
}

Changelog

Changelog
Version Description
BuddyPress 1.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.