Make WordPress Core

Changeset 56452

Timestamp:
08/24/2023 04:53:15 PM (12 months ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r56414 r56452  
    78677867    global $wpdb;
    78687868
    7869     $types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) );
    7870     return $types;
     7869    /**
     7870     * Filters the list of available post MIME types for the given post type.
     7871     *
     7872     * @since 6.4.0
     7873     *
     7874     * @param string[]|null $mime_types An array of MIME types. Default null.
     7875     * @param string        $type       The post type name. Usually 'attachment' but can be any post type.
     7876     */
     7877    $mime_types = apply_filters( 'get_available_post_mime_types', null, $type );
     7878
     7879    if ( ! is_array( $mime_types ) ) {
     7880        $mime_types = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT post_mime_type FROM $wpdb->posts WHERE post_type = %s", $type ) );
     7881    }
     7882
     7883    return $mime_types;
    78717884}
    78727885
Note: See TracChangeset for help on using the changeset viewer.