=== modified file 'modules/field_ui/field_ui.admin.inc'
--- modules/field_ui/field_ui.admin.inc	2009-08-29 08:00:03 +0000
+++ modules/field_ui/field_ui.admin.inc	2009-08-31 18:17:49 +0000
@@ -1007,6 +1007,7 @@
 
   $field = field_info_field($instance['field_name']);
   $form['#field'] = $field;
+  $form['#instance'] = $instance;
 
   if (!empty($field['locked'])) {
     $form['locked'] = array(

=== modified file 'modules/user/user.module'
--- modules/user/user.module	2009-08-31 18:00:03 +0000
+++ modules/user/user.module	2009-08-31 19:14:28 +0000
@@ -3065,6 +3065,17 @@
   if (count(element_children($form)) == 1) {
     $form['account']['#type'] = 'markup';
   }
+  
+  // Add user fields to the registration form.
+  field_attach_form('user', $null, $form, $form_state);
+  if (isset($form['#fields']) && is_array($form['#fields'])) {
+    // Don't display fields that aren't set to show on the registration pages.
+    foreach ($form['#fields'] as $field) {
+      if (!isset($field['instance']['settings']['user_register']) || !$field['instance']['settings']['user_register']) {
+        $form[$field['field']['field_name']]['#access'] = FALSE;
+      }
+    }
+  }
 
   $form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
   $form['#validate'][] = 'user_register_validate';
@@ -3130,3 +3141,18 @@
       ->execute();
   }
 }
+
+/**
+ * Add a checkbox to the field settings form to add the user
+ */
+function user_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
+  $instance= $form['#instance'];
+  
+  if ($instance['bundle'] == 'user') {
+    $form['instance']['settings']['user_register'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display this field on the registration form.'),
+      '#default_value' => isset($instance['settings']['user_register']) ? $instance['settings']['user_register'] : FALSE,
+    );
+  }
+}

=== modified file 'modules/user/user.test'
--- modules/user/user.test	2009-08-25 03:00:03 +0000
+++ modules/user/user.test	2009-08-31 19:14:45 +0000
@@ -105,6 +105,53 @@
     $this->assertText(t('View'), t('[user auth] Found view tab on the profile page.'));
     $this->assertText(t('Edit'), t('[user auth] Found edit tab on the profile page.'));
   }
+}  
+ 
+class UserRegistrationFieldsTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'User registration fields',
+      'description' => 'Add user fields to the registration page.',
+      'group' => 'User'
+    );
+  }
+  
+  function setUp() {
+    parent::setUp('field_test');
+  }
+  
+  function testUserRegistrationFields() {
+    $field1 = array(
+      'field_name' => drupal_strtolower($this->randomName()),
+      'type' => 'test_field',
+    );
+    $field2 = array(
+      'field_name' => drupal_strtolower($this->randomName()),
+      'type' => 'test_field',
+    ); 
+    field_create_field($field1);
+    field_create_field($field2);
+    
+    $instance1 = array(
+      'field_name' => $field2['field_name'],
+      'bundle' => 'user',
+      'label' => $this->randomName(),
+    );
+    $instance2 = array(
+      'field_name' => $field1['field_name'],
+      'bundle' => 'user',
+      'label' => $this->randomName(),
+      'settings' => array(
+        'user_register' => TRUE,
+      ),
+    );
+    field_create_instance($instance1);
+    field_create_instance($instance2);
+    
+    $this->drupalGet('user/register');
+    $this->assertNoText($instance1['label'], t('Fields are not added to the registration form by default.'));
+    $this->assertText($instance2['label'], t('Fields can be added to the registration form.'));
+  }
 }
 
 

