diff --git a/src/wp-includes/class-wp-theme-json-resolver.php b/src/wp-includes/class-wp-theme-json-resolver.php index 0bdf4a23db119..760a8ce80a4ef 100644 --- a/src/wp-includes/class-wp-theme-json-resolver.php +++ b/src/wp-includes/class-wp-theme-json-resolver.php @@ -172,8 +172,18 @@ public static function get_core_data() { * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) ); - static::$core = $theme_json->get_theme_json(); + $theme_json = apply_filters( 'wp_theme_json_data_default', new WP_Theme_JSON_Data( $config, 'default' ) ); + + /* + * Backward compatibility for extenders returning a WP_Theme_JSON_Data + * compatible class that is not a WP_Theme_JSON_Data object. + */ + if ( $theme_json instanceof WP_Theme_JSON_Data ) { + static::$core = $theme_json->get_theme_json(); + } else { + $config = $theme_json->get_data(); + static::$core = new WP_Theme_JSON( $config, 'default' ); + } return static::$core; } @@ -253,8 +263,18 @@ public static function get_theme_data( $deprecated = array(), $options = array() * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); - static::$theme = $theme_json->get_theme_json(); + $theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) ); + + /* + * Backward compatibility for extenders returning a WP_Theme_JSON_Data + * compatible class that is not a WP_Theme_JSON_Data object. + */ + if ( $theme_json instanceof WP_Theme_JSON_Data ) { + static::$theme = $theme_json->get_theme_json(); + } else { + $config = $theme_json->get_data(); + static::$theme = new WP_Theme_JSON( $config ); + } if ( $wp_theme->parent() ) { // Get parent theme.json. @@ -384,8 +404,19 @@ public static function get_block_data() { * * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ - $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) ); - static::$blocks = $theme_json->get_theme_json(); + $theme_json = apply_filters( 'wp_theme_json_data_blocks', new WP_Theme_JSON_Data( $config, 'blocks' ) ); + + /* + * Backward compatibility for extenders returning a WP_Theme_JSON_Data + * compatible class that is not a WP_Theme_JSON_Data object. + */ + if ( $theme_json instanceof WP_Theme_JSON_Data ) { + static::$blocks = $theme_json->get_theme_json(); + } else { + $config = $theme_json->get_data(); + static::$blocks = new WP_Theme_JSON( $config, 'blocks' ); + } + return static::$blocks; } @@ -519,7 +550,17 @@ public static function get_user_data() { * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data. */ $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); - return $theme_json->get_theme_json(); + + /* + * Backward compatibility for extenders returning a WP_Theme_JSON_Data + * compatible class that is not a WP_Theme_JSON_Data object. + */ + if ( $theme_json instanceof WP_Theme_JSON_Data ) { + return $theme_json->get_theme_json(); + } else { + $config = $theme_json->get_data(); + return new WP_Theme_JSON( $config, 'custom' ); + } } /* @@ -537,8 +578,18 @@ 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( $config, 'custom' ) ); - static::$user = $theme_json->get_theme_json(); + $theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data( $config, 'custom' ) ); + + /* + * Backward compatibility for extenders returning a WP_Theme_JSON_Data + * compatible class that is not a WP_Theme_JSON_Data object. + */ + if ( $theme_json instanceof WP_Theme_JSON_Data ) { + static::$user = $theme_json->get_theme_json(); + } else { + $config = $theme_json->get_data(); + static::$user = new WP_Theme_JSON( $config, 'custom' ); + } return static::$user; }