Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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
zaguiini authored and hellofromtonya committed Apr 4, 2022
commit 340df68716ad3a7c567c47b11a3c21e31c5de913
64 changes: 64 additions & 0 deletions lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,7 @@
*
* @access private
*/
class WP_Theme_JSON_Resolver_Gutenberg 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;
}

class WP_Theme_JSON_Resolver_Gutenberg extends WP_Theme_JSON_Resolver_6_0 {
Copy link
Contributor

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_data but I'm not sure how now...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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...

/**
* Returns the theme's data.
*
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,17 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-patterns-controller.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-rest-block-pattern-categories-controller.php';
require __DIR__ . '/compat/wordpress-6.0/functions.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php';
require __DIR__ . '/compat/wordpress-6.0/rest-api.php';
require __DIR__ . '/compat/wordpress-6.0/block-patterns.php';
require __DIR__ . '/compat/wordpress-6.0/block-template.php';
require __DIR__ . '/compat/wordpress-6.0/register-webfonts-from-theme-json.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-theme-json-resolver-gutenberg.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-webfonts.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-webfonts-provider.php';
require __DIR__ . '/compat/wordpress-6.0/class-wp-webfonts-provider-local.php';
require __DIR__ . '/compat/wordpress-6.0/webfonts.php';
require __DIR__ . '/compat/wordpress-6.0/edit-form-blocks.php';
require __DIR__ . '/experimental/register-webfonts-from-theme-json.php';
require __DIR__ . '/experimental/class-wp-theme-json-resolver-gutenberg.php';
require __DIR__ . '/experimental/class-wp-webfonts.php';
require __DIR__ . '/experimental/class-wp-webfonts-provider.php';
require __DIR__ . '/experimental/class-wp-webfonts-provider-local.php';
require __DIR__ . '/experimental/webfonts.php';
require __DIR__ . '/experimental/blocks.php';

require __DIR__ . '/blocks.php';
Expand Down