Adding Fields to Registration
-
Hello I am trying to further extend the registration form. I have added both “first_name” and “last_name” as displayed by wordpress but for some reason it seems as though the update_user_meta is not saving whatsoever.
I have created the file wp-content/plugins/theme-my-login-custom.php
I have created wp-content/themes/child/register-form.phpThis is the code I am using on the register page:
<div class="tml-user-first-last-name-wrap" style="margin-bottom: 25px;"> <span style="width:50%; padding-left: 25px; padding-right: 1px; float:left;"><input type="text" placeholder="First Name" name="first_name" id="first_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'first_name' ); ?>" size="20" /> <label for="first_name<?php $template->the_instance(); ?>"><?php _e( '', 'theme-my-login' ) ?></label> </span> <span style="width:50%; padding-left: 1px; padding-right: 25px; float:right;"><input type="text" placeholder="Last Name" name="last_name" id="last_name<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'last_name' ); ?>" size="20" /> <label for="last_name<?php $template->the_instance(); ?>"><?php _e( '', 'theme-my-login' ) ?></label> </span> <br> </div>This is the code I have in the custom file:
function tml_registration_errors( $errors ) { if ( empty( $_POST['first_name'] ) ) $errors->add( 'empty_first_name', '<strong>ERROR</strong>: Please enter your first name.' ); if ( empty( $_POST['last_name'] ) ) $errors->add( 'empty_last_name', '<strong>ERROR</strong>: Please enter your last name.' ); return $errors; } add_filter( 'registration_errors', 'tml_registration_errors' ); function tml_user_register( $user_id ) { if ( !empty( $_POST['first_name'] ) ) update_user_meta( $user_id, 'first_name', $_POST['first_name'] ); if ( !empty( $_POST['last_name'] ) ) update_user_meta( $user_id, 'last_name', $_POST['last_name'] ); } add_action( 'user_register', 'tml_user_register' );Any ideas?
The page I need help with: [log in to see the link]
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
The topic ‘Adding Fields to Registration’ is closed to new replies.