To add custom fields WordPress user registration page we need to utilize the hook user_new_form because since WordPress 3.7 the hook register_form no longer works. Here is an example of adding a checkbox to the end of the user registration form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<?php //Add a new form element... add_action( 'user_new_form', 'es_plugin_register_form' ); function es_plugin_register_form() { ?> <table class="form-table"> <tbody> <tr> <th scope="row"><label for="parent_account"><?php _e( 'Parent Account', 'eversion' ) ?></label></th> <td><label for="parent_account"><input name="parent_account" id="parent_account" value="1" type="checkbox">Create a parent account?</label></td> </tr> </tbody> </table> <?php } //Save our extra registration user meta. add_action( 'user_register', 'es_myplugin_user_register' ); function es_myplugin_user_register( $user_id ) { if ( isset( $_POST['parent_account'] ) ) { update_user_meta( $user_id, 'parent_account', 1 ); } } ?> |
Here is the result of us adding custom fields to WordPress user […]