diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-data.php b/lib/compat/wordpress-6.1/class-wp-theme-json-data-gutenberg.php similarity index 88% rename from lib/compat/wordpress-6.1/class-wp-theme-json-data.php rename to lib/compat/wordpress-6.1/class-wp-theme-json-data-gutenberg.php index d03b2227558ea..9add04bb65b09 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-data.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-data-gutenberg.php @@ -8,7 +8,7 @@ /** * Class to update with a theme.json structure. */ -class WP_Theme_JSON_Data { +class WP_Theme_JSON_Data_Gutenberg { /** * Container of the data to update. @@ -22,7 +22,7 @@ class WP_Theme_JSON_Data { * * @var string */ - private $origin = null; + private $origin = ''; /** * Constructor. @@ -40,11 +40,10 @@ public function __construct( $data = array(), $origin = 'theme' ) { * * @param array $new_data Array following the theme.json specification. * - * @return WP_Theme_JSON_Data the modified data. + * @return WP_Theme_JSON_Data_Gutenberg The own instance with access to the modified data. */ public function update_with( $new_data ) { $this->theme_json->merge( new WP_Theme_JSON_Gutenberg( $new_data, $this->origin ) ); - return $this; } diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php index d210fa16d2310..f05a4b1f75254 100644 --- a/lib/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php @@ -54,10 +54,16 @@ public static function get_core_data() { return static::$core; } - $config = static::read_json_file( __DIR__ . '/theme.json' ); - $config = static::translate( $config ); - $config = apply_filters( 'global_styles_default', new WP_Theme_JSON_Data( $config, 'default' ) ); - static::$core = new WP_Theme_JSON_Gutenberg( $config->get_data(), 'default' ); + $config = static::read_json_file( __DIR__ . '/theme.json' ); + $config = static::translate( $config ); + /** + * Filters the default data provided by WordPress for global styles & settings. + * + * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'global_styles_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) ); + $config = $theme_json->get_data(); + static::$core = new WP_Theme_JSON_Gutenberg( $config, 'default' ); return static::$core; } @@ -81,8 +87,14 @@ public static function get_user_data() { $json_decoding_error = json_last_error(); if ( JSON_ERROR_NONE !== $json_decoding_error ) { trigger_error( 'Error when decoding a theme.json schema for user data. ' . json_last_error_msg() ); - $config = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); - return new WP_Theme_JSON_Gutenberg( $config->get_data(), 'custom' ); + /** + * Filters the data provided by the user for global styles & settings. + * + * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); + $config = $theme_json->get_data(); + return new WP_Theme_JSON_Gutenberg( $config, 'custom' ); } // Very important to verify if the flag isGlobalStylesUserThemeJSON is true. @@ -97,8 +109,14 @@ public static function get_user_data() { } } - $config = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); - static::$user = new WP_Theme_JSON_Gutenberg( $config->get_data(), 'custom' ); + /** + * Filters the data provided by the user for global styles & settings. + * + * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'global_styles_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); + $config = $theme_json->get_data(); + static::$user = new WP_Theme_JSON_Gutenberg( $config, 'custom' ); return static::$user; } diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php index 30b93d85e698e..a3f9538056cb6 100644 --- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php @@ -39,8 +39,14 @@ public static function get_theme_data( $deprecated = array(), $settings = array( $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); $theme_json_data = gutenberg_add_registered_webfonts_to_theme_json( $theme_json_data ); - $theme_json_data = apply_filters( 'global_styles_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); - static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data->get_data() ); + /** + * Filters the data provided by the theme for global styles & settings. + * + * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'global_styles_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) ); + $theme_json_data = $theme_json->get_data(); + static::$theme = new WP_Theme_JSON_Gutenberg( $theme_json_data ); if ( wp_get_theme()->parent() ) { // Get parent theme.json. @@ -130,11 +136,17 @@ public static function get_block_data() { } } - $config = apply_filters( 'global_styles_blocks', new WP_Theme_JSON_Data( $config, 'core' ) ); + /** + * Filters the data provided by the blocks for global styles & settings. + * + * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'global_styles_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'core' ) ); + $config = $theme_json->get_data(); // Core here means it's the lower level part of the styles chain. // It can be a core or a third-party block. - return new WP_Theme_JSON_Gutenberg( $config->get_data(), 'core' ); + return new WP_Theme_JSON_Gutenberg( $config, 'core' ); } /** diff --git a/lib/load.php b/lib/load.php index 81a63b49769b6..1493b5ee79791 100644 --- a/lib/load.php +++ b/lib/load.php @@ -83,7 +83,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.1/block-editor-settings.php'; require __DIR__ . '/compat/wordpress-6.1/persisted-preferences.php'; require __DIR__ . '/compat/wordpress-6.1/get-global-styles-and-settings.php'; -require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-data.php'; +require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-data-gutenberg.php'; require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-6-1.php'; require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php'; require __DIR__ . '/compat/wordpress-6.1/block-template-utils.php';