Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


peterverkooijen
Participant

@peterverkooijen

Would this work? Does it make sense?

function synchro_wp_usermeta($user_id, $meta ) {
global $bp, $wpdb;

// Extract signup meta fields to fill out profile
$field_ids = $meta['xprofile_field_ids'];
$field_ids = explode( ',', $field_ids );

// Loop through each bit of profile data and save it to profile.
for ( $i = 0; $i < count($field_ids); $i++ ) {
if ( empty( $field_ids[$i] ) ) continue;

$field_value = $meta["field_{$field_ids[$i]}"];

$field = new BP_XProfile_ProfileData();
$field->user_id = $user_id;
$field->value = $field_value;
$field->field_id = $field_ids[$i];
$field->last_updated = time();
}

$fullname = $field->field_1;
$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', 'synchro_wp_usermeta' );

I’m looking for a way to define $fullname, to take the input from field_1 (* Name).

Please, anyone, help. I’ve been struggling with this for about four months now.

EDIT: Tried the code in bp_custom.php. It produced (?) a nasty database error, may have even crashed the server… :-(

Skip to toolbar