Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin update first_name, last_name in wp_usermeta on activation


peterverkooijen
Participant

@peterverkooijen

Thanks Paul!

$meta[‘field_1’] definitely looks like something to try, although I still totally don’t “get” serialized PHP arrays.

I was also wondering if I could just bp_user_fullname() at this point, before activation.

Trying both now…

EDIT:

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

$fullname = $meta['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( 'wpmu_activate_user', 'synchro_wp_usermeta' );

?>

Registration process works fine, but I with this error in the screen on activation:

Warning: Missing argument 2 for synchro_wp_usermeta() in /serverpath/wp-content/mu-plugins/bp-custom.php on line 187

I had taken $password out. Thought I didn’t need it. Will try again with it added back in….

EDIT2: Adding $password only gives me a second error:

Warning: Missing argument 2 for synchro_wp_usermeta() in /serverpath/wp-content/mu-plugins/bp-custom.php on line 187

Warning: Missing argument 3 for synchro_wp_usermeta() in /serverpath/wp-content/mu-plugins/bp-custom.php on line 187

Can I just take $user_id out? Is all the information I need already in that wpmu_activate_user action?

I’ll try that next, after deleting test users. Running out of email addresses…

Skip to toolbar