• I followed the instructions for adding custom fields to the registration form here.
    Which worked great. However, now I have duplicate profile fields. The section I added to the functions.php file is:
    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>Additional information</h3>

    <table class="form-table">

    <tr>
    <th><label for="phone_no">Phone Number</label></th>

    <td>
    <input type="text" name="phone_no" id="phone_no" value="<?php echo esc_attr( get_the_author_meta( 'phone_no', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter your phone number.</span>
    </td>
    </tr>

    <tr>
    <th><label for="street_address">Street Address</label></th>

    <td>
    <input type="text" name="street_address" id="street_address" value="<?php echo esc_attr( get_the_author_meta( 'street_address', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter your address.</span>
    </td>
    </tr>

    <tr>
    <th><label for="address_2">Address 2</label></th>

    <td>
    <input type="text" name="address_2" id="address_2" value="<?php echo esc_attr( get_the_author_meta( 'address_2', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter suite, apt number, etc.</span>
    </td>
    </tr>

    <tr>
    <th><label for="city">City</label></th>

    <td>
    <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter your city.</span>
    </td>
    </tr>

    <tr>
    <th><label for="state">State</label></th>

    <td>
    <input type="text" name="state" id="state" value="<?php echo esc_attr( get_the_author_meta( 'state', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter your state.</span>
    </td>
    </tr>

    <tr>
    <th><label for="zip_code">Zip Code</label></th>

    <td>
    <input type="text" name="zip_code" id="zip_code" value="<?php echo esc_attr( get_the_author_meta( 'zip_code', $user->ID ) ); ?>" class="regular-text" />
    <span class="description">Please enter your zip code.</span>
    </td>
    </tr>

    </table>
    <?php }
    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_user_meta( $user_id, 'phone_no', $_POST['phone_no'] );
    update_user_meta( $user_id, 'street_address', $_POST['street_address'] );
    update_user_meta( $user_id, 'address_2', $_POST['address_2'] );
    update_user_meta( $user_id, 'city', $_POST['city'] );
    update_user_meta( $user_id, 'state', $_POST['state'] );
    update_user_meta( $user_id, 'zip_code', $_POST['zip_code'] );
    }

    But now just above that are Address, City, State, Zip Code and Country fields.
    I don’t know where they came from.

    https://www.ads-software.com/plugins/theme-my-login/

  • The topic ‘Duplicate profile fields’ is closed to new replies.