From 97fe69da4055eea9ea6ec3b020e684fda2aad8af Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Thu, 20 Jun 2024 16:01:53 +0100 Subject: [PATCH 1/2] check for origin --- lib/class-wp-theme-json-data-gutenberg.php | 11 ++++++ ...class-wp-theme-json-resolver-gutenberg.php | 35 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/class-wp-theme-json-data-gutenberg.php b/lib/class-wp-theme-json-data-gutenberg.php index 2c7eec9d5dbf4a..edc3308eb27303 100644 --- a/lib/class-wp-theme-json-data-gutenberg.php +++ b/lib/class-wp-theme-json-data-gutenberg.php @@ -79,4 +79,15 @@ public function get_data() { public function get_theme_json() { return $this->theme_json; } + + /** + * Return the origin of the data. + * + * @since N.E.X.T // need to update the version + * + * @return string + */ + public function get_origin() { + return $this->origin; + } } diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 6a8d2558d1c85a..66611618900a09 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -173,6 +173,13 @@ public static function get_core_data() { * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) ); + if( 'default' === $theme_json->get_origin() ) { + _doing_it_wrong( + __METHOD__, + __( 'Origin should be `default` here.', 'gutenberg' ), + 'N.E.X.T' // Need to update this version. + ); + } static::$core = $theme_json->get_theme_json(); return static::$core; @@ -263,6 +270,13 @@ public static function get_theme_data( $deprecated = array(), $options = array() * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) ); + if( 'theme' === $theme_json->get_origin() ) { + _doing_it_wrong( + __METHOD__, + __( 'Origin should be `theme` here.', 'gutenberg' ), + 'N.E.X.T' // Need to update this version. + ); + } static::$theme = $theme_json->get_theme_json(); if ( $wp_theme->parent() ) { @@ -398,6 +412,13 @@ public static function get_block_data() { * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) ); + if( 'blocks' === $theme_json->get_origin() ) { + _doing_it_wrong( + __METHOD__, + __( 'Origin should be `blocks` here.', 'gutenberg' ), + 'N.E.X.T' // Need to update this version. + ); + } static::$blocks = $theme_json->get_theme_json(); return static::$blocks; @@ -531,6 +552,13 @@ public static function get_user_data() { * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); + if( 'custom' === $theme_json->get_origin() ) { + _doing_it_wrong( + __METHOD__, + __( 'Origin should be `custom` here.', 'gutenberg' ), + 'N.E.X.T' // Need to update this version. + ); + } return $theme_json->get_theme_json(); } @@ -553,6 +581,13 @@ public static function get_user_data() { /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); + if( 'custom' === $theme_json->get_origin() ) { + _doing_it_wrong( + __METHOD__, + __( 'Origin should be `custom` here.', 'gutenberg' ), + 'N.E.X.T' // Need to update this version. + ); + } static::$user = $theme_json->get_theme_json(); return static::$user; From f4851d1df2be1976c1cf3c8df37c9a12056a1ee3 Mon Sep 17 00:00:00 2001 From: Karthik Thayyil Date: Thu, 20 Jun 2024 16:24:59 +0100 Subject: [PATCH 2/2] fix linting issue --- lib/class-wp-theme-json-resolver-gutenberg.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 66611618900a09..9ca37effbc0c23 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -172,8 +172,8 @@ public static function get_core_data() { * * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) ); - if( 'default' === $theme_json->get_origin() ) { + $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data_Gutenberg( $config, 'default' ) ); + if ( 'default' === $theme_json->get_origin() ) { _doing_it_wrong( __METHOD__, __( 'Origin should be `default` here.', 'gutenberg' ), @@ -269,8 +269,8 @@ public static function get_theme_data( $deprecated = array(), $options = array() * * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) ); - if( 'theme' === $theme_json->get_origin() ) { + $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data_Gutenberg( $theme_json_data, 'theme' ) ); + if ( 'theme' === $theme_json->get_origin() ) { _doing_it_wrong( __METHOD__, __( 'Origin should be `theme` here.', 'gutenberg' ), @@ -411,8 +411,8 @@ public static function get_block_data() { * * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) ); - if( 'blocks' === $theme_json->get_origin() ) { + $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) ); + if ( 'blocks' === $theme_json->get_origin() ) { _doing_it_wrong( __METHOD__, __( 'Origin should be `blocks` here.', 'gutenberg' ), @@ -552,7 +552,7 @@ public static function get_user_data() { * @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); - if( 'custom' === $theme_json->get_origin() ) { + if ( 'custom' === $theme_json->get_origin() ) { _doing_it_wrong( __METHOD__, __( 'Origin should be `custom` here.', 'gutenberg' ), @@ -580,8 +580,8 @@ public static function get_user_data() { gutenberg_register_block_style_variations_from_theme_json_data( $variations ); /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */ - $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); - if( 'custom' === $theme_json->get_origin() ) { + $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) ); + if ( 'custom' === $theme_json->get_origin() ) { _doing_it_wrong( __METHOD__, __( 'Origin should be `custom` here.', 'gutenberg' ),