Register extra/additional fields for Theme My Login including admin
-
Hi all.
I spent some time figuring this out and though someone my use it.
This code will allow you to add extra fields to Theme My Login and display them in the user front end as well as admin back end.
We are going to create two additional fields:
- Job Title
- Tel number
1 Create a file called theme-my-login-custom.php in wp-content/plugins folder and paste the following code :
<?php function tml_registration_errors( $errors ) { //This will add form validation to your extra fields. if ( empty( $_POST['job_title'] ) ) $errors->add( 'empty_job_title', '<strong>ERROR</strong>: Job title is required' ); if ( empty( $_POST['tel_number'] ) ) $errors->add( 'empty_tel_number', '<strong>ERROR</strong>: Tel number Required' ); return $errors; } add_filter( 'registration_errors', 'tml_registration_errors' ); function tml_user_register( $user_id ) { //register the extra fields if ( !empty( $_POST['job_title'] ) ) update_user_meta( $user_id, 'job_title', $_POST['job_title'] ); } if ( !empty( $_POST['tel_number'] ) ) update_user_meta( $user_id, 'tel_number', $_POST['job_title'] ); } add_action( 'user_register', 'tml_user_register' );2. On TML theme and profile page add the following code (profile-form.php register-form.php) Make sure you copied theme files from wp-content/plugin/theme-my-login/temapltes to wp-content/themes/your-theme
<tr> <th> <label for="job_title"><?php _e( 'Job Title' ); ?></label> </th> <td> <input type="text" name="job_title" id="job_title" value="<?php echo esc_attr( $profileuser->job_title ); ?>" class="regular-text" /> </td> </tr> <tr> <th> <label for="tel_number"><?php _e( 'Tel Number' ); ?></label> </th> <td> <input type="text" name="tel_number" id="tel_number" value="<?php echo esc_attr( $profileuser->tel_number); ?>" class="regular-text" /> </td> </tr>3 Last thing – register your new filed in admin. Past this code to your wp-content/themes/your-theme/function.php
<h3>Extra profile information</h3> <table class="form-table"> <tr> <th> <label for="job_title">job Title</label> </th> <td> <input type="text" name="job_title" id="job_title" value="<?php echo esc_attr( get_the_author_meta( 'job_title', $user->ID ) ); ?>" class="regular-text" /><br /> </td> </tr> <tr> <th> <label for="tel_number">Tel Number</label> </th> <td> <input type="text" name="tel_number" id="tel_number" value="<?php echo esc_attr( get_the_author_meta( 'tel_number', $user->ID ) ); ?>" class="regular-text" /><br /> <span class="description">This is user tel number.</span> </td> </tr> </table>Hope this will help someone
The topic ‘Register extra/additional fields for Theme My Login including admin’ is closed to new replies.