Skip to content
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

Check for origin and issue warning if origin is incorrect. #62708

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions lib/class-wp-theme-json-data-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
43 changes: 39 additions & 4 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,14 @@ 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' ) );
$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;
Expand Down Expand Up @@ -262,7 +269,14 @@ 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' ) );
$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() ) {
Expand Down Expand Up @@ -397,7 +411,14 @@ 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' ) );
$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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -552,7 +580,14 @@ 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' ) );
$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;
Expand Down
Loading