Commit 1992c9cf03 for wordpress.org
commit 1992c9cf0329a11b0aea2357668ff7135999cc1f
Author: SergeyBiryukov <sergeybiryukov@git.wordpress.org>
Date: Tue Nov 3 14:51:59 2026 +0000
Media: Ignore empty items in a comma-separated `post_mime_type` string.
`wp_post_mime_type_where()` splits a comma-separated string of MIME types with `explode()`. An extra comma left an empty item, and the empty string is one of the wildcards, so a value like `image/jpeg,` returned no clause and matched every MIME type. This affected `WP_Query` and `get_posts()` with `post_mime_type`, `wp_count_attachments()` and the media modal's `query-attachments` Ajax request.
**What changes**
- `wp_post_mime_type_where()`: after a string is split, empty items are removed with `array_diff()`. A value of `'0'` is not removed.
- Arrays are not changed. An empty string, a string of only commas and spaces, and an explicit `%` still match every MIME type.
Developed in https://github.com/WordPress/wordpress-develop/pull/15403.
Follow-up to r6910.
Props ekamran.
Fixes #66454.
Built from https://develop.svn.wordpress.org/trunk@65229
git-svn-id: http://core.svn.wordpress.org/trunk@64378 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/post.php b/wp-includes/post.php
index 4cb9e69f5f..5806d879f1 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -3955,6 +3955,8 @@ function wp_post_mime_type_where( $post_mime_types, $table_alias = '' ) {
$wildcards = array( '', '%', '%/%' );
if ( is_string( $post_mime_types ) ) {
$post_mime_types = array_map( 'trim', explode( ',', $post_mime_types ) );
+ // Skip empty items left by extra commas, so they do not match the '' wildcard.
+ $post_mime_types = array_diff( $post_mime_types, array( '' ) );
}
$where_clauses = array();
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 2489f9e795..baeab0d306 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.2-beta3-65228';
+$wp_version = '7.2-beta3-65229';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.