WordPress Snippets at WPcustoms

Auto select full name as display name

When a users registers and enters his first_name (john) and last_name (doe) this function will automatically set the nickname and display name to “john doe”.


/**
 * Snippet Name: Auto select full name as display name
 * Snippet URL: http://www.wpcustoms.net/snippets/auto-select-full-name-as-display-name/
 */
 function wpc_set_default_display_name( $user_id ) {
  $user = get_userdata( $user_id );
  $name = sprintf( '%s %s', $user->first_name, $user->last_name );
  $args = array(
    'ID' => $user_id,
    'display_name' => $name,
    'nickname' => $name
  );
  wp_update_user( $args );
}
add_action( 'user_register', 'wpc_set_default_display_name' );