From aa8ba65a34e905de37d9764ba08e1a8dcdee8071 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 24 Aug 2023 16:55:18 +0000 Subject: [PATCH] Media: Add a filter to the `get_available_post_mime_types()` function to allow overriding its database query. This introduces the `get_available_post_mime_types` filter so this query can be skipped or cached by plugins. Props maciejmackowiak, archon810, rcorrales Fixes #52759 Built from https://develop.svn.wordpress.org/trunk@56452 git-svn-id: http://core.svn.wordpress.org/trunk@55964 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 17 +++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 59b1975207..5367f51e06 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -7866,8 +7866,21 @@ function wp_cache_set_posts_last_changed() { function get_available_post_mime_types( $type = 'attachment' ) { global $wpdb; - $types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) ); - return $types; + /** + * Filters the list of available post MIME types for the given post type. + * + * @since 6.4.0 + * + * @param string[]|null $mime_types An array of MIME types. Default null. + * @param string $type The post type name. Usually 'attachment' but can be any post type. + */ + $mime_types = apply_filters( '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 ) ); + } + + return $mime_types; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 0853fa1576..8bfc43a2a9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56451'; +$wp_version = '6.4-alpha-56452'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.