Allow JSON Uploads to WordPress Media Library

Last updated 2 months ago

PHP

<?php
/**
 * Allow JSON file uploads to WordPress media library.
 *
 * @package WordPress
 *
 * @author Justin Kopepasah <[email protected]>
 */

/**
 * Filters the uploads mime types to allow JSON files.
 *
 * @param array $types Currently allowed types.
 *
 * @return array Filtered types.
 */
add_filter(
	'upload_mimes',
	function( $types ) {
		return array_merge( $types, [ 'json' => 'text/plain' ] );
	}
);

Source: https://koop.sh/software/allow-json-uploads-to-wordpress-media-library/

All code snippets are licensed GPLv2 or later unless otherwise stated.