[wp-trac] [WordPress Trac] #45633: finfo_file() returns text/plain for json file instead of application/json

WordPress Trac noreply at wordpress.org
Mon Nov 7 06:53:53 UTC 2022


#45633: finfo_file() returns text/plain for json file instead of application/json
--------------------------+-----------------------------
 Reporter:  tabrisrp      |       Owner:  joemcgill
     Type:  defect (bug)  |      Status:  assigned
 Priority:  normal        |   Milestone:  Future Release
Component:  Upload        |     Version:  5.0.1
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |     Focuses:  administration
--------------------------+-----------------------------

Comment (by pelentak):

 Maybe a fix for this issue is to force json type:
 {{{#!php
 <?php
 function forceJsonType(array $data, string $file, string $filename,
 $mimes): array
 {
     $ext = isset($data['ext']) ? (string) $data['ext'] : '';

     if (strlen($ext) < 1) {
         $exploded = explode('.', $filename);
         $ext = strtolower(end($exploded));
     }

     if ($ext !== 'json') {
         return $data;
     }

     $data['ext'] = 'json';
     $data['type'] = 'application/json';

     return $data;
 }

 add_filter(
     'wp_check_filetype_and_ext',
     'forceJsonType',
     10,
     4
 );

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45633#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list