WordPress.org

Make WordPress Core

Ticket #41801: 41801.3.diff

File 41801.3.diff, 8.4 KB (added by pbiron, 14 months ago)
  • src/wp-admin/includes/schema.php

    From eedbe29be5927c63452571bba73f15582d5e4634 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Fri, 4 Jan 2019 09:59:17 -0700
    Subject: [PATCH] Adds wp_get_image_extensions() and wp_image_extensions
     filter.  Replaces hardcoded lists of image extensions across core with a call
     to wp_get_image_extensions().
    
    There are still 2 remaining places in core with hardcoded lists of image extensions that should remain so:
    
    WP_Theme::get_screenshot()
    wp_get_ext_types()
    ---
     src/wp-admin/includes/schema.php              |  8 +--
     src/wp-admin/network/settings.php             |  2 +-
     .../class-wp-customize-media-control.php      |  2 +-
     src/wp-includes/formatting.php                |  2 +-
     src/wp-includes/media.php                     | 19 ++++++
     src/wp-includes/ms-functions.php              |  2 +-
     src/wp-includes/post.php                      |  3 +-
     tests/phpunit/tests/media.php                 | 60 +++++++++++++++++++
     8 files changed, 86 insertions(+), 12 deletions(-)
    
    diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php
    index 0bb6060771..cb60713e72 100644
    a b We hope you enjoy your new site. Thanks! 
    12071207        );
    12081208
    12091209        $misc_exts        = array(
    1210                 // Images.
    1211                 'jpg',
    1212                 'jpeg',
    1213                 'png',
    1214                 'gif',
    12151210                // Video.
    12161211                'mov',
    12171212                'avi',
    We hope you enjoy your new site. Thanks! 
    12361231        );
    12371232        $audio_exts       = wp_get_audio_extensions();
    12381233        $video_exts       = wp_get_video_extensions();
    1239         $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts ) );
     1234        $image_exts       = wp_get_image_extensions();
     1235        $upload_filetypes = array_unique( array_merge( $misc_exts, $audio_exts, $video_exts, $image_exts ) );
    12401236
    12411237        $sitemeta = array(
    12421238                'site_name'                   => __( 'My Network' ),
  • src/wp-admin/network/settings.php

    diff --git a/src/wp-admin/network/settings.php b/src/wp-admin/network/settings.php
    index 1469c70528..96b8923d9e 100644
    a b if ( isset( $_GET['updated'] ) ) { 
    372372                        <tr>
    373373                                <th scope="row"><label for="upload_filetypes"><?php _e( 'Upload file types' ); ?></label></th>
    374374                                <td>
    375                                         <input name="upload_filetypes" type="text" id="upload_filetypes" aria-describedby="upload-filetypes-desc" class="large-text" value="<?php echo esc_attr( get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) ); ?>" size="45" />
     375                                        <input name="upload_filetypes" type="text" id="upload_filetypes" aria-describedby="upload-filetypes-desc" class="large-text" value="<?php echo esc_attr( get_site_option( 'upload_filetypes', implode( ' ', wp_get_image_extensions() ) ) ); ?>" size="45" />
    376376                                        <p class="description" id="upload-filetypes-desc">
    377377                                                <?php _e( 'Allowed file types. Separate types by spaces.' ); ?>
    378378                                        </p>
  • src/wp-includes/customize/class-wp-customize-media-control.php

    diff --git a/src/wp-includes/customize/class-wp-customize-media-control.php b/src/wp-includes/customize/class-wp-customize-media-control.php
    index 338324fd36..d7ac49df2a 100644
    a b class WP_Customize_Media_Control extends WP_Customize_Control { 
    8686                        if ( $this->setting->default ) {
    8787                                // Fake an attachment model - needs all fields used by template.
    8888                                // Note that the default value must be a URL, NOT an attachment ID.
    89                                 $type               = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
     89                                $type               = in_array( substr( $this->setting->default, -3 ), wp_get_image_extensions() ) ? 'image' : 'document';
    9090                                $default_attachment = array(
    9191                                        'id'    => 1,
    9292                                        'url'   => $this->setting->default,
  • src/wp-includes/formatting.php

    diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
    index f858d7b9ab..c9587d2f62 100644
    a b function translate_smiley( $matches ) { 
    31173117
    31183118        $matches    = array();
    31193119        $ext        = preg_match( '/\.([^.]+)$/', $img, $matches ) ? strtolower( $matches[1] ) : false;
    3120         $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
     3120        $image_exts = wp_get_image_extensions();
    31213121
    31223122        // Don't convert smilies that aren't images - they're probably emoji.
    31233123        if ( ! in_array( $ext, $image_exts ) ) {
  • src/wp-includes/media.php

    diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
    index a8bf034f49..c7fe4b4e33 100644
    a b function wp_get_video_extensions() { 
    24942494        return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'flv' ) );
    24952495}
    24962496
     2497/**
     2498 * Returns a filtered list of WP-supported image formats.
     2499 *
     2500 * @since 5.1.0
     2501 *
     2502 * @return array List of supported video formats.
     2503 */
     2504function wp_get_image_extensions() {
     2505        /**
     2506         * Filters the list of supported image formats.
     2507         *
     2508         * @since 5.1.0
     2509         *
     2510         * @param array $extensions An array of supported 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
    24972516/**
    24982517 * Builds the Video shortcode output.
    24992518 *
  • src/wp-includes/ms-functions.php

    diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php
    index eca785f201..101e54b35b 100644
    a b function recurse_dirsize( $directory, $exclude = null ) { 
    18641864 * @return array
    18651865 */
    18661866function check_upload_mimes( $mimes ) {
    1867         $site_exts  = explode( ' ', get_site_option( 'upload_filetypes', 'jpg jpeg png gif' ) );
     1867        $site_exts  = explode( ' ', get_site_option( 'upload_filetypes', implode( ' ', wp_get_image_extensions() ) ) );
    18681868        $site_mimes = array();
    18691869        foreach ( $site_exts as $ext ) {
    18701870                foreach ( $mimes as $ext_pattern => $mime ) {
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index 8debd3db3b..bcf72291e0 100644
    a b function wp_attachment_is( $type, $post = null ) { 
    57595759
    57605760        switch ( $type ) {
    57615761                case 'image':
    5762                         $image_exts = array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' );
    5763                         return in_array( $ext, $image_exts );
     5762                        return in_array( $ext, wp_get_image_extensions() );
    57645763
    57655764                case 'audio':
    57665765                        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 eea6f24a90..6e8c465346 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                return $exts;
     2518        }
     2519        /**
     2520         * Helper for test_media_extensions().
     2521         *
     2522         * Function to hook to `wp_video_extensions`.
     2523         *
     2524         * @param array $exts Video file extensions.
     2525         * @return array
     2526         */
     2527        function _add_mov_video_extension( $exts ) {
     2528                $exts[] = 'mov';
     2529                return $exts;
     2530        }
     2531        /**
     2532         * Helper for test_media_extensions().
     2533         *
     2534         * Function to hook to `wp_image_extensions`.
     2535         *
     2536         * @param array $exts Image file extensions.
     2537         * @return array
     2538         */
     2539        function _add_bmp_image_extension( $exts ) {
     2540                $exts[] = 'bmp';
     2541                return $exts;
     2542        }
    24832543}
    24842544
    24852545/**