| | |

Add registration custom field Tutor LMS

If you want to add any custom field in your registration page, then you need to follow the following four steps:

First, need to add a function in your function.php file

add_filter('tutor_student_registration_required_fields', 'required_nid_no_callback');
if ( ! function_exists('required_nid_no_callback')){
    function required_nid_no_callback($atts){
        $atts['nid'] = 'National Id';
        return $atts;
    }
}
add_action('user_register', 'add_nid_after_user_register');
add_action('profile_update', 'add_nid_after_user_register');
if ( ! function_exists('add_nid_after_user_register')) {
    function add_nid_after_user_register($user_id){
        if ( ! empty($_POST['nid'])) {
            $nid = sanitize_text_field($_POST['nid']);
            update_user_meta($user_id, '_nid', $nid);
        }
    }
}

Then, Need to override the registration page and need to add following code, here the file path location : plugins/tutor/templates/dashboard/registration.php

Then, add a field in that registration page

<div class="tutor-form-col-6">
    <div class="tutor-form-group">
        <label>
            <?php _e('NId', 'tutor'); ?>
        </label>

        <input type="text" name="nid" value="<?php echo tutor_utils()->input_old('nid'); ?>" placeholder="<?php _e('NID', 'tutor'); ?>">
    </div>
</div>

The third step, Need to override the my-profile.php page and need to add the following code, here is the file path location :

/plugins/tutor/templates/dashboard/my-profile.php

Here, need to add a variable first for this at the top of the page
$nid = get_user_meta($uid,'_nid',true);

Then, Need to add this example code
        <div class="tutor-dashboard-profile-item">
            <div class="heading">
                <span><?php _e('NId', 'tutor'); ?></span>
            </div>
            <div class="content">
                
                <p><?php  echo $nid ? $nid : "________"; ?>&nbsp;</p>
            </div>
        </div>

Last, Need to override the profile.php page and need to add the following code, here is the file path location :

Need to add this example code

/plugins/tutor/templates/dashboard/settings/profile.php

            <div class="tutor-form-col-6">
                <div class="tutor-form-group">
                    <label>
                        <?php _e('Nid', 'tutor'); ?>
                    </label>
                    <input type="number" min="1" name="nid" value="<?php echo get_user_meta($user->ID,'_nid',true); ?>" placeholder="<?php _e('NId', 'tutor'); ?>">
                </div>
            </div>

Also, Add the following code to wp-content/plugins/tutor/views/metabox/user-profile-fields.php

<tr class="user-description-wrap">
<th><label for="description"><?php _e('Nid Number'); ?></label></th>
<td>
<input type="text" name="phone" id="nid" value="<?php echo get_user_meta($user->ID, '_nid', true); ?>" class="regular-text" />
</td>
</tr>

For more details can watch the video :

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *