[wp-trac] [WordPress Trac] #64056: Media / REST API: Uploading non-resizable image formats (SVG) generates multiple PHP warnings

WordPress Trac noreply at wordpress.org
Tue Sep 30 14:27:40 UTC 2025


#64056: Media / REST API: Uploading non-resizable image formats (SVG) generates
multiple PHP warnings
-----------------------------+-----------------------------
 Reporter:  jignesh.nakrani  |      Owner:  (none)
     Type:  enhancement      |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  REST API         |    Version:
 Severity:  normal           |   Keywords:
  Focuses:  rest-api         |
-----------------------------+-----------------------------
 When uploading an SVG file using the WordPress Media REST API (e.g., via
 /wp/v2/media), the response includes several PHP warnings. These warnings
 indicate undefined array keys for "width" and "height" in image.php,
 followed by multiple "Cannot modify header information" errors in class-
 wp-rest-server.php. The SVG file uploads successfully, but the warnings
 clutter the API response, which can disrupt client-side applications
 expecting clean JSON output.

 '''Steps to Reproduce:'''
 - Set up a WordPress installation with SVG support enabled (e.g., using a
 plugin like Safe SVG or custom code).
    {{{
 // Allow SVG file to be uploaded.
 add_filter( 'upload_mimes', 'custom_mime_types' );

 function custom_mime_types( $mimes ) {
     $mimes['svg'] = 'image/svg+xml';

     return $mimes;
 }
 }}}

 - Use the REST API endpoint /wp/v2/media to upload an SVG file (e.g., via
 a POST request with a valid SVG file and appropriate authentication).

 - Observe the API response, which includes the following warnings:


 {{{
 <br />
 <b>Warning</b>:  Undefined array key "width" in <b>/var/www/src/wp-
 admin/includes/image.php</b> on line <b>110</b><br />
 <br />
 <b>Warning</b>:  Undefined array key "height" in <b>/var/www/src/wp-
 admin/includes/image.php</b> on line <b>111</b><br />
 <br />
 <b>Warning</b>:  Cannot modify header information - headers already sent
 by (output started at /var/www/src/wp-admin/includes/image.php: 110) in
 <b>/var/www/src/wp-includes/rest-api/class-wp-rest-server.php</b> on line
 <b>1896</b><br />
 <br />
 <b>Warning</b>:  Cannot modify header information - headers already sent
 by (output started at /var/www/src/wp-admin/includes/image.php: 110) in
 <b>/var/www/src/wp-includes/rest-api/class-wp-rest-server.php</b> on line
 <b>1896</b><br />
 <br />
 <b>Warning</b>:  Cannot modify header information - headers already sent
 by (output started at /var/www/src/wp-admin/includes/image.php: 110) in
 <b>/var/www/src/wp-includes/rest-api/class-wp-rest-server.php</b> on line
 <b>1896</b><br />
 <br />
 <b>Warning</b>:  Cannot modify header information - headers already sent
 by (output started at /var/www/src/wp-admin/includes/image.php: 110) in
 <b>/var/www/src/wp-includes/rest-api/class-wp-rest-server.php</b> on line
 <b>1896</b><br />
 <br />
 <b>Warning</b>:  Cannot modify header information - headers already sent
 by (output started at /var/www/src/wp-admin/includes/image.php: 110) in
 <b>/var/www/src/wp-includes/rest-api/class-wp-rest-server.php</b> on line
 <b>1920</b><br />
 }}}



 '''Expected Behavior:'''

 The SVG file should upload successfully via the REST API, and the response
 should be a clean JSON object containing the media details without any PHP
 warnings.


 '''Additional Context:'''

 - The issue appears to stem from wp-admin/includes/image.php attempting to
 access width and height keys in the image metadata, which are not
 applicable to SVG files (as SVGs are vector-based and do not have fixed
 pixel dimensions).
 - The subsequent header warnings in class-wp-rest-server.php are likely
 caused by the earlier warnings outputting text before headers are sent,
 breaking the REST API's ability to set headers properly.
 - Tested on a fresh WordPress install with minimal plugins to confirm the
 issue persists.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64056>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list