Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin update first_name, last_name in wp_usermeta on activation


peterverkooijen
Participant

@peterverkooijen

The last attempt in the previous post does not work. No error messages, registration goes through as normal, but nothing in wp_usermeta.

This also has no effect:

function synchro_wp_usermeta() {
global $bp_user_signup_meta, $bp, $wpdb;

$fields = BP_XProfile_Field::get_signup_fields();

if ( $fields ) {
foreach ( $fields as $field ) {

$fullname = $_POST['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' );

Please, I need feedback to finish this function/plugin. A real coder can spot the problem probably immediately. Please point it out, don’t leave me hanging.

Skip to toolbar