# Default Upload Limits for WPForms File Fields

> Gives every WPForms file upload field a safe list of allowed file types and a maximum size when the field does not set its own.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, uploads, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-default-upload-limits/

## Code

```php
$wpide_wpf_upload_ext = 'pdf,doc,docx,jpg,jpeg,png'; // Allowed extensions.
$wpide_wpf_upload_mb  = 5;                           // Maximum size in MB.

$wpide_wpf_upload_defaults = function ( $form_data ) use ( $wpide_wpf_upload_ext, $wpide_wpf_upload_mb ) {
    if ( empty( $form_data['fields'] ) || ! is_array( $form_data['fields'] ) ) {
        return $form_data;
    }

    foreach ( $form_data['fields'] as $id => $field ) {
        if ( 'file-upload' !== $field['type'] ) {
            continue;
        }
        if ( empty( $field['extensions'] ) ) {
            $form_data['fields'][ $id ]['extensions'] = $wpide_wpf_upload_ext;
        }
        if ( empty( $field['max_size'] ) ) {
            $form_data['fields'][ $id ]['max_size'] = $wpide_wpf_upload_mb;
        }
    }

    return $form_data;
};

add_filter( 'wpforms_frontend_form_data', $wpide_wpf_upload_defaults );
add_filter( 'wpforms_process_before_form_data', $wpide_wpf_upload_defaults );
```

## Notes

Applies to the File Upload field available in WPForms Pro and newer Lite versions; values set on the field always win.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Default Upload Limits for WPForms File Fields" 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/
