WordPress.org

Make WordPress Core

Ticket #41801: 41801.2.diff

File 41801.2.diff, 4.6 KB (added by pbiron, 18 months ago)

revised patch: add unit tests, add call to wp_get_image_extensions() in populate_network()

  • src/wp-admin/includes/schema.php

    From fa50751418b2af7ed175ed564c095bdf9e780b6d Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Fri, 17 Aug 2018 12:21:55 -0600
    Subject: [PATCH] revised patch: add unit tests, add call to
     wp_get_image_extensions() in populate_network()
    
    ---
     src/wp-admin/includes/schema.php |  3 +-
     src/wp-includes/media.php        | 19 ++++++++++++
     src/wp-includes/post.php         |  3 +-
     tests/phpunit/tests/media.php    | 65 ++++++++++++++++++++++++++++++++++++++++
     4 files changed, 87 insertions(+), 3 deletions(-)
    
    diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php
    index 4611ead..c5a5944 100644
    a b We hope you enjoy your new site. Thanks! 
    11141114        );
    11151115        $audio_exts       = wp_get_audio_extensions();
    11161116        $video_exts       = wp_get_video_extensions();
    1117         $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) );
     1117        $image_exts       = wp_get_image_extensions();
     1118        $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts, $image_exts ) );
    11181119
    11191120        $sitemeta = array(
    11201121                'site_name'                   => $site_name,
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index 33c2e83..5333f4f 100644
    a b function wp_get_video_extensions() { 
    24952495}
    24962496
    24972497/**
     2498 * Returns a filtered list of WP-supported image formats.
     2499 *
     2500 * @since 5.0.0
     2501 *
     2502 * @return array List of supported image formats.
     2503 */
     2504function wp_get_image_extensions() {
     2505        /**
     2506         * Filters the list of supported image formats.
     2507         *
     2508         * @since 5.0.0
     2509         *
     2510         * @param array $extensions An array of support image formats. Defaults are
     2511         *                          'jpg', 'jpeg', 'jpe', 'gif', 'png'.
     2512         */
     2513        return apply_filters( 'wp_image_extensions', array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ) );
     2514}
     2515
     2516/**
    24982517 * Builds the Video shortcode output.
    24992518 *
    25002519 * This implements the functionality of the Video Shortcode for displaying
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 3c2b782..e79bf75 100644
    a b function wp_attachment_is( $type, $post = null ) { 
    56975697
    56985698        switch ( $type ) {
    56995699                case 'image':
    5700                         $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
    5701                         return in_array( $ext, $image_exts );
     5700                        return in_array( $ext, wp_get_audio_extensions() );
    57025701
    57035702                case 'audio':
    57045703                        return in_array( $ext, wp_get_audio_extensions() );
  • tests/phpunit/tests/media.php

    diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
    index eea6f24..3b8f8f9 100644
    a b EOF; 
    24802480
    24812481                $this->assertSame( $expected, $url );
    24822482        }
     2483
     2484        /**
     2485         * @ticket 41801
     2486         */
     2487        function test_media_extensions() {
     2488                $default_audio_exts = wp_get_audio_extensions();
     2489
     2490                add_filter( 'wp_audio_extensions', array( $this, '_add_aiff_audio_extension' ) );
     2491                $this->assertEquals( array_merge( $default_audio_exts, array( 'aiff' ) ), wp_get_audio_extensions() );
     2492                remove_filter( 'wp_audio_extensions', array( $this, '_add_aiff_audio_extension' ) );
     2493
     2494                $default_video_exts = wp_get_video_extensions();
     2495
     2496                add_filter( 'wp_video_extensions', array( $this, '_add_mov_video_extension' ) );
     2497                $this->assertEquals( array_merge( $default_video_exts, array( 'mov' ) ), wp_get_video_extensions() );
     2498                remove_filter( 'wp_video_extensions', array( $this, '_add_mov_video_extension' ) );
     2499
     2500                $default_image_exts = wp_get_image_extensions();
     2501
     2502                add_filter( 'wp_image_extensions', array( $this, '_add_bmp_image_extension' ) );
     2503                $this->assertEquals( array_merge( $default_image_exts, array( 'bmp' ) ), wp_get_image_extensions() );
     2504                remove_filter( 'wp_image_extensions', array( $this, '_add_bmp_image_extension' ) );
     2505        }
     2506
     2507        /**
     2508         * Helper for test_media_extensions().
     2509         *
     2510         * Function to hook to `wp_audio_extensions`.
     2511         *
     2512         * @param array $exts Audio file extensions.
     2513         * @return array
     2514         */
     2515        function _add_aiff_audio_extension( $exts ) {
     2516                $exts[] = 'aiff';
     2517
     2518                return $exts;
     2519        }
     2520
     2521        /**
     2522         * Helper for test_media_extensions().
     2523         *
     2524         * Function to hook to `wp_video_extensions`.
     2525         *
     2526         * @param array $exts Video file extensions.
     2527         * @return array
     2528         */
     2529        function _add_mov_video_extension( $exts ) {
     2530                $exts[] = 'mov';
     2531
     2532                return $exts;
     2533        }
     2534
     2535        /**
     2536         * Helper for test_media_extensions().
     2537         *
     2538         * Function to hook to `wp_image_extensions`.
     2539         *
     2540         * @param array $exts Image file extensions.
     2541         * @return array
     2542         */
     2543        function _add_bmp_image_extension( $exts ) {
     2544                $exts[] = 'bmp';
     2545
     2546                return $exts;
     2547        }
    24832548}
    24842549
    24852550/**