PROSITE ONLY!!!! Adding extra fields to the sign-up page.

First, I searched and searched, read and read, and the only CLEAR answer is to use Gravity Forms to add fields. But I don't want to pay the $200 just to get the "User Registration" plug-in. Second, when I search for an answer to add extra fields, 80% of the results are for Membership 2 plugin, not Prosites; frustrating.

In your support pages, you give a cursory suggestion that BuddyPress and Xprofile can be used but with no specific instructions on how to do it. There are two support questions that seem to reference each other creating a loop with no real answer (hint for future searchers for extra fields in ProSites).

Anyway, I added BuddyPress and xProfile to my PROSITE site, but the fields I added are not showing. Is there a setting I need to check or custom code to use to get the extra fields to show in PROSITES? Again, I am aware that Gravity Forms work, but I don't want to pay the $200 fee when you say that BP and xProile will work. So how exactly does it work?

Please be specific.

  • Umesh Kumar

    Hey bayfish,

    You can use the action signup_hidden_fields to add fields to different screens on Pro SIte signup page.

    That's the same action, that you'd used to add fields to User/Site registration screen in default WordPress.

    Here is a e.g: to add an extra field on the User Screen, on top of the form:

    add_action('signup_hidden_fields', 'wpmu_192221_add_fields');
    function wpmu_192221_add_fields( $method ) {
    	if( empty( $method ) ) {
    		return;
    	}
    	switch ( $method ) {
    		case 'validate-user':
    			//Add fields related to user detail screen
    			echo '<div class="wpmu-fieldname">
    				<label for="field_1">Field1:</label>
    				<input name="field_1" type="text" id="field_1" value="" maxlength="60">(Some text if required.)
    			</div>';
    			break;
    		case 'create-another-site':
    			//If you want to print some fields on Additional Blog Create Screen
    			break;
    		case 'validate-site':
    			//Add fields displayed on site detail screen
    			break;
    	}
    
    }

    Similarly you can use the action signup_extra_fields for User Section and signup_blogform for Site detail section to output fields after the form.

    Cheers

  • bayfish

    Thank you for your help.

    I tried the code and the fields show on the sign-up page, but it seems to me that's all it is, just fields. I don't see how they tie into xprofile to populate the xprofile fields.

    When I tested it, the xprofile fields were not populated.

    Granted, I think I'm using the correct xprofile field names, in the event I am not, how does one go about getting the xprofile field names to insert them into the method to populate?

    • Umesh Kumar

      bayfish,

      For the data to appear in xProfile fields, you need to map it by hooking into the action wpmu_new_user and register_new_user.

      Here is the example code:

      Where field id is available from the fields you've added in the Extended Profile section of BuddyPress.

      For e.g. I added a Address field in Extended profile, and the id for the same is 2.

      So, while adding the same field to Pro Site signup page, keep the input name same, for the ease of operation.

      add_action('signup_hidden_fields', 'wpmu_192221_add_fields');
      function wpmu_192221_add_fields( $method ) {
      	if( empty( $method ) ) {
      		return;
      	}
      	switch ( $method ) {
      		case 'validate-user':
      			//Add fields related to user detail screen
      			echo '<div class="wpmu-fieldname">
      				<label for="field_2">Address:</label>
      				<input name="field_2" type="text" id="field_2" value="" maxlength="60">(Some text if required.)
      			</div>';
      			break;
      		case 'create-another-site':
      			//If you want to print some fields on Additional Blog Create Screen
      			break;
      		case 'validate-site':
      			//Add fields displayed on site detail screen
      			break;
      	}
      
      }
      add_action('wpmu_new_user', 'map_to_xprofile');
      add_action('register_new_user', 'map_to_xprofile');
      function map_to_xprofile( $user_id ) {
      	if( !isset( $user_id ) ) {
      		return;
      	}
      	if( function_exists('xprofile_set_field_data') ) {
      		// The ID of the field, or the $name of the field.
      		$field = 2;
      
      		// The value for the field you want to set for the user.
      		$value = !empty( $_POST['field_2'] ) ? sanitize_text_field( $_POST['field_2'] ) : ''; 
      
      		// Whether or not the field is required.
      		$is_required = false; 
      
      		// NOTICE! Understand what this does before running.
      		$result = xprofile_set_field_data($field, $user_id, $value, $is_required);
      
      	}
      }

      I've tested the code, the Address appears properly for the User in extended profile section.

      Do write back, in case you've any other doubts, and apologies for the delay :slight_smile:

      Cheers

  • bayfish

    This is what I did and got an error when declaring the variable because of the two equal signs. How do I call the field as a variable if the field has an equal sign?

    add_action('signup_hidden_fields', 'wpmu_192221_add_fields');
    function wpmu_192221_add_fields( $method ) {
    	if( empty( $method ) ) {
    		return;
    	}
    	switch ( $method ) {
    		case 'validate-user':
    			//Add fields related to user detail screen
    			echo '<div class="wpmu-fieldname">
    				<label for="first_name">First Name:</label>
    				<input name="first_name" type="text" id="field_id=2" value="" maxlength="60">
    				<label for="last_name">Last Name:</label>
    				<input name="last_name" type="text" id="field_id=3" value="" maxlength="60">
    				<label for="office_phone">Office Phone: (required)</label>
    				<input name="office_phone" type="text" id="field_id=4" value="" maxlength="60">
    				<label for="theme_number_and_name">Theme number and name:</label>
    				<input name="theme_number_and_name" type="text" id="field_id=10" value="" maxlength="60">
    				<label for="current_web_address">Current Web address or domain name:</label>
    				<input name="current_web_address" type="text" id="field_id=11" value="" maxlength="60">			</div>';
    			break;
    		case 'create-another-site':
    			//If you want to print some fields on Additional Blog Create Screen
    			break;
    		case 'validate-site':
    			//Add fields displayed on site detail screen
    			break;
    	}
    
    }
    
    add_action('wpmu_new_user', 'map_to_xprofile');
    add_action('register_new_user', 'map_to_xprofile');
    function map_to_xprofile( $user_id ) {
    	if( !isset( $user_id ) ) {
    		return;
    	}
    	if( function_exists('xprofile_set_field_data') ) {
    		// The ID of the field, or the $name of the field.
    		$field = field_id=10;      //ERROR on this line//
    
    		// The value for the field you want to set for the user.
    		$value = !empty( $_POST['field_id=10'] ) ? sanitize_text_field( $_POST['field_id=10'] ) : ''; 
    
    		// Whether or not the field is required.
    		$is_required = false; 
    
    		// NOTICE! Understand what this does before running.
    		$result = xprofile_set_field_data($field, $user_id, $value, $is_required);
    
    	}
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.