Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


peterverkooijen
Participant

@peterverkooijen

Another attempt! What I really need is a variation of the xprofile_sync_wp_profile function that takes $fullname directly from the registration form and can be executed on user_register.

That shouldn’t be too hard, right?

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

$fullname = GET FROM THE REGISTRATION FORM INPUT
$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 have another plugin that also takes data from the registration form. That plugin has this in the code: $input_data. Is that standard wp? There’s nothing about it in the Codex.

That other plugin has this function, minus irrelevant bits:

function subscribe($input_data) {

// $post_data = array();
foreach ($input_data as $varname => $varvalue) {
$post_data[$varname] = $varvalue;
}

}
$post_data='action=subscribe&group_ids[]='.$this->lid.'&email_address='.$this->email_id.'&firstname='.$this->name_id;

So in my case that last line would become something like this?:

$post_data= 'first_name='.$this->first_name;

Of course somehow put together in one function. Like this?:

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

$post_data = array();
foreach ($input_data as $varname => $varvalue) {
$post_data[$varname] = $varvalue;
}

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

Can anyone please help? What should I put here for the “fullname” field?:

$fullname = $post_data[fullname];

Or is the entire approach wrong?

Skip to toolbar