@@ -172,8 +172,18 @@ public static function get_core_data() {
172172 *
173173 * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
174174 */
175- $ theme_json = apply_filters ( 'wp_theme_json_data_default ' , new WP_Theme_JSON_Data ( $ config , 'default ' ) );
176- static ::$ core = $ theme_json ->get_theme_json ();
175+ $ theme_json = apply_filters ( 'wp_theme_json_data_default ' , new WP_Theme_JSON_Data ( $ config , 'default ' ) );
176+
177+ /*
178+ * Backward compatibility for extenders returning a WP_Theme_JSON_Data
179+ * compatible class that is not a WP_Theme_JSON_Data object.
180+ */
181+ if ( $ theme_json instanceof WP_Theme_JSON_Data ) {
182+ static ::$ core = $ theme_json ->get_theme_json ();
183+ } else {
184+ $ config = $ theme_json ->get_data ();
185+ static ::$ core = new WP_Theme_JSON ( $ config , 'default ' );
186+ }
177187
178188 return static ::$ core ;
179189 }
@@ -263,8 +273,18 @@ public static function get_theme_data( $deprecated = array(), $options = array()
263273 *
264274 * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
265275 */
266- $ theme_json = apply_filters ( 'wp_theme_json_data_theme ' , new WP_Theme_JSON_Data ( $ theme_json_data , 'theme ' ) );
267- static ::$ theme = $ theme_json ->get_theme_json ();
276+ $ theme_json = apply_filters ( 'wp_theme_json_data_theme ' , new WP_Theme_JSON_Data ( $ theme_json_data , 'theme ' ) );
277+
278+ /*
279+ * Backward compatibility for extenders returning a WP_Theme_JSON_Data
280+ * compatible class that is not a WP_Theme_JSON_Data object.
281+ */
282+ if ( $ theme_json instanceof WP_Theme_JSON_Data ) {
283+ static ::$ theme = $ theme_json ->get_theme_json ();
284+ } else {
285+ $ config = $ theme_json ->get_data ();
286+ static ::$ theme = new WP_Theme_JSON ( $ config );
287+ }
268288
269289 if ( $ wp_theme ->parent () ) {
270290 // Get parent theme.json.
@@ -386,8 +406,19 @@ public static function get_block_data() {
386406 *
387407 * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
388408 */
389- $ theme_json = apply_filters ( 'wp_theme_json_data_blocks ' , new WP_Theme_JSON_Data ( $ config , 'blocks ' ) );
390- static ::$ blocks = $ theme_json ->get_theme_json ();
409+ $ theme_json = apply_filters ( 'wp_theme_json_data_blocks ' , new WP_Theme_JSON_Data ( $ config , 'blocks ' ) );
410+
411+ /*
412+ * Backward compatibility for extenders returning a WP_Theme_JSON_Data
413+ * compatible class that is not a WP_Theme_JSON_Data object.
414+ */
415+ if ( $ theme_json instanceof WP_Theme_JSON_Data ) {
416+ static ::$ blocks = $ theme_json ->get_theme_json ();
417+ } else {
418+ $ config = $ theme_json ->get_data ();
419+ static ::$ blocks = new WP_Theme_JSON ( $ config , 'blocks ' );
420+ }
421+
391422 return static ::$ blocks ;
392423 }
393424
@@ -523,7 +554,17 @@ public static function get_user_data() {
523554 * @param WP_Theme_JSON_Data $theme_json Class to access and update the underlying data.
524555 */
525556 $ theme_json = apply_filters ( 'wp_theme_json_data_user ' , new WP_Theme_JSON_Data ( $ config , 'custom ' ) );
526- return $ theme_json ->get_theme_json ();
557+
558+ /*
559+ * Backward compatibility for extenders returning a WP_Theme_JSON_Data
560+ * compatible class that is not a WP_Theme_JSON_Data object.
561+ */
562+ if ( $ theme_json instanceof WP_Theme_JSON_Data ) {
563+ return $ theme_json ->get_theme_json ();
564+ } else {
565+ $ config = $ theme_json ->get_data ();
566+ return new WP_Theme_JSON ( $ config , 'custom ' );
567+ }
527568 }
528569
529570 /*
@@ -545,8 +586,18 @@ public static function get_user_data() {
545586 }
546587
547588 /** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
548- $ theme_json = apply_filters ( 'wp_theme_json_data_user ' , new WP_Theme_JSON_Data ( $ config , 'custom ' ) );
549- static ::$ user = $ theme_json ->get_theme_json ();
589+ $ theme_json = apply_filters ( 'wp_theme_json_data_user ' , new WP_Theme_JSON_Data ( $ config , 'custom ' ) );
590+
591+ /*
592+ * Backward compatibility for extenders returning a WP_Theme_JSON_Data
593+ * compatible class that is not a WP_Theme_JSON_Data object.
594+ */
595+ if ( $ theme_json instanceof WP_Theme_JSON_Data ) {
596+ static ::$ user = $ theme_json ->get_theme_json ();
597+ } else {
598+ $ config = $ theme_json ->get_data ();
599+ static ::$ user = new WP_Theme_JSON ( $ config , 'custom ' );
600+ }
550601
551602 return static ::$ user ;
552603 }
0 commit comments