(Pro-form)(Buddypress) Make Display Name Default to Username, Or Make it Custom Profile Field

Tim, Pat, et al,

I’ve looked through past topics as well as the KB, but I haven’t found a way yet to make the display name either a custom profile field similar to others on the registration form, or make it default to the username (and perhaps let them know that “your username is going to be what other members see”). Basically and put simply, I’d just like members not to have to show their real name by default within buddypress, but still provide it in the checkout for obvious reasons. I also do know that, once logged in, they can change it, but by then their real name would already be broadcast in the activity feed.

Thanks!

Ben,

Try adding this to an mu-plugin or in your active theme’s functions.php file:

<?php
function update_names( $user_id ) {
	$data = get_userdata( $user_id );
	$username = strtolower( $data->user_login );
	wp_update_user( 
		array (
			'ID' => $user_id, 
			'display_name' => $username,
		) 
	);
}
add_action( 'user_register', 'update_names' );

This will make the display name default to the username for new members. You will still have to change current members’ display names manually.

Thanks Tim, I really appreciate it. I’ve been all over the place developmentally and haven’t been able to implement it, but I’ll let you know how it goes when I do.