Skip to content

Commit 4dbb202

Browse files
committed
Media: Correct the fallback value passed to the $mimes parameter of wp_check_filetype_and_ext() from _wp_handle_upload(), and update corresponding documentation.
Previously when the `mimes` element was not specified in the overrides array passed to `_wp_handle_upload()` it resulted in boolean false being passed to this parameter, which is incorrect. The fallback value should be `null`. Props platonkristinin, pkbhatt Fixes #58349 git-svn-id: https://develop.svn.wordpress.org/trunk@55872 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 240f914 commit 4dbb202

2 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/wp-admin/includes/file.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ function wp_handle_upload_error( &$file, $message ) {
890890

891891
// If you override this, you must provide $ext and $type!!
892892
$test_type = isset( $overrides['test_type'] ) ? $overrides['test_type'] : true;
893-
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : false;
893+
$mimes = isset( $overrides['mimes'] ) ? $overrides['mimes'] : null;
894894

895895
// A correct form post will pass this test.
896896
if ( $test_form && ( ! isset( $_POST['action'] ) || $_POST['action'] !== $action ) ) {

src/wp-includes/functions.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,9 +3012,9 @@ function wp_get_default_extension_for_mime_type( $mime_type ) {
30123012
*
30133013
* @since 2.0.4
30143014
*
3015-
* @param string $filename File name or path.
3016-
* @param string[] $mimes Optional. Array of allowed mime types keyed by their file extension regex.
3017-
* Defaults to the result of get_allowed_mime_types().
3015+
* @param string $filename File name or path.
3016+
* @param string[]|null $mimes Optional. Array of allowed mime types keyed by their file extension regex.
3017+
* Defaults to the result of get_allowed_mime_types().
30183018
* @return array {
30193019
* Values for the extension and mime type.
30203020
*
@@ -3053,11 +3053,11 @@ function wp_check_filetype( $filename, $mimes = null ) {
30533053
*
30543054
* @since 3.0.0
30553055
*
3056-
* @param string $file Full path to the file.
3057-
* @param string $filename The name of the file (may differ from $file due to $file being
3058-
* in a tmp directory).
3059-
* @param string[] $mimes Optional. Array of allowed mime types keyed by their file extension regex.
3060-
* Defaults to the result of get_allowed_mime_types().
3056+
* @param string $file Full path to the file.
3057+
* @param string $filename The name of the file (may differ from $file due to $file being
3058+
* in a tmp directory).
3059+
* @param string[]|null $mimes Optional. Array of allowed mime types keyed by their file extension regex.
3060+
* Defaults to the result of get_allowed_mime_types().
30613061
* @return array {
30623062
* Values for the extension, mime type, and corrected filename.
30633063
*
@@ -3239,18 +3239,19 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
32393239
* @since 3.0.0
32403240
* @since 5.1.0 The $real_mime parameter was added.
32413241
*
3242-
* @param array $wp_check_filetype_and_ext {
3242+
* @param array $wp_check_filetype_and_ext {
32433243
* Values for the extension, mime type, and corrected filename.
32443244
*
32453245
* @type string|false $ext File extension, or false if the file doesn't match a mime type.
32463246
* @type string|false $type File mime type, or false if the file doesn't match a mime type.
32473247
* @type string|false $proper_filename File name with its correct extension, or false if it cannot be determined.
32483248
* }
3249-
* @param string $file Full path to the file.
3250-
* @param string $filename The name of the file (may differ from $file due to
3251-
* $file being in a tmp directory).
3252-
* @param string[] $mimes Array of mime types keyed by their file extension regex.
3253-
* @param string|false $real_mime The actual mime type or false if the type cannot be determined.
3249+
* @param string $file Full path to the file.
3250+
* @param string $filename The name of the file (may differ from $file due to
3251+
* $file being in a tmp directory).
3252+
* @param string[]|null $mimes Array of mime types keyed by their file extension regex, or null if
3253+
* none were provided.
3254+
* @param string|false $real_mime The actual mime type or false if the type cannot be determined.
32543255
*/
32553256
return apply_filters( 'wp_check_filetype_and_ext', compact( 'ext', 'type', 'proper_filename' ), $file, $filename, $mimes, $real_mime );
32563257
}

0 commit comments

Comments
 (0)