Changeset 57879
- Timestamp:
- 03/26/2024 09:22:48 AM (4 months ago)
- Location:
- branches/6.5
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.5
-
branches/6.5/src/wp-includes/fonts.php
r57875 r57879 93 93 94 94 /** 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 95 112 * Returns an array containing the current fonts upload directory's path and URL. 96 113 * 97 114 * @since 6.5.0 98 115 * 99 * @return array $defaults { 100 * Array of information about the upload directory. 116 * @param bool $create_dir Optional. Whether to check and create the font uploads directory. Default true. 117 * @return array { 118 * Array of information about the font upload directory. 101 119 * 102 120 * @type string $path Base directory and subdirectory or full path to the fonts upload directory. … … 108 126 * } 109 127 */ 110 function wp_get_font_dir() { 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 * Returns the font directory for use by the font library. 144 * 145 * This function is a callback for the {@see 'upload_dir'} filter. It is not 146 * intended to be called directly. Use wp_get_font_dir() instead. 147 * 148 * The function can be used when extending the font library to modify the upload 149 * destination for font files via the upload_dir filter. The recommended way to 150 * do this is: 151 * 152 * ```php 153 * add_filter( 'upload_dir', '_wp_filter_font_directory' ); 154 * // Your code to upload or sideload a font file. 155 * remove_filter( 'upload_dir', '_wp_filter_font_directory' ); 156 * ``` 157 * 158 * @since 6.5.0 159 * @access private 160 * 161 * @param string $font_dir The font directory. 162 * @return string The modified font directory. 163 */ 164 function _wp_filter_font_directory( $font_dir ) { 165 if ( doing_filter( 'font_dir' ) ) { 166 // Avoid an infinite loop. 167 return $font_dir; 168 } 169 111 170 $site_path = ''; 112 171 if ( is_multisite() && ! ( is_main_network() && is_main_site() ) ) { … … 114 173 } 115 174 116 $ defaults= array(175 $ = array( 117 176 'path' => path_join( WP_CONTENT_DIR, 'fonts' ) . $site_path, 118 177 'url' => untrailingslashit( content_url( 'fonts' ) ) . $site_path, … … 130 189 * @since 6.5.0 131 190 * 132 * @param array $defaults The original fonts directory data. 191 * @param array $font_dir { 192 * Array of information about the font upload directory. 193 * 194 * @type string $path Base directory and subdirectory or full path to the fonts upload directory. 195 * @type string $url Base URL and subdirectory or absolute URL to the fonts upload directory. 196 * @type string $subdir Subdirectory 197 * @type string $basedir Path without subdir. 198 * @type string $baseurl URL path without subdir. 199 * @type string|false $error False or error message. 200 * } 133 201 */ 134 return apply_filters( 'font_dir', $ defaults);202 return apply_filters( 'font_dir', $ ); 135 203 } 136 204 -
branches/6.5/src/wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php
r57813 r57879 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 860 /* 861 * Set the upload directory to the fonts directory. 862 * 863 * wp_get_font_dir() contains the 'font_dir' hook, whose callbacks are 864 * likely to call wp_get_upload_dir(). 865 * 866 * To avoid an infinite loop, don't hook wp_get_font_dir() to 'upload_dir'. 867 * Instead, just pass its return value to the 'upload_dir' callback. 868 */ 869 $font_dir = wp_get_font_dir(); 870 $set_upload_dir = function () use ( $font_dir ) { 871 return $font_dir; 872 }; 873 add_filter( 'upload_dir', $set_upload_dir ); 859 // Filter the upload directory to return the fonts directory. 860 add_filter( 'upload_dir', '_wp_filter_font_directory' ); 874 861 875 862 $overrides = array( … … 888 875 $uploaded_file = wp_handle_upload( $file, $overrides ); 889 876 890 remove_filter( 'upload_dir', $set_upload_dir);877 remove_filter( 'upload_dir', ); 891 878 remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); 892 879 -
branches/6.5/tests/phpunit/tests/fonts/font-library/fontLibraryHooks.php
r57539 r57879 74 74 75 75 add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); 76 add_filter( 'upload_dir', ' wp_get_font_dir' );76 add_filter( 'upload_dir', '' ); 77 77 $font_file = wp_upload_bits( 78 78 $font_filename, … … 80 80 file_get_contents( $font_file_path ) 81 81 ); 82 remove_filter( 'upload_dir', ' wp_get_font_dir' );82 remove_filter( 'upload_dir', '' ); 83 83 remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) ); 84 84 -
branches/6.5/tests/phpunit/tests/fonts/font-library/wpFontsDir.php
r57539 r57879 70 70 $this->assertSame( static::$dir_defaults, $font_dir, 'The wp_get_font_dir() method should return the default values.' ); 71 71 } 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 72 112 }
Note: See TracChangeset
for help on using the changeset viewer.