Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Make 2+ part name in full name required + xprofile_sync_wp_profile()


peterverkooijen
Participant

@peterverkooijen

Or can I just add this to bp_custom.php?

function xprofile_sync_wp_profile() {
global $bp, $wpdb;

if ( (int)get_site_option( 'bp-disable-profile-sync' ) )
return true;

$fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );
$space = strpos( $fullname, ' ' );

if ( false === $space ) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr( $fullname, 0, $space );
$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
}

update_usermeta( $bp->loggedin_user->id, 'nickname', $fullname );
update_usermeta( $bp->loggedin_user->id, 'first_name', $firstname );
update_usermeta( $bp->loggedin_user->id, 'last_name', $lastname );

$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $bp->loggedin_user->id ) );
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain( $bp->loggedin_user->id ), $bp->loggedin_user->id ) );
}
add_action( 'user_register', 'xprofile_sync_wp_profile' );

Note the user_register edit in add_action.

Testing it now…

Edit: Apparently the function xprofile_sync_wp_profile() is already included in bp-xprofile/bp-xprofile-filters.php…

Trying that with the same edit:

add_action( 'user_register', 'xprofile_sync_wp_profile' );

Edit: Still no separate first_name and last_name in wp_usermeta. :-(

This is driving me nuts. Can anyone please help? Getting a first and last name in the database should not be this hard for a social network!

Skip to toolbar