resync_wordpress_xprofile_fields()

Resync WordPress profile data to BuddyBoss.

Description

Source

File: bp-core/admin/bp-core-admin-tools.php

715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
function resync_wordpress_xprofile_fields() {
    $users = get_users( [
        'fields' => [ 'ID', 'user_nicename' ]
    ] );
 
    foreach ( $users as $user ) {
        xprofile_set_field_data( bp_xprofile_firstname_field_id(), $user->ID, get_user_meta( $user->ID, 'first_name', true ) );
        xprofile_set_field_data( bp_xprofile_lastname_field_id(), $user->ID, get_user_meta( $user->ID, 'last_name', true ) );
 
        // make sure nickname is valid
        $nickname = get_user_meta( $user->ID, 'nickname', true );
        $nickname = sanitize_title( $nickname );
        $invalid  = bp_xprofile_validate_nickname_value( '', bp_xprofile_nickname_field_id(), $nickname, $user->ID );
 
        // or use the user_nicename
        if ( ! $nickname || $invalid ) {
            $nickname = $user->user_nicename;
        }
 
        bp_update_user_meta( $user->ID, 'nickname', $nickname );
        xprofile_set_field_data( bp_xprofile_nickname_field_id(), $user->ID, $nickname );
    }
 
    $statement = __( 'Re-sync user WordPress data to BuddyBoss profile fields; %s', 'buddyboss' );
 
    return array( 0, sprintf( $statement, __( 'Complete!', 'buddyboss' ) ) );
}

Changelog

Changelog
Version Description
BuddyBoss 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.