# Allow Font, eBook and Data File Uploads for Administrators

> Lets administrators upload web fonts (WOFF, WOFF2, TTF, OTF), EPUB eBooks, JSON and GPX files to the Media Library, which WordPress blocks by default.

- Type: PHP
- Runs: Run everywhere
- Category: [Media](https://wpide.com/library/category/media/)
- Tags: uploads, mime-types, fonts
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/allow-font-and-data-uploads-for-admins/

## Code

```php
// Extension => MIME type allowed for administrators.
$wpide_extra_mimes = array(
    'woff'  => 'font/woff',
    'woff2' => 'font/woff2',
    'ttf'   => 'font/ttf',
    'otf'   => 'font/otf',
    'epub'  => 'application/epub+zip',
    'json'  => 'application/json',
    'gpx'   => 'application/gpx+xml',
);

add_filter( 'upload_mimes', function ( $mimes, $user = null ) use ( $wpide_extra_mimes ) {
    $user_id = $user instanceof WP_User ? $user->ID : ( $user ? (int) $user : get_current_user_id() );

    if ( user_can( $user_id, 'manage_options' ) ) {
        $mimes = array_merge( $mimes, $wpide_extra_mimes );
    }

    return $mimes;
}, 10, 2 );

// File type detection often reports these formats differently; trust the extension for administrators.
add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename ) use ( $wpide_extra_mimes ) {
    if ( ! empty( $data['ext'] ) || ! current_user_can( 'manage_options' ) ) {
        return $data;
    }

    $ext = strtolower( pathinfo( (string) $filename, PATHINFO_EXTENSION ) );

    if ( isset( $wpide_extra_mimes[ $ext ] ) ) {
        return array( 'ext' => $ext, 'type' => $wpide_extra_mimes[ $ext ], 'proper_filename' => false );
    }

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

## Notes

Other roles keep the default list. Add or remove extensions in $wpide_extra_mimes.

## How to use it

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