Leave a Reply

1 comment

  1. The register form have different hooks for custom fields.

    I hope this source example help you.

        /**
         * Add custom field to registration form
         */
        add_action( 'register_form', 'fb_show_first_name_field' );
        add_action( 'register_post', 'fb_check_fields', 10, 3 );
        add_action( 'user_register', 'fb_register_extra_fields' );
    
        function fb_show_first_name_field() {
        ?>
            <p>
                <label>Twitter<br/>
                    <input id="twitter" type="text" tabindex="30" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
                </label>
            </p>
        <?php
        }
    
        function fb_check_fields ( $login, $email, $errors ) {
            global $twitter;
    
            if ( '' === $_POST['twitter'] )
                $errors->add( 'empty_realname', "<strong>ERROR</strong>: Please Enter your twitter handle" );
            else
                $twitter = $_POST['twitter'];
    
        }
    
        function fb_register_extra_fields ( $user_id, $password = "", $meta = array() ) {
    
            update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
        }
    

    It is also usefull, I think, that you add the fields to the rpofile page for changes and view of the field content.

        /**
         * Add additional custom field
         */
        add_action( 'show_user_profile', 'fb_show_extra_profile_fields' );
        add_action( 'edit_user_profile', 'fb_show_extra_profile_fields' );
    
        function fb_show_extra_profile_fields( $user ) {
        ?>
            <h3>Extra profile information</h3>
            <table class="form-table">
                <tr>
                    <th><label for="twitter">Twitter</label></th>
                    <td>
                        <input type="text" name="twitter" id="twitter" value="<?php echo esc_attr( get_the_author_meta( 'twitter', $user->ID ) ); ?>" class="regular-text" /><br />
                        <span class="description">Please enter your Twitter username.</span>
                    </td>
                </tr>
            </table>
        <?php
        }
    
        add_action( 'personal_options_update',  'fb_save_extra_profile_fields' );
        add_action( 'edit_user_profile_update', 'fb_save_extra_profile_fields' );
        function fb_save_extra_profile_fields( $user_id ) {
    
            if ( ! current_user_can( 'edit_user', $user_id ) )
                return FALSE;
    
            /* Copy and paste this line for additional fields. Make sure to change 'twitter' to the field ID. */
            update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
        }