Skip to:
Content
Pages
Categories
Search
Top
Bottom

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


peterverkooijen
Participant

@peterverkooijen

Is the hook to use this?:

user_register

Runs when a user’s profile is first created. Action function argument: user ID.

So something like this?:

<?php
/*
Plugin Name: Real Name Synchro
Plugin URI: http://
Version: v0.001
Author: peterverkooijen
Description: A plugin to store firstname and lastname from the fullname field in Buddypress registration in WPMU usermeta tables, based on examples in the <a href="http://www.devlounge.net">Devlounge</a> series.
*/
if (!class_exists("RealNameSynchro")) {
class RealNameSynchro {
function RealNameSynchro() { //constructor

}
function xprofile_sync_wp_profile() {
global $bp, $wpdb;

if ( (int)get_site_option( 'bp-disable-profile-sync' ) )
return true;

$fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );
$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( 'xprofile_updated_profile', 'xprofile_sync_wp_profile' );

}

} //End Class RealNameSynchro

if (class_exists("RealNameSynchro")) {
$dl_pluginSeries = new RealNameSynchro();
}
//Actions and Filters
if (isset($dl_pluginSeries)) {
//Actions
add_action('user_register', array(&$dl_pluginSeries, 'xprofile_sync_wp_profile'), 1);
//Filters
}

?>

Testing it now…

Edit: Activating this plugin produces a white screen. Not a good start… :-(

Where did I go wrong?

Skip to toolbar