0

I have created custom fields on my registration form, such as 'telephone', using Theme My Login. I have found a way to make them appear in the backend (on the User page) but I can't update those fields.

What do I need to do in order to be able to update them?

Register-form.php:

<label for="telephone<?php $template->the_instance(); ?>"><?php _e( 'Telephone', 'theme-my-login' ) ?></label>
    <input type="text" name="telephone"  id="pays<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'telephone' ); ?>"/>

Functions.php:

<?php
function custom_user_profile_fields($user) {
?>
<table class="form-table">
<tr>
    <th>
        <label for="telephone"><?php _e('Téléphone'); ?></label>
    </th>
    <td>
        <input type="text" name="telephone" id="telephone" value="<?php echo esc_attr( get_the_author_meta( 'telephone', $user->ID ) ); ?>" class="regular-text" />     
    </td>
</tr>
</table>

<?php
}
add_action('show_user_profile', 'custom_user_profile_fields');
add_action('edit_user_profile', 'custom_user_profile_fields');
?>
  • Theme My Login has an option 'Enable Themed Profiles' if you check that box you should see any extra fields as part of the user profile – dg4220 Jul 13 '16 at 11:10
1

I use update_user_meta to update the fields. You can add this in functions.php of your child theme.

function save_extra_user_profile_fields( $user_id ) {

if ( !current_user_can( 'edit_user', $user_id ) ) { 
    return false; 
}

update_user_meta( $user_id, 'telephone', $_POST['telephone'] );   
}
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
0

You can use the following function to update custom field value for user

    update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );

For more information. Please visit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.