# Prefill WPForms With the Logged-In User's Details

> Fills WPForms name and email fields with the logged-in visitor's details, so members and customers do not have to type them again.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, prefill, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-prefill-logged-in-user/

## Code

```php
add_filter( 'wpforms_field_properties', function ( $properties, $field, $form_data ) {
    if ( ! is_user_logged_in() || ! in_array( $field['type'], array( 'name', 'email' ), true ) ) {
        return $properties;
    }

    $user = wp_get_current_user();

    if ( 'email' === $field['type'] && empty( $properties['inputs']['primary']['attr']['value'] ) ) {
        $properties['inputs']['primary']['attr']['value'] = $user->user_email;
    }

    if ( 'name' === $field['type'] && ( empty( $field['format'] ) || 'simple' === $field['format'] ) && empty( $properties['inputs']['primary']['attr']['value'] ) ) {
        $properties['inputs']['primary']['attr']['value'] = $user->display_name;
    }

    return $properties;
}, 10, 3 );
```

## Notes

Works with the Simple name format and email fields; fields with their own default value are left alone.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Prefill WPForms With the Logged-In User's Details" 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/
