# Allow JSON, CSV and Other Data File Uploads

> Lets administrators upload data files such as JSON, CSV, XML and Markdown to the Media Library, which WordPress blocks by default.

- Type: PHP
- Runs: Run everywhere
- Category: [Developer](https://wpide.com/library/category/developer/)
- Tags: uploads, media, mime-types, files
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/dev-allow-json-csv-uploads/

## Code

```php
add_filter( 'upload_mimes', function ( $mimes ) {
    if ( ! current_user_can( 'manage_options' ) ) {
        return $mimes;
    }

    // Extension => MIME type.
    $types = array(
        'json' => 'application/json',
        'csv'  => 'text/csv',
        'xml'  => 'application/xml',
        'md'   => 'text/markdown',
    );

    return array_merge( $mimes, $types );
} );

add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename, $mimes ) {
    if ( ! empty( $data['ext'] ) || ! current_user_can( 'manage_options' ) ) {
        return $data;
    }

    $check = wp_check_filetype( $filename, $mimes );

    if ( in_array( $check['ext'], array( 'json', 'csv', 'xml', 'md' ), true ) ) {
        $data['ext']  = $check['ext'];
        $data['type'] = $check['type'];
    }

    return $data;
}, 10, 4 );
```

## Notes

Only users with the manage_options capability get the extra file types. Edit $types to add or remove extensions.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Allow JSON, CSV and Other Data File Uploads" 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/
