how can i add new fields to registration page for new user registration in wordpress multisite?

I want to add a custom field in the user registration page. How can I manage to add a field to the current form? I tried the code below but it’s not working, nor do register_from, register_post and user_register hooks.

add_action('register_form','show_first_name_field');
add_action('register_post','check_fields',10,3);
add_action('user_register', 'register_extra_fields');

function 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 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 register_extra_fields ( $user_id, $password = "", $meta = array() )
{
    update_user_meta( $user_id, 'twitter', $_POST['twitter'] );
}

Related posts

2 comments

  1. I solved it.i used below code to add custom fields in registration page

    /**
    
     * Add additional custom field to profile page
    
     */
    
    
    
    add_action ( 'show_user_profile', 'my_show_extra_profile_fields' );
    
    add_action ( 'edit_user_profile', 'my_show_extra_profile_fields' );
    
    
    
    function my_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
    
    }
    
    
    
    /**
    
     * Save data input from custom field on profile page
    
     */
    
    
    
    add_action ( 'personal_options_update', 'my_save_extra_profile_fields' );
    
    add_action ( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
    
    
    
    function my_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_usermeta( $user_id, 'twitter', $_POST['twitter'] );
    
    }
    
    
    
    
    
    /**
    
     * Add cutom field to WPMU registration form
    
     */
    
    add_action('signup_extra_fields','custom_signup_extra_fields', $errors);
    
    
    
    function custom_signup_extra_fields($errors) {
    
    ?>
    
        <label>Twitter</label>
    
        <input id="twitter" type="text" size="25" value="<?php echo $_POST['twitter']; ?>" name="twitter" />
    
        <br />
    
    
    
    <?php
    
    }
    
    
    
    /**
    
     * Save custom field input to wp_signups table
    
     */
    
    add_filter( 'add_signup_meta', 'custom_add_signup_meta' );
    
    
    
    function custom_add_signup_meta ( $meta = array() ) {
    
    
    
        $meta['twitter'] = $_POST['twitter'];
    
    
    
        return $meta;
    
    
    
    }
    

Comments are closed.