Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferromariano/f96eb3fda77aa2334f72 to your computer and use it in GitHub Desktop.
Save ferromariano/f96eb3fda77aa2334f72 to your computer and use it in GitHub Desktop.
/*
1. create custom user fields with wordpress (see https://gist.github.com/makbeta/5851535 )
2. clone `register-form.php` from /wp-content/plugins/theme-my-login/templates to your theme
3. Add your new field to the registration template
*/
<p>
<label for="subscription">Customer ID</label>
<input type="text" name="subscription" id="subscription<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'subscription' ); ?>" size="20" /><br />
<span class="description">Please enter your customer ID.</span>
</p>
/* Add handling of the field during registration by adding the following to your functions.php */
<?php
// This function can be used for validation such as required fields
function my_registration_errors( $errors, $user_login ) {
// Require "my-field"
if ( empty( $_POST['subscription'] ) )
$errors->add( 'empty_subscription', __( '"Customer ID" is a required field!' ) );
return $errors;
}
// This function will save the custom field to the user meta table
function my_new_user_registered( $user_id ) {
if ( isset( $_POST['subscription'] ) )
update_user_meta( $user_id, 'subscription', $_POST['subscription'] );
}
add_action( 'registration_errors', 'my_registration_errors', 10, 2 );
add_action( 'tml_new_user_registered', 'my_new_user_registered' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment