kalammitta
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Plugins
In reply to: [Theme My Login] Problem updating custom field in TML ProfileHere is my solution to the problem of adding fields to Theme-My-Login registration form
1) add the code to the file functions.php rename the existing WordPress fields to the ones we need
add_filter('user_contactmethods', '_my_get_user_contactmethods'); function _my_get_user_contactmethods() { $user_contactmethods = array( 'appartment' => __('Numéro de votre appartement'), 'basement_number' => __('Numéro de cave, le cas échéant') ); return $user_contactmethods; }
2) in the file register-form.php add the output of fields
<label for="appartment<?php $template->the_instance(); ?>"><?php _e( 'Numéro de appartemen', 'theme-my-login' ) ?></label> <input type="text" name="appartment" id="appartment" class="input" value="<?php echo $_POST['appartment']; ?>" size="15" tabindex="20" /> <label for="basement_number<?php $template->the_instance(); ?>"><?php _e( 'Numéro de chambre au sous-sol', 'theme-my-login' ) ?></label> <input type="text" name="basement_number" id="basement_number" class="input" value="<?php echo $_POST['basement_number']; ?>" size="15" tabindex="20" />
3)in the file functions.php will check for errors the entered data by the user and update the user data :
add_action('register_post','check_fields',10,3); add_action('user_register', 'register_fields'); function check_fields ( $login, $email, $errors ) { global $appartment, $basement_number; if ($_POST['appartment'] == ''){ $errors->add( 'empty_realname', "<strong>ERREUR</strong>: Indiquez le numéro de votre appartment!" ); } else { $appartment = $_POST['appartment']; } if ($_POST['basement_number'] == ''){ $errors->add( 'empty_realname', "<strong>ERREUR</strong>: Indiquez votre numéro de cave, le cas échéant" ); } else { $basement_number = $_POST['basement_number'];} } function register_fields($user_id,$password= "",$meta=array()){ update_user_meta( $user_id, 'appartment', $_POST['appartment'] ); update_user_meta( $user_id, 'basement_number', $_POST['basement_number'] ); }
- This reply was modified 7 years, 10 months ago by kalammitta.
Viewing 1 replies (of 1 total)