From 11d450f47e2ff3d2293f25e50b31ff30f20d94b4 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Thu, 13 Apr 2017 20:21:45 +0000 Subject: [PATCH] Media: Improve filters that allow overriding slow media queries. As a follow-up to [40382], this commit makes the following improvements: - Make the filter names more specific. - Fix the inline documentation (use `@param` instead of `@return). - Use `null ===` instead of `is_null` to avoid extra function calls. - Rename the `$has_audio` and `$has_video` variables now that they actually represent something slightly different. See #31071. git-svn-id: https://develop.svn.wordpress.org/trunk@40421 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 195d0f9c7d..d3ba104454 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -3333,11 +3333,11 @@ function wp_enqueue_media( $args = array() ) { * * @link https://core.trac.wordpress.org/ticket/31071 * - * @return bool|null Whether to show the button, or `null` for default behavior. + * @param bool|null Whether to show the button, or `null` for default behavior. */ - $has_audio = apply_filters( 'media_has_audio', null ); - if ( is_null( $has_audio ) ) { - $has_audio = $wpdb->get_var( " + $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', null ); + if ( null === $show_audio_playlist ) { + $show_audio_playlist = $wpdb->get_var( " SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' @@ -3358,11 +3358,11 @@ function wp_enqueue_media( $args = array() ) { * * @link https://core.trac.wordpress.org/ticket/31071 * - * @return bool|null Whether to show the button, or `null` for default behavior. + * @param bool|null Whether to show the button, or `null` for default behavior. */ - $has_video = apply_filters( 'media_has_video', null ); - if ( is_null( $has_video ) ) { - $has_video = $wpdb->get_var( " + $show_video_playlist = apply_filters( 'media_library_show_video_playlist', null ); + if ( null === $show_video_playlist ) { + $show_video_playlist = $wpdb->get_var( " SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' @@ -3383,11 +3383,11 @@ function wp_enqueue_media( $args = array() ) { * * @link https://core.trac.wordpress.org/ticket/31071 * - * @return array|null An array of objects with `month` and `year` - * properties, or `null` (or any other non-array value) - * for default behavior. + * @param array|null An array of objects with `month` and `year` + * properties, or `null` (or any other non-array value) + * for default behavior. */ - $months = apply_filters( 'media_months', null ); + $months = apply_filters( 'media_library_months_with_files', null ); if ( ! is_array( $months ) ) { $months = $wpdb->get_results( $wpdb->prepare( " SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month @@ -3414,14 +3414,14 @@ function wp_enqueue_media( $args = array() ) { ), 'defaultProps' => $props, 'attachmentCounts' => array( - 'audio' => ( $has_audio ) ? 1 : 0, - 'video' => ( $has_video ) ? 1 : 0 + 'audio' => ( $show_audio_playlist ) ? 1 : 0, + 'video' => ( $show_video_playlist ) ? 1 : 0, ), 'embedExts' => $exts, 'embedMimes' => $ext_mimes, 'contentWidth' => $content_width, 'months' => $months, - 'mediaTrash' => MEDIA_TRASH ? 1 : 0 + 'mediaTrash' => MEDIA_TRASH ? 1 : 0, ); $post = null;