# Phone and Company Fields in User Profiles

> Adds Phone and Company fields to user profiles, editable by the user and by administrators.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, profile, fields
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/phone-company-profile-fields/

## Code

```php
// Meta key => label.
$wpide_profile_fields = array(
    'wpide_phone'   => 'Phone',
    'wpide_company' => 'Company',
);

$wpide_profile_fields_render = function ( $user ) use ( $wpide_profile_fields ) {
    echo '<h2>Contact Details</h2><table class="form-table" role="presentation">';
    foreach ( $wpide_profile_fields as $key => $label ) {
        printf(
            '<tr><th><label for="%1$s">%2$s</label></th><td><input type="text" class="regular-text" name="%1$s" id="%1$s" value="%3$s"></td></tr>',
            esc_attr( $key ),
            esc_html( $label ),
            esc_attr( get_user_meta( $user->ID, $key, true ) )
        );
    }
    echo '</table>';
};

add_action( 'show_user_profile', $wpide_profile_fields_render );
add_action( 'edit_user_profile', $wpide_profile_fields_render );

// WordPress verifies the profile form nonce before these actions run.
$wpide_profile_fields_save = function ( $user_id ) use ( $wpide_profile_fields ) {
    if ( ! current_user_can( 'edit_user', $user_id ) ) {
        return;
    }

    foreach ( array_keys( $wpide_profile_fields ) as $key ) {
        if ( isset( $_POST[ $key ] ) ) {
            update_user_meta( $user_id, $key, sanitize_text_field( wp_unslash( $_POST[ $key ] ) ) );
        }
    }
};

add_action( 'personal_options_update', $wpide_profile_fields_save );
add_action( 'edit_user_profile_update', $wpide_profile_fields_save );
```

## Notes

Read a value in templates with get_user_meta( $user_id, 'wpide_phone', true ).

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Phone and Company Fields in User Profiles" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
