Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Plugin update first_name, last_name in wp_usermeta on activation


peterverkooijen
Participant

@peterverkooijen

This works!

$array = $wpdb->get_var("SELECT meta FROM $wpdb->signups");

$my_vars = unserialize($array);

$fullname = $my_vars[field_1];

echo $fullname;

I know it’s basically DJPaul’s solution, twenty posts back, but minus the apostrophes.

So now I know how to get the fullname, but still not how to get the fullname of the user that is activating = has the activation key?

Why doesn’t this work then?:

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

$array = $wpdb->get_var("SELECT meta FROM $wpdb->signups WHERE activation_key = %s", $key);

$my_vars = unserialize($array);

$fullname = $my_vars[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', 10, 1);

Skip to toolbar