Ticket #41801: 41801.3.diff
| File 41801.3.diff, 8.4 KB (added by , 8 years 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! 1207 1207 ); 1208 1208 1209 1209 $misc_exts = array( 1210 // Images.1211 'jpg',1212 'jpeg',1213 'png',1214 'gif',1215 1210 // Video. 1216 1211 'mov', 1217 1212 'avi', … … We hope you enjoy your new site. Thanks! 1236 1231 ); 1237 1232 $audio_exts = wp_get_audio_extensions(); 1238 1233 $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 ) ); 1240 1236 1241 1237 $sitemeta = array( 1242 1238 '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'] ) ) { 372 372 <tr> 373 373 <th scope="row"><label for="upload_filetypes"><?php _e( 'Upload file types' ); ?></label></th> 374 374 <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" /> 376 376 <p class="description" id="upload-filetypes-desc"> 377 377 <?php _e( 'Allowed file types. Separate types by spaces.' ); ?> 378 378 </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 { 86 86 if ( $this->setting->default ) { 87 87 // Fake an attachment model - needs all fields used by template. 88 88 // 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'; 90 90 $default_attachment = array( 91 91 'id' => 1, 92 92 '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 ) { 3117 3117 3118 3118 $matches = array(); 3119 3119 $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(); 3121 3121 3122 3122 // Don't convert smilies that aren't images - they're probably emoji. 3123 3123 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() { 2494 2494 return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'flv' ) ); 2495 2495 } 2496 2496 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 */ 2504 function 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 2497 2516 /** 2498 2517 * Builds the Video shortcode output. 2499 2518 * -
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 ) { 1864 1864 * @return array 1865 1865 */ 1866 1866 function 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() ) ) ); 1868 1868 $site_mimes = array(); 1869 1869 foreach ( $site_exts as $ext ) { 1870 1870 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 ) { 5759 5759 5760 5760 switch ( $type ) { 5761 5761 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() ); 5764 5763 5765 5764 case 'audio': 5766 5765 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; 2480 2480 2481 2481 $this->assertSame( $expected, $url ); 2482 2482 } 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 } 2483 2543 } 2484 2544 2485 2545 /**
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)