WordPress.org

Support

Support » Plugins and Hacks » Add extra custom fields to user profiles based on user view

Add extra custom fields to user profiles based on user view

Viewing 1 replies (of 1 total)
  • Rhand
    Participant

    @rhand

    I found some other code at Bavotasan.com that I am working on adjusting:

    // Add Extr profile fields http://bavotasan.com/2009/adding-extra-fields-to-the-wordpress-user-profile/
    
    function extra_user_profile_fields( $user ) { ?>
    <h3><?php _e("Extra profile information", "blank"); ?></h3>
    
    <table class="form-table">
    <tr>
    <th><label for="address"><?php _e("Address"); ?></label></th>
    <td>
    <input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your address."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="city"><?php _e("Birth Place"); ?></label></th>
    <td>
    <input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'birthplace', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your birth place."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="province"><?php _e("Province"); ?></label></th>
    <td>
    <input type="text" name="province" id="province" value="<?php echo esc_attr( get_the_author_meta( 'province', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your province."); ?></span>
    </td>
    </tr>
    <tr>
    <th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
    <td>
    <input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
    <span class="description"><?php _e("Please enter your postal code."); ?></span>
    </td>
    </tr>
    </table>
    <?php }
    
    add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
    
    function save_extra_user_profile_fields( $user_id ) {
    
    if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
    
    update_user_meta( $user_id, 'address', $_POST['address'] );
    update_user_meta( $user_id, 'city', $_POST['birthplace'] );
    update_user_meta( $user_id, 'province', $_POST['province'] );
    update_user_meta( $user_id, 'postalcode', $_POST['postalcode'] );

    I have been able to retrieve stored data already. I will adjust some more fields and update data in a bit.

Viewing 1 replies (of 1 total)
  • The topic ‘Add extra custom fields to user profiles based on user view’ is closed to new replies.