Modifying the Registration Fields

Type: Filter
Name: td_registration_fields
Location: wp-trade/inc/TD_Posts.class.php

Example of adding, updating and removing fields

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function my_registration_fields( $registration_fields ) {
   
    $additions = array(
        'user_email'        =>  cvf_field_builder('email', 'Enter Email Address', true ), // Modified the Label
        'contact_number'    =>  cvf_field_builder('text', 'Contact Number', false ), // Make the field NOT required
        'about_me'          =>  cvf_field_builder('textarea', 'Enter something about you', true, '', 'Write here' ) // Added Field
    );
   
    // Example of removing fields
    unset(
        $registration_fields['zip_code'],
        $registration_fields['city']
    );
   
    $registration_fields = array_merge( $registration_fields, $additions );
   
    return $registration_fields;
   
}
add_filter('td_registration_fields', 'my_registration_fields');

Usage of cvf_field_builder() function

1
2
3
4
5
6
7
cvf_field_builder(
    $type,          // Accepted types are: text, email, password, textarea, select (required)
    $label,         // will be outputted as "<label> Your Field Label </label>" (required)
    $required,      // true, false (required)
    $value,         // Define the value for your select, input, and  textarea fields
    $placeholder    // Add placeholder to <input[type="text"]>, <input[type="email"]> or <textarea>
);

Example of Reordering the registration fields

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function reorder_registration_fields( $registration_fields ) {
   
    // NOTE: Define all the fields (including hooked fields) before making any re-ordering
    $reordered = array(
        'user_email',
        'username',        
        'password',
        'password2',
        'first_name',
        'last_name',
        'contact_number',
        'country_2x_format',
        'about_me',
        'security_code',       
        'submit_form'
    );
   
    $registration_fields = array_merge( array_flip( $reordered ), $registration_fields );
   
    return $registration_fields;
   
}
add_filter('td_registration_fields', 'reorder_registration_fields');

Bellow is the default registration fields in their proper order:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$registration_fields = array(
    'username'          =>  cvf_field_builder('text', 'Username', true ),  
    'user_email'        =>  cvf_field_builder('email', 'Email Address', true ),
    'password'          =>  cvf_field_builder('password', 'Password', true ),
    'password2'         =>  cvf_field_builder('password', 'Re-enter password', true ),
    'contact_number'    =>  cvf_field_builder('text', 'Contact Number', true ),
    'first_name'        =>  cvf_field_builder('text', 'First Name', true ),
    'last_name'         =>  cvf_field_builder('text', 'Last Name', true ),
    'zip_code'          =>  cvf_field_builder('text', 'Zip Cide', true ),
    'city'              =>  cvf_field_builder('text', 'City', true ),
    'country_2x_format' =>  cvf_field_builder('select', 'Country', true, $country_options ),
    'security_code'     =>  cvf_field_builder('text', 'Captcha', true, '', 'Enter code above' ),
    'submit_form'       =>  cvf_field_builder('submit', '', false, 'Finish Registration' )
);


Do you need help with a project? or have a new project in mind that you need help with?

Contact Me