Modifying the Profile Fields

Type: Filter
Name: td_profile_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_profile_fields( $profile_fields ) {
   
    $additions_modifications = array(
        'first_name'    =>  cvf_field_builder('text', 'Your First Name', true, $author->first_name ), // Modified the Label
        'last_name'     =>  cvf_field_builder('text', 'Last Name', false, $author->last_name ), // Make the field NOT required
        'about_me'      =>  cvf_field_builder('textarea', 'Enter something about you', true, $author->about_me, 'Write here' ) // Added Field
    );
   
    // Example of removing fields
    unset(
        $profile_fields['zip_code'],
        $profile_fields['city']
    );
   
    $profile_fields = array_merge( $profile_fields, $additions_modifications );
   
    return $profile_fields;
   
}
add_filter('td_profile_fields', 'my_profile_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 profile fields

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

Bellow is the default profile fields in their proper order:

1
2
3
4
5
6
7
8
9
10
11
$profile_fields = array(
    'username'          =>  cvf_field_builder('text', 'Username', true, $author->user_login ), 
    'user_email'        =>  cvf_field_builder('email', 'Email Address', true, $author->user_email ),   
    'contact_number'    =>  cvf_field_builder('text', 'Contact Number', true, $author->contact_number ),
    'first_name'        =>  cvf_field_builder('text', 'First Name', true, $author->first_name ),
    'last_name'         =>  cvf_field_builder('text', 'Last Name', true, $author->last_name ),
    'zip_code'          =>  cvf_field_builder('text', 'Zip Cide', true, $author->zip_code ),
    'city'              =>  cvf_field_builder('text', 'City', true, $author->city ),
    'country_2x_format' =>  cvf_field_builder('select', 'Country', true, $country_options ),
    'submit_form'       =>  cvf_field_builder('submit', '', false, 'Update Profile' )
);


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

Contact Me