You can customize WordPress built-in user registration page through the use of hooks.
Lets customizing the registration form involves the following hooks:
1. register_form Allow rendering of new HTML element.
|
1 2 3 4 5 6 7 8 9 10 |
// Add privacy policy field. add_action( 'register_form', 'loginpress_add_privacy_policy_field' ); function loginpress_add_privacy_policy_field() { ?> <p> <label for="lp_privacy_policy"><?php _e( 'Privacy Policy', 'loginpress' ) ?><br /> <input type="checkbox" name="lp_privacy_policy" id="lp_privacy_policy" class="checkbox" /> </label> </p> <?php } |
2. registration_errors Perform validation on form registration fields.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
// Add validation. In this case, we make sure lp_privacy_policy is required. add_filter( 'registration_errors', 'loginpresss_privacy_policy_auth', 10, 3 ); function loginpresss_privacy_policy_auth( $errors, $sanitized_user_login, $user_email ) { if ( ! isset( $_POST['lp_privacy_policy'] ) ) : $errors->add( 'policy_error', "<strong>ERROR</strong>: Please accept the privacy policy." ); return $errors; endif; return $errors; } |
3. user_register Save custom form data.
|
1 2 3 4 5 6 7 8 |
// Lastly, save our extra registration user meta. add_action( 'user_register', 'loginpress_privacy_policy_save' ); public function loginpress_privacy_policy_save( $user_id ) { if ( isset( $_POST['lp_privacy_policy'] ) ) update_user_meta( $user_id, 'lp_privacy_policy', $_POST['lp_privacy_policy'] ); } |