Skip to Content
Frontlane Studio
All Snippets
PHP WordPress October 4, 2022

Allow JSON Uploads to WordPress Media Library

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

WordPress PHP

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

<?php
/**
 * Allow JSON file uploads to WordPress media library.
 *
 * @package WordPress
 *
 * @author Justin Kopepasah <justin@kopepasah.com>
 */

/**
 * 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' ] );
	}
);

*/

/**
 * 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' ] );
	}
);