Make WordPress Core

Changeset 61576


Ignore:
Timestamp:
02/02/2026 06:13:27 AM (5 weeks ago)
Author:
westonruter
Message:

Customize: Use wp_check_filetype() instead of substr() to extract file extension.

This fixes compatibility with image files that have 4-character extensions, such as .webp and .avif.

Follow-up to [57524], [50810], [30309].

Props buutqn, westonruter.
See #51228, #35725, #21483.
Fixes #64557.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/customize/class-wp-customize-media-control.php

    r60645 r61576  
    9393                 * Note that the default value must be a URL, NOT an attachment ID.
    9494                 */
    95                 $ext  = substr( $this->setting->default, -3 );
    96                 $type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp', 'webp', 'avif' ), true ) ? 'image' : 'document';
     95                $ext       = wp_check_filetype( $this->setting->default )['ext'];
     96                $ext_types = wp_get_ext_types();
     97                $type      = isset( $ext_types['image'] ) && in_array( $ext, $ext_types['image'], true ) ? 'image' : 'document';
    9798
    9899                $default_attachment = array(
Note: See TracChangeset for help on using the changeset viewer.