Make WordPress Core

Changeset 40421


Ignore:
Timestamp:
04/13/2017 08:21:45 PM (9 years ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

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

    r40382 r40421  
    33343334         * @link https://core.trac.wordpress.org/ticket/31071
    33353335         *
    3336          * @return bool|null Whether to show the button, or `null` for default behavior.
    3337          */
    3338         $has_audio = apply_filters( 'media_has_audio', null );
    3339         if ( is_null( $has_audio ) ) {
    3340                 $has_audio = $wpdb->get_var( "
     3336         * @param bool|null Whether to show the button, or `null` for default behavior.
     3337         */
     3338        $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', null );
     3339        if ( null === $show_audio_playlist ) {
     3340                $show_audio_playlist = $wpdb->get_var( "
    33413341                        SELECT ID
    33423342                        FROM $wpdb->posts
     
    33593359         * @link https://core.trac.wordpress.org/ticket/31071
    33603360         *
    3361          * @return bool|null Whether to show the button, or `null` for default behavior.
    3362          */
    3363         $has_video = apply_filters( 'media_has_video', null );
    3364         if ( is_null( $has_video ) ) {
    3365                 $has_video = $wpdb->get_var( "
     3361         * @param bool|null Whether to show the button, or `null` for default behavior.
     3362         */
     3363        $show_video_playlist = apply_filters( 'media_library_show_video_playlist', null );
     3364        if ( null === $show_video_playlist ) {
     3365                $show_video_playlist = $wpdb->get_var( "
    33663366                        SELECT ID
    33673367                        FROM $wpdb->posts
     
    33843384         * @link https://core.trac.wordpress.org/ticket/31071
    33853385         *
    3386          * @return array|null An array of objects with `month` and `year`
    3387          *                    properties, or `null` (or any other non-array value)
    3388          *                    for default behavior.
    3389          */
    3390         $months = apply_filters( 'media_months', null );
     3386         * @param array|null An array of objects with `month` and `year`
     3387         *                   properties, or `null` (or any other non-array value)
     3388         *                   for default behavior.
     3389         */
     3390        $months = apply_filters( 'media_library_months_with_files', null );
    33913391        if ( ! is_array( $months ) ) {
    33923392                $months = $wpdb->get_results( $wpdb->prepare( "
     
    34153415                'defaultProps' => $props,
    34163416                'attachmentCounts' => array(
    3417                         'audio' => ( $has_audio ) ? 1 : 0,
    3418                         'video' => ( $has_video ) ? 1 : 0
     3417                        'audio' => ( $show_audio_playlist ) ? 1 : 0,
     3418                        'video' => ( $show_video_playlist ) ? 1 : 0,
    34193419                ),
    34203420                'embedExts'    => $exts,
     
    34223422                'contentWidth' => $content_width,
    34233423                'months'       => $months,
    3424                 'mediaTrash'   => MEDIA_TRASH ? 1 : 0
     3424                'mediaTrash'   => MEDIA_TRASH ? 1 : 0,
    34253425        );
    34263426
Note: See TracChangeset for help on using the changeset viewer.