Plugin update first_name, last_name in wp_usermeta on activation
- 
		Continuing from this thread: Fresh start with a slightly shifted focus and more descriptive topic title. I’m trying to come up with a plugin that guarantees that first_name + last_name are stored in wp_usermeta for every user. At the moment BP only stores these values when users update their profile, so you can never count on them being there for other scripts, like a mailing list or event registration. The existing profile update synchronize function is an obvious starting point: xprofile_sync_wp_profile() This function takes the logged-in user’s fullname database field, splits it into first and last name, and stores the result in wp_usermeta. Instead of taking $fullname from the database I’ve tried to figure out how to take it from the registration form directly and store it on registration. That was a dead end.  Looking for examples in other plugins I see that Paul Gibbs’ Welcome Pack uses the wpmu_activate_user action. That should work for my purposes as well; every user that’s activated gets first and last name in wp_usermeta. Where do I get the $fullname from? The first function in the Welcome Pack plugin has these “$thingies” between the () – what do you call those?: function dp_welcomepack_welcomemessage( $user_id, $password, $meta )I know the input for fullname (field_1) is somehow included in that $meta stuff. How? I have no clue… Here’s what I have so far: function synchro_wp_usermeta($user_id, $meta) {
 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( 'wpmu_activate_user', 'synchro_wp_usermeta' );Getting another coffee now, digging further through the Welcome Pack plugin next. Any pointers very much appreciated! 
- The topic ‘Plugin update first_name, last_name in wp_usermeta on activation’ is closed to new replies.