Ticket #60835: 60835.1.diff
| File 60835.1.diff, 6.1 KB (added by , 22 months ago) |
|---|
-
src/wp-admin/includes/file.php
diff --git src/wp-admin/includes/file.php src/wp-admin/includes/file.php index 60416754f3..158542df53 100644
function _wp_handle_upload( &$file, $overrides, $time, $action ) { 877 877 $unique_filename_callback = $overrides['unique_filename_callback']; 878 878 } 879 879 880 // You may define your own subdirectory and pass the name in $overrides['subdir']. 881 $subdir = isset( $overrides['subdir'] ) ? $overrides['subdir'] : ''; 882 880 883 /* 881 884 * This may not have originally been intended to be overridable, 882 885 * but historically has been. … … function _wp_handle_upload( &$file, $overrides, $time, $action ) { 976 979 * A writable uploads dir will pass this test. Again, there's no point 977 980 * overriding this one. 978 981 */ 979 $uploads = wp_upload_dir( $time );982 $uploads = wp_upload_dir( $time, true, false, $subdir ); 980 983 if ( ! ( $uploads && false === $uploads['error'] ) ) { 981 984 return call_user_func_array( $upload_error_handler, array( &$file, $uploads['error'] ) ); 982 985 } -
src/wp-includes/fonts.php
diff --git src/wp-includes/fonts.php src/wp-includes/fonts.php index 4806662160..68ded26989 100644
function wp_get_font_dir() { 126 126 * } 127 127 */ 128 128 function wp_font_dir( $create_dir = true ) { 129 /* 130 * Allow extenders to manipulate the font directory consistently. 131 * 132 * Ensures the upload_dir filter is fired both when calling this function 133 * directly and when the upload directory is filtered in the Font Face 134 * REST API endpoint. 135 */ 136 add_filter( 'upload_dir', '_wp_filter_font_directory' ); 137 $font_dir = wp_upload_dir( null, $create_dir, false ); 138 remove_filter( 'upload_dir', '_wp_filter_font_directory' ); 139 return $font_dir; 140 } 141 142 /** 143 * A callback function for use in the {@see 'upload_dir'} filter. 144 * 145 * This function is intended for internal use only and should not be used by plugins and themes. 146 * Use wp_get_font_dir() instead. 147 * 148 * @since 6.5.0 149 * @access private 150 * 151 * @param string $font_dir The font directory. 152 * @return string The modified font directory. 153 */ 154 function _wp_filter_font_directory( $font_dir ) { 155 if ( doing_filter( 'font_dir' ) ) { 156 // Avoid an infinite loop. 157 return $font_dir; 158 } 159 160 $font_dir = array( 161 'path' => untrailingslashit( $font_dir['basedir'] ) . '/fonts', 162 'url' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts', 163 'subdir' => '', 164 'basedir' => untrailingslashit( $font_dir['basedir'] ) . '/fonts', 165 'baseurl' => untrailingslashit( $font_dir['baseurl'] ) . '/fonts', 166 'error' => false, 167 ); 129 $font_dir = wp_upload_dir( null, $create_dir, false, '/fonts' ); 168 130 169 131 /** 170 132 * Filters the fonts directory data. -
src/wp-includes/functions.php
diff --git src/wp-includes/functions.php src/wp-includes/functions.php index b85036cb95..4d703e2963 100644
function wp_get_upload_dir() { 2348 2348 * @param bool $create_dir Optional. Whether to check and create the uploads directory. 2349 2349 * Default true for backward compatibility. 2350 2350 * @param bool $refresh_cache Optional. Whether to refresh the cache. Default false. 2351 * @param string $subdir Optional. Sub directories to override default time formatted in 'yyyy/mm'. Default empty. 2351 2352 * @return array { 2352 2353 * Array of information about the upload directory. 2353 2354 * … … function wp_get_upload_dir() { 2359 2360 * @type string|false $error False or error message. 2360 2361 * } 2361 2362 */ 2362 function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false ) {2363 function wp_upload_dir( $time = null, $create_dir = true, $refresh_cache = false, $subdir = '' ) { 2363 2364 static $cache = array(), $tested_paths = array(); 2364 2365 2365 2366 $key = sprintf( '%d-%s', get_current_blog_id(), (string) $time ); 2366 2367 2367 2368 if ( $refresh_cache || empty( $cache[ $key ] ) ) { 2368 $cache[ $key ] = _wp_upload_dir( $time );2369 $cache[ $key ] = _wp_upload_dir( $time, $subdir ); 2369 2370 } 2370 2371 2371 2372 /** -
src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php index c7f72d4ec1..8620645cc5 100644
class WP_REST_Font_Faces_Controller extends WP_REST_Posts_Controller { 856 856 */ 857 857 protected function handle_font_file_upload( $file ) { 858 858 add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); 859 // Filter the upload directory to return the fonts directory.860 add_filter( 'upload_dir', '_wp_filter_font_directory' );861 859 862 860 $overrides = array( 863 861 'upload_error_handler' => array( $this, 'handle_font_file_upload_error' ), … … class WP_REST_Font_Faces_Controller extends WP_REST_Posts_Controller { 865 863 'test_form' => false, 866 864 // Only allow uploading font files for this request. 867 865 'mimes' => WP_Font_Utils::get_allowed_font_mime_types(), 866 // Only allow uploading font files to the fonts directory. 867 'subdir' => '/fonts' 868 868 ); 869 869 870 870 // Bypasses is_uploaded_file() when running unit tests. … … class WP_REST_Font_Faces_Controller extends WP_REST_Posts_Controller { 874 874 875 875 $uploaded_file = wp_handle_upload( $file, $overrides ); 876 876 877 remove_filter( 'upload_dir', '_wp_filter_font_directory' );878 877 remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); 879 878 880 879 return $uploaded_file; -
tests/phpunit/tests/fonts/font-library/wpFontsDir.php
diff --git tests/phpunit/tests/fonts/font-library/wpFontsDir.php tests/phpunit/tests/fonts/font-library/wpFontsDir.php index 22208ca7b2..005f42a7f7 100644
class Tests_Fonts_WpFontDir extends WP_UnitTestCase { 117 117 * This emulates the approach a plugin developer may take to 118 118 * add the filter when extending the font library functionality. 119 119 */ 120 add_filter( 'upload_dir', '_wp_filter_font_directory' );121 122 120 add_filter( 123 121 'upload_dir', 124 122 function ( $upload_dir ) {