[wp-trac] [WordPress Trac] #58349: TypeError in wp_check_filetype_and_ext hook: bool values into $mimes argument can be passed
WordPress Trac
noreply at wordpress.org
Thu May 18 05:46:27 UTC 2023
#58349: TypeError in wp_check_filetype_and_ext hook: bool values into $mimes
argument can be passed
-----------------------------+-----------------------------
Reporter: platonkristinin | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
-----------------------------+-----------------------------
[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
<?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
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58349>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list