From f5aa4c90bcf8cccc433a0b2b37f4b77a0e4b518e Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Tue, 18 Jun 2024 14:46:10 +0000 Subject: [PATCH] Code Modernization: Fix non-nullable deprecation in get_available_post_mime_types(). Fixes a PHP 8.1 and above "null to non-nullable" deprecation notice in `get_available_post_mime_types()`: {{{ Deprecated: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in ./wp-includes/post.php on line 3395 }}} [https://developer.wordpress.org/reference/functions/get_available_post_mime_types/#return This function is documented] to: * Return `An array of MIME types.` * as an array of `string`s, i.e. `string[]`. A `null` or empty element within the returned array is not a valid MIME type. If a `null` exists in the returned array, it is the root cause of PHP throwing the deprecation notice. This commit removes the `null` and empty elements from the returned array of MIME types. It also adds a unit test. Follow-up to [56623], [56452]. Props nosilver4u, jrf, ironprogrammer, antpb, antonvlasenko, rajinsharwar, hellofromTonya. Fixes #59195. Built from https://develop.svn.wordpress.org/trunk@58437 git-svn-id: http://core.svn.wordpress.org/trunk@57886 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 5 +++-- wp-includes/version.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 2f7cba613f..993056ff2c 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -8094,10 +8094,11 @@ function get_available_post_mime_types( $type = 'attachment' ) { $mime_types = apply_filters( 'pre_get_available_post_mime_types', null, $type ); if ( ! is_array( $mime_types ) ) { - $mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) ); + $mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s AND post_mime_type != ''", $type ) ); } - return $mime_types; + // Remove nulls from returned $mime_types. + return array_values( array_filter( $mime_types ) ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 45917072ae..cbf661fdf0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-beta2-58436'; +$wp_version = '6.6-beta2-58437'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.