Opened 16 months ago
Closed 16 months ago
#58349 closed defect (bug) (fixed)
TypeError in wp_check_filetype_and_ext hook: bool values into $mimes argument can be passed
Reported by: | platonkristinin | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 6.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
https://developer.wordpress.org/reference/hooks/wp_check_filetype_and_ext/ API doc states that $mimes argument is keyed array:
$mimes string[] Array of mime types keyed by their file extension regex.
But by fact into this argument can be passed a bool data type. When I add my custom hook
<?php function my_check_filetype_and_ext(array $wp_check_filetype_and_ext, string $file, string $filename, array $mimes, string|false $real_mime): array { } add_filter('wp_check_filetype_and_ext', [$this, 'my_check_svg_filetype_and_ext'], accepted_args: 5);
then I get following error:
PHP Fatal error: Uncaught TypeError: Argument #4 ($mimes) must be of type array, bool given
So there is a bug in documentation or in hook implementation. I'm leaning towards the second, because mimes always should be array and there are no reasons to pass boolean values.
Workaround is allow false values for $mimes:
array|false $mimes
Attachments (1)
Change History (6)
Note: See
TracTickets for help on using
tickets.
Thanks for the report. It does indeed seem that
false
can get passed to the$mimes
parameter, which is incorrect. This parameter should be an array of strings ornull
.Ref: https://github.com/WordPress/wordpress-develop/blob/261ab3fa5de7b1972dd52e938cdb4abd8d9014df/src/wp-admin/includes/file.php#L931 .
$mimes
has a fallback offalse
here when it should benull
: https://github.com/WordPress/wordpress-develop/blob/261ab3fa5de7b1972dd52e938cdb4abd8d9014df/src/wp-admin/includes/file.php#L893.