-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Webfonts: register and enqueue fonts by font-family #39559
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
130fb24
Group registered webfonts by font family
zaguiini 7ad1a8e
Add registered font-family groups to theme.json
zaguiini f061bdf
Separate between registering and enqueueing webfonts
zaguiini 000c8ec
Add wp_enqueue_webfont method
zaguiini f1971d4
Fix wp_register_webfont description
zaguiini 009d2b2
Do not duplicate font families if registering from both theme.json an…
zaguiini 826a94b
Rename font to webfont where appropriate
jeyip bbb8197
Add tests
zaguiini e1ea79f
Fix linter offenses
zaguiini bf7b349
Fire gutenberg_register_webfonts_from_theme_json on init
zaguiini 340df68
Move webfonts logic from wordpress-6.0 to experimental
zaguiini 9fe1f80
Update return types and comment for consistency and matching.
hellofromtonya 6fba7fb
Use trigger_log instead of error_log().
hellofromtonya 8392827
Fix tests with _doing_it_wrong.
hellofromtonya 6d66272
Add `get_webfonts_by_provider()` method to handle regrouping.
hellofromtonya 90cc444
Updates from code review.
hellofromtonya cc63012
Restore loading lib/compat/wordpress-6.0/class-wp-theme-json-gutenber…
hellofromtonya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Move webfonts logic from wordpress-6.0 to experimental
The API, although looking really good, is not ready for Core. So we must move it from wordpress-6.0 to experimental, and only add it there when it's ready to enter WordPress. Relocate files to /lib/experimental. Per the Gutenberg PHP > File structure documentation https://github.com/WordPress/gutenberg/tree/trunk/lib#file-structure.
- Loading branch information
commit 340df68716ad3a7c567c47b11a3c21e31c5de913
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
| /** | ||
| * WP_Theme_JSON_Resolver_6_0 class | ||
| * | ||
| * @package gutenberg | ||
| */ | ||
|
|
||
| /** | ||
| * Class that abstracts the processing of the different data sources | ||
| * for site-level config and offers an API to work with them. | ||
| * | ||
| * This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes). | ||
| * This is a low-level API that may need to do breaking changes. Please, | ||
| * use get_global_settings, get_global_styles, and get_global_stylesheet instead. | ||
| * | ||
| * @access private | ||
| */ | ||
| class WP_Theme_JSON_Resolver_6_0 extends WP_Theme_JSON_Resolver_5_9 { | ||
| /** | ||
| * Given a theme.json structure modifies it in place | ||
| * to update certain values by its translated strings | ||
| * according to the language set by the user. | ||
| * | ||
| * @param array $theme_json The theme.json to translate. | ||
| * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. | ||
| * Default 'default'. | ||
| * @return array Returns the modified $theme_json_structure. | ||
| */ | ||
| protected static function translate( $theme_json, $domain = 'default' ) { | ||
| if ( null === static::$i18n_schema ) { | ||
| $i18n_schema = wp_json_file_decode( __DIR__ . '/theme-i18n.json' ); | ||
| static::$i18n_schema = null === $i18n_schema ? array() : $i18n_schema; | ||
| } | ||
|
|
||
| return wp_translate_settings_using_i18n_schema( static::$i18n_schema, $theme_json, $domain ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the style variations defined by the theme. | ||
| * | ||
| * @return array | ||
| */ | ||
| public static function get_style_variations() { | ||
| $variations = array(); | ||
| $base_directory = get_stylesheet_directory() . '/styles'; | ||
| if ( is_dir( $base_directory ) ) { | ||
| $nested_files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $base_directory ) ); | ||
| $nested_html_files = iterator_to_array( new RegexIterator( $nested_files, '/^.+\.json$/i', RecursiveRegexIterator::GET_MATCH ) ); | ||
| ksort( $nested_html_files ); | ||
| foreach ( $nested_html_files as $path => $file ) { | ||
| $decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) ); | ||
| if ( is_array( $decoded_file ) ) { | ||
| $translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) ); | ||
| $variation = ( new WP_Theme_JSON_Gutenberg( $translated ) )->get_raw_data(); | ||
| if ( empty( $variation['title'] ) ) { | ||
| $variation['title'] = basename( $path, '.json' ); | ||
| } | ||
| $variations[] = $variation; | ||
| } | ||
| } | ||
| } | ||
| return $variations; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file no longer seems to be loaded at all? I'd like to modify
get_theme_databut I'm not sure how now...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry @scruffian, what do you mean? It is listed in
load.php: https://github.com/WordPress/gutenberg/blob/trunk/lib/load.php#L111.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, looks like I was stuck in a bad merge state...