-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Font Library #5285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font Library #5285
Changes from 1 commit
9a00814
6f9aefc
d78d99b
1d74144
42eeb48
9e06a93
b323b67
715eea9
e54426a
1078767
699f45b
a6dca33
9ba9187
5084180
46a1e9f
7e666e6
e6cce43
673c042
72bbec5
1d8de84
d769cc5
c4a31d2
57f05a1
8933cb8
9aeb0ba
1725825
d4bce59
89e888f
ab70608
739edeb
534264e
c2d38d6
2a715cd
6bf7be3
bbb09e9
654dd1d
635d870
8714206
2e08b53
8c5ddec
ae15e18
04fe719
839ff70
5116443
d89e201
e4b2a85
8e3e711
947e2cb
88ec9b7
3e63080
e218ec8
02d6767
641e9f3
5178b1e
4612703
f69e6e5
17c9fd3
3021090
db11c1f
31af894
21e3d33
9aa43bf
f38bb59
b005321
2b29de4
aaf3741
d6534cc
3b01b46
f16ead0
30369c6
e1f0b58
aec6c93
b34fe52
e948c1b
0926426
11b26db
feb1199
a776cee
909da30
fd706d1
7081941
b49da9a
2d369aa
86dab9e
b167d7f
1c23f09
4f7fd91
14ca3bd
8d9f496
1243b31
c5c6ec4
f398761
d85e545
07d01ff
ec52113
3967726
a19ac36
05d3ff7
963d226
e28134f
b2a96fc
640159e
d44da25
603ee9e
7382406
d9ffea9
9edfb39
c4de43f
9deeb4a
6c9e856
89cd000
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
porting WordPress/gutenberg#54844 Co-authored-by: Jason Crist <[email protected]>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,18 +17,27 @@ | |
| class WP_Font_Library { | ||
|
|
||
| /** | ||
| * Fonts mime types allowed for each file type. | ||
| * Each file type can have multiple mime types depending on the PHP version. | ||
| * Currently wp_check_filetype_and_ext() only allows one mime type per file extension. | ||
| * Provide the expected mime-type value for font files per-PHP release. Due to differences in the values returned these values differ between PHP versions. | ||
| * | ||
| * This is necessary until a collection of valid mime-types per-file extension can be provided to 'upload_mimes' filter. | ||
| * | ||
| * @since 6.4.0 | ||
| * | ||
| * @param array $php_version_id The version of PHP to provide mime types for. The default is the current PHP version. | ||
| * | ||
| * @return Array A collection of mime types keyed by file extension. | ||
| */ | ||
| const PHP_7_TTF_MIME_TYPE = PHP_VERSION_ID >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf'; | ||
| public static function get_expected_font_mime_types_per_php_version( $php_version_id = PHP_VERSION_ID ) { | ||
|
||
|
|
||
| $php_7_ttf_mime_type = $php_version_id >= 70300 ? 'application/font-sfnt' : 'application/x-font-ttf'; | ||
matiasbenedetto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const ALLOWED_FONT_MIME_TYPES = array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => PHP_VERSION_ID >= 70400 ? 'font/sfnt' : self::PHP_7_TTF_MIME_TYPE, | ||
| 'woff' => PHP_VERSION_ID >= 80100 ? 'font/woff' : 'application/font-woff', | ||
| 'woff2' => PHP_VERSION_ID >= 80100 ? 'font/woff2' : 'application/font-woff2', | ||
| ); | ||
| return array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => $php_version_id >= 70400 ? 'font/sfnt' : $php_7_ttf_mime_type, | ||
| 'woff' => $php_version_id >= 80100 ? 'font/woff' : 'application/font-woff', | ||
| 'woff2' => $php_version_id >= 80100 ? 'font/woff2' : 'application/font-woff2', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Font collections. | ||
|
|
@@ -131,6 +140,6 @@ public static function set_upload_dir( $defaults ) { | |
| * @return array Modified upload directory. | ||
| */ | ||
| public static function set_allowed_mime_types( $mime_types ) { | ||
| return array_merge( $mime_types, self::ALLOWED_FONT_MIME_TYPES ); | ||
| return array_merge( $mime_types, self::get_expected_font_mime_types_per_php_version() ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
| /** | ||
| * Test WP_Font_Family_Utils::get_expected_font_mime_types_per_php_version(). | ||
| * | ||
| * @package WordPress | ||
| * @subpackage Font Library | ||
| * | ||
| * @group fonts | ||
| * @group font-library | ||
| * | ||
| * @covers WP_Font_Family_Utils::get_expected_font_mime_types_per_php_version | ||
| */ | ||
| class Tests_Fonts_WpFontsFamilyUtils_GetMimeTypes extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * | ||
matiasbenedetto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @dataProvider data_should_supply_correct_mime_type_for_php_version | ||
| * | ||
| * @param array $php_version_id PHP_VERSION_ID value. | ||
| * @param array $expected Expected mime types. | ||
| */ | ||
| public function test_should_supply_correct_mime_type_for_php_version( $php_version_id, $expected ) { | ||
| $mimes = WP_Font_Library::get_expected_font_mime_types_per_php_version( $php_version_id ); | ||
| $this->assertEquals( $mimes, $expected ); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider. | ||
| * | ||
| * @return array[] | ||
| */ | ||
| public function data_should_supply_correct_mime_type_for_php_version() { | ||
| return array( | ||
| 'version 7.2' => array( | ||
| 'php_version_id' => 70200, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'application/x-font-ttf', | ||
| 'woff' => 'application/font-woff', | ||
| 'woff2' => 'application/font-woff2', | ||
| ), | ||
| ), | ||
| 'version 7.3' => array( | ||
| 'php_version_id' => 70300, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'application/font-sfnt', | ||
| 'woff' => 'application/font-woff', | ||
| 'woff2' => 'application/font-woff2', | ||
| ), | ||
| ), | ||
| 'version 7.4' => array( | ||
| 'php_version_id' => 70400, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'font/sfnt', | ||
| 'woff' => 'application/font-woff', | ||
| 'woff2' => 'application/font-woff2', | ||
| ), | ||
| ), | ||
| 'version 8.0' => array( | ||
| 'php_version_id' => 80000, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'font/sfnt', | ||
| 'woff' => 'application/font-woff', | ||
| 'woff2' => 'application/font-woff2', | ||
| ), | ||
| ), | ||
| 'version 8.1' => array( | ||
| 'php_version_id' => 80100, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'font/sfnt', | ||
| 'woff' => 'font/woff', | ||
| 'woff2' => 'font/woff2', | ||
| ), | ||
| ), | ||
| 'version 8.2' => array( | ||
| 'php_version_id' => 80200, | ||
| 'expected' => array( | ||
| 'otf' => 'font/otf', | ||
| 'ttf' => 'font/sfnt', | ||
| 'woff' => 'font/woff', | ||
| 'woff2' => 'font/woff2', | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.