Changeset 57879 for branches/6.5/src/wp-includes/fonts.php
- Timestamp:
- 03/26/2024 09:22:48 AM (13 months ago)
- Location:
- branches/6.5
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/6.5
-
branches/6.5/src/wp-includes/fonts.php
r57875 r57879 93 93 94 94 /** 95 * Retrieves font uploads directory information. 96 * 97 * Same as wp_font_dir() but "light weight" as it doesn't attempt to create the font uploads directory. 98 * Intended for use in themes, when only 'basedir' and 'baseurl' are needed, generally in all cases 99 * when not uploading files. 100 * 101 * @since 6.5.0 102 * 103 * @see wp_font_dir() 104 * 105 * @return array See wp_font_dir() for description. 106 */ 107 function wp_get_font_dir() { 108 return wp_font_dir( false ); 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 $font_dir = 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', $font_dir ); 135 203 } 136 204
Note: See TracChangeset
for help on using the changeset viewer.