Profile Details

Home Forums User Registration Profile Details

This topic contains 2 replies, has 2 voices, and was last updated by  Paulo Ferreira 1 year ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #5581

    Paulo Ferreira
    Participant

    Hello,
    I’m trying add 2 fields to the profile details because I don’t want to use it in the register form.

    I added this code on the form-edit-profile.php page. This show but not save.

    						$current_user = wp_get_current_user();
    
    						$teste = array('user_registration_first_name' => 
    										array(
    			    							"label"        => 'First Name',
    			    							"description"  =>  '',
    			    							"type"         => 'text',
    			    							"field_key"    => 'first_name',
    			    							"required"     =>'',
    			    							"default"      => '',
    			    							"value"        => $current_user->user_firstname,
    										),
    								 'user_registration_last_name' => 
    										array(
    			    							"label"        => 'Last Name',
    			    							"description"  =>  '',
    			    							"type"         => 'text',
    			    							"field_key"    => 'last_name',
    			    							"required"     =>'',
    			    							"default"      => '',
    			    							"value"        => $current_user->user_lastname,
    										)
    								
    
    						);
    						
    						$profile = array_merge($teste,$profile);

    Can u help me?

    #5583

    sanjeev3
    Member

    Hello Paulo,

    You need to filter the fields too. You may use this filter. Looks like field_key is redundant here. Assuming user_email is a required field for the form.

    add_filter( 'user_registration_profile_account_filter_user_email', 'filter_data' );
    
    function filter_data( $filter_data ) {
    	$filter_data['fields']['user_registration_first_name'] = array
                    (
     			    "label"        => 'First Name',
    			    "description"  =>  '',
    			    "type"         => 'text',
    			    "field_key"    => 'last_name',
    			    "required"     =>'',
    			    "default"      => '',
        );
    
        $filter_data['fields']['user_registration_last_name'] = array
                    (
     			    "label"        => 'Last Name',
    			    "description"  =>  '',
    			    "type"         => 'text',
    			    "field_key"    => 'last_name',
    			    "required"     =>'',
    			    "default"      => '',
        );
    
        return $filter_data;
    }

    Also, instead of directly editing the template, you can also use this filter. However, it is okay, if you have overridden the template in the child theme.

    add_filter( 'user_registration_profile_to_edit', 'ur_profile' );
    function ur_profile( $profile ) {
    
    	$current_user = wp_get_current_user();
    
    	$teste = array('user_registration_first_name' =>
    					array(
    						"label"        => 'First Name',
    						"description"  =>  '',
    						"type"         => 'text',
    						"field_key"    => 'first_name',
    						"required"     =>'',
    						"default"      => '',
    						"value"        => $current_user->first_name,
    					),
    			 'user_registration_last_name' =>
    					array(
    						"label"        => 'Last Name',
    						"description"  =>  '',
    						"type"         => 'text',
    						"field_key"    => 'last_name',
    						"required"     =>'',
    						"default"      => '',
    						"value"        => $current_user->last_name,
    					)
    
    	);
    
    	$profile = array_merge( $teste, $profile );
    	return $profile;
    }

    Let us know if you have any further confusion.

    Regards,
    WPEverest Support

    #5589

    Paulo Ferreira
    Participant

    Perfect thank you so much

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.