diff --git a/wp-includes/class-wp-theme-json-data.php b/wp-includes/class-wp-theme-json-data.php new file mode 100644 index 0000000000..089e65eddb --- /dev/null +++ b/wp-includes/class-wp-theme-json-data.php @@ -0,0 +1,72 @@ +origin = $origin; + $this->theme_json = new WP_Theme_JSON( $data, $this->origin ); + } + + /** + * Updates the theme.json with the the given data. + * + * @since 6.1.0 + * + * @param array $new_data Array following the theme.json specification. + * + * @return WP_Theme_JSON_Data The own instance with access to the modified data. + */ + public function update_with( $new_data ) { + $this->theme_json->merge( new WP_Theme_JSON( $new_data, $this->origin ) ); + return $this; + } + + /** + * Returns an array containing the underlying data + * following the theme.json specification. + * + * @since 6.1.0 + * + * @return array + */ + public function get_data() { + return $this->theme_json->get_raw_data(); + } + +} diff --git a/wp-includes/class-wp-theme-json-resolver.php b/wp-includes/class-wp-theme-json-resolver.php index 1efb8a4c8a..4acc61a784 100644 --- a/wp-includes/class-wp-theme-json-resolver.php +++ b/wp-includes/class-wp-theme-json-resolver.php @@ -137,6 +137,15 @@ public static function get_core_data() { $config = static::read_json_file( __DIR__ . '/theme.json' ); $config = static::translate( $config ); + /** + * Filters the default data provided by WordPress for global styles & settings. + * + * @since 6.1.0 + * + * @param WP_Theme_JSON_Data Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'theme_json_default', new WP_Theme_JSON_Data( $config, 'default' ) ); + $config = $theme_json->get_data(); static::$core = new WP_Theme_JSON( $config, 'default' ); return static::$core; @@ -172,6 +181,15 @@ public static function get_theme_data( $deprecated = array(), $options = array() if ( null === static::$theme ) { $theme_json_data = static::read_json_file( static::get_file_path_from_theme( 'theme.json' ) ); $theme_json_data = static::translate( $theme_json_data, wp_get_theme()->get( 'TextDomain' ) ); + /** + * Filters the data provided by the theme for global styles & settings. + * + * @since 6.1.0 + * + * @param WP_Theme_JSON_Data Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'theme_json_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); + $theme_json_data = $theme_json->get_data(); static::$theme = new WP_Theme_JSON( $theme_json_data ); if ( wp_get_theme()->parent() ) { @@ -258,6 +276,16 @@ public static function get_block_data() { } } + /** + * Filters the data provided by the blocks for global styles & settings. + * + * @since 6.1.0 + * + * @param WP_Theme_JSON_Data Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data( $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( $config, 'core' ); @@ -382,6 +410,15 @@ 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() ); + /** + * Filters the data provided by the user for global styles & settings. + * + * @since 6.1.0 + * + * @param WP_Theme_JSON_Data Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); + $config = $theme_json->get_data(); return new WP_Theme_JSON( $config, 'custom' ); } @@ -396,6 +433,16 @@ public static function get_user_data() { $config = $decoded_data; } } + + /** + * Filters the data provided by the user for global styles & settings. + * + * @since 6.1.0 + * + * @param WP_Theme_JSON_Data Class to access and update the underlying data. + */ + $theme_json = apply_filters( 'theme_json_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); + $config = $theme_json->get_data(); static::$user = new WP_Theme_JSON( $config, 'custom' ); return static::$user; diff --git a/wp-includes/version.php b/wp-includes/version.php index 8dd22fcd12..721da9b913 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-alpha-54250'; +$wp_version = '6.1-alpha-54251'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. diff --git a/wp-settings.php b/wp-settings.php index 6f0e33bd7e..d80d79bb82 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -172,6 +172,7 @@ require ABSPATH . WPINC . '/theme.php'; require ABSPATH . WPINC . '/class-wp-theme.php'; require ABSPATH . WPINC . '/class-wp-theme-json-schema.php'; +require ABSPATH . WPINC . '/class-wp-theme-json-data.php'; require ABSPATH . WPINC . '/class-wp-theme-json.php'; require ABSPATH . WPINC . '/class-wp-theme-json-resolver.php'; require ABSPATH . WPINC . '/global-styles-and-settings.php';