From ddd383954b096791fd4309928cd8067a74f6385b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Thu, 20 Oct 2022 16:29:01 +0200
Subject: [PATCH 01/16] Add wp_theme_has_theme_json
---
.../get-global-styles-and-settings.php | 33 +++++++++++++++++++
lib/load.php | 1 +
2 files changed, 34 insertions(+)
create mode 100644 lib/compat/wordpress-6.2/get-global-styles-and-settings.php
diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
new file mode 100644
index 00000000000000..1d0f70984aaaec
--- /dev/null
+++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
@@ -0,0 +1,33 @@
+
Date: Thu, 20 Oct 2022 16:34:05 +0200
Subject: [PATCH 02/16] Use the public API in all places
---
lib/block-supports/layout.php | 4 ++--
lib/client-assets.php | 2 +-
lib/compat/wordpress-6.0/block-patterns.php | 2 +-
lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php | 2 +-
lib/compat/wordpress-6.0/get-global-styles-and-settings.php | 2 +-
lib/compat/wordpress-6.1/block-editor-settings.php | 2 +-
lib/compat/wordpress-6.1/get-global-styles-and-settings.php | 2 +-
lib/compat/wordpress-6.1/template-parts-screen.php | 2 +-
lib/experimental/block-editor-settings-mobile.php | 2 +-
lib/experimental/class-wp-theme-json-resolver-gutenberg.php | 2 +-
10 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php
index 0734936b2610ba..a50e1fb8837178 100644
--- a/lib/block-supports/layout.php
+++ b/lib/block-supports/layout.php
@@ -477,7 +477,7 @@ function gutenberg_restore_group_inner_container( $block_content, $block ) {
preg_quote( $tag_name, '/' )
);
if (
- WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ||
+ wp_theme_has_theme_json() ||
1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] )
) {
@@ -542,7 +542,7 @@ function gutenberg_restore_image_outer_container( $block_content, $block ) {
)/iUx";
if (
- WP_Theme_JSON_Resolver::theme_has_support() ||
+ wp_theme_has_theme_json() ||
0 === preg_match( $image_with_align, $block_content, $matches )
) {
return $block_content;
diff --git a/lib/client-assets.php b/lib/client-assets.php
index f1b94c0d46abf5..ea199750fa10b3 100644
--- a/lib/client-assets.php
+++ b/lib/client-assets.php
@@ -318,7 +318,7 @@ function gutenberg_register_packages_styles( $styles ) {
);
// Only load the default layout and margin styles for themes without theme.json file.
- if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
+ if ( ! wp_theme_has_theme_json() ) {
$wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
}
diff --git a/lib/compat/wordpress-6.0/block-patterns.php b/lib/compat/wordpress-6.0/block-patterns.php
index 6ba5a150355308..c42ec73152219a 100644
--- a/lib/compat/wordpress-6.0/block-patterns.php
+++ b/lib/compat/wordpress-6.0/block-patterns.php
@@ -15,7 +15,7 @@ function _register_remote_theme_patterns() {
return;
}
- if ( ! WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
+ if ( ! wp_theme_has_theme_json() ) {
return;
}
diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
index b85e8e335037af..45779d395e6291 100644
--- a/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
+++ b/lib/compat/wordpress-6.0/class-wp-theme-json-resolver-6-0.php
@@ -86,7 +86,7 @@ public static function get_theme_data( $deprecated = array(), $options = array()
* and merge the static::$theme upon that.
*/
$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_default_block_editor_settings() );
- if ( ! static::theme_has_support() ) {
+ if ( ! wp_theme_has_theme_json() ) {
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
$theme_support_data['settings']['color'] = array();
}
diff --git a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php
index 1dfafe9f7631d3..9ed3e891182cb5 100644
--- a/lib/compat/wordpress-6.0/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.0/get-global-styles-and-settings.php
@@ -85,7 +85,7 @@ function gutenberg_get_global_styles_svg_filters() {
}
}
- $supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
+ $supports_theme_json = wp_theme_has_theme_json();
$origins = array( 'default', 'theme', 'custom' );
if ( ! $supports_theme_json ) {
diff --git a/lib/compat/wordpress-6.1/block-editor-settings.php b/lib/compat/wordpress-6.1/block-editor-settings.php
index 3181329475df4f..cafe91e787dc68 100644
--- a/lib/compat/wordpress-6.1/block-editor-settings.php
+++ b/lib/compat/wordpress-6.1/block-editor-settings.php
@@ -68,7 +68,7 @@ function gutenberg_get_block_editor_settings( $settings ) {
}
}
- if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
+ if ( wp_theme_has_theme_json() ) {
$block_classes = array(
'css' => 'styles',
'__unstableType' => 'theme',
diff --git a/lib/compat/wordpress-6.1/get-global-styles-and-settings.php b/lib/compat/wordpress-6.1/get-global-styles-and-settings.php
index 1837aa04dbb20d..35c540ce1c57a6 100644
--- a/lib/compat/wordpress-6.1/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.1/get-global-styles-and-settings.php
@@ -83,7 +83,7 @@ function gutenberg_get_global_stylesheet( $types = array() ) {
}
}
$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data();
- $supports_theme_json = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
+ $supports_theme_json = wp_theme_has_theme_json();
if ( empty( $types ) && ! $supports_theme_json ) {
$types = array( 'variables', 'presets', 'base-layout-styles' );
} elseif ( empty( $types ) ) {
diff --git a/lib/compat/wordpress-6.1/template-parts-screen.php b/lib/compat/wordpress-6.1/template-parts-screen.php
index d9b785100b8d99..c8b5958bedcd4d 100644
--- a/lib/compat/wordpress-6.1/template-parts-screen.php
+++ b/lib/compat/wordpress-6.1/template-parts-screen.php
@@ -116,7 +116,7 @@ static function( $classes ) {
'styles' => get_block_editor_theme_styles(),
'defaultTemplateTypes' => $indexed_template_types,
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(),
- 'supportsLayout' => WP_Theme_JSON_Resolver::theme_has_support(),
+ 'supportsLayout' => wp_theme_has_theme_json(),
'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
'__unstableHomeTemplate' => gutenberg_resolve_home_template(),
);
diff --git a/lib/experimental/block-editor-settings-mobile.php b/lib/experimental/block-editor-settings-mobile.php
index b0da17e9296671..91e3694c199f83 100644
--- a/lib/experimental/block-editor-settings-mobile.php
+++ b/lib/experimental/block-editor-settings-mobile.php
@@ -22,7 +22,7 @@ function gutenberg_get_block_editor_settings_mobile( $settings ) {
isset( $_GET['context'] ) &&
'mobile' === $_GET['context']
) {
- if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
+ if ( wp_theme_has_theme_json() ) {
$settings['__experimentalStyles'] = gutenberg_get_global_styles();
}
diff --git a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php
index bab54c9410ac8e..43ac5b3bc9ec45 100644
--- a/lib/experimental/class-wp-theme-json-resolver-gutenberg.php
+++ b/lib/experimental/class-wp-theme-json-resolver-gutenberg.php
@@ -73,7 +73,7 @@ public static function get_theme_data( $deprecated = array(), $settings = array(
* and merge the static::$theme upon that.
*/
$theme_support_data = WP_Theme_JSON_Gutenberg::get_from_editor_settings( get_default_block_editor_settings() );
- if ( ! static::theme_has_support() ) {
+ if ( ! wp_theme_has_theme_json() ) {
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
$theme_support_data['settings']['color'] = array();
}
From e69459221fc1eb636d2651549c04c7a063fe52ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:08:53 +0200
Subject: [PATCH 03/16] Add wp_theme_clean_theme_json_cached_data
---
lib/compat/wordpress-6.2/default-filters.php | 4 ++++
.../get-global-styles-and-settings.php | 20 +++++++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 lib/compat/wordpress-6.2/default-filters.php
diff --git a/lib/compat/wordpress-6.2/default-filters.php b/lib/compat/wordpress-6.2/default-filters.php
new file mode 100644
index 00000000000000..c72ad1e6490df0
--- /dev/null
+++ b/lib/compat/wordpress-6.2/default-filters.php
@@ -0,0 +1,4 @@
+
Date: Thu, 20 Oct 2022 17:09:39 +0200
Subject: [PATCH 04/16] Port and add unit tests
---
phpunit/data/themedir1/default/style.css | 13 +++++++
phpunit/wp-theme-json.php | 43 ++++++++++++++++++++++++
2 files changed, 56 insertions(+)
create mode 100644 phpunit/data/themedir1/default/style.css
create mode 100644 phpunit/wp-theme-json.php
diff --git a/phpunit/data/themedir1/default/style.css b/phpunit/data/themedir1/default/style.css
new file mode 100644
index 00000000000000..e73392422dd641
--- /dev/null
+++ b/phpunit/data/themedir1/default/style.css
@@ -0,0 +1,13 @@
+/*
+Theme Name: WordPress Default
+Theme URI: http://wordpress.org/
+Description: The default WordPress theme based on the famous Kubrick.
+Version: 1.6
+Author: Michael Heilemann
+Author URI: http://binarybonsai.com/
+
+This is just a stub to test the loading of the above metadata.
+*/
+
+
+
diff --git a/phpunit/wp-theme-json.php b/phpunit/wp-theme-json.php
new file mode 100644
index 00000000000000..e4e0b0ddd2c801
--- /dev/null
+++ b/phpunit/wp-theme-json.php
@@ -0,0 +1,43 @@
+assertSame( true, false );
+ }
+
+ public function test_theme_and_parent_do_not_have_theme_json() {
+ $this->assertSame( true, false );
+ }
+
+ public function test_theme_has_not_theme_json_but_parent_has() {
+ $this->assertSame( true, false );
+ }
+
+ /**
+ * Test that switching themes recalculates theme support.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ *
+ */
+ public function test_switching_themes_recalculates_support() {
+ // The "default" theme doesn't have theme.json support.
+ switch_theme( 'default' );
+ $default = wp_theme_has_theme_json();
+
+ // Switch to a theme that does have support.
+ switch_theme( 'block-theme' );
+ $has_theme_json_support = wp_theme_has_theme_json();
+
+ $this->assertSame( true, false );
+ $this->assertFalse( $default );
+ $this->assertTrue( $has_theme_json_support );
+ }
+}
From 204df73719d79c3e70c41d89798d765c29b6388d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Thu, 20 Oct 2022 17:13:27 +0200
Subject: [PATCH 05/16] Add note to backport
---
lib/compat/wordpress-6.2/default-filters.php | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/compat/wordpress-6.2/default-filters.php b/lib/compat/wordpress-6.2/default-filters.php
index c72ad1e6490df0..ad21a0fbec00ee 100644
--- a/lib/compat/wordpress-6.2/default-filters.php
+++ b/lib/compat/wordpress-6.2/default-filters.php
@@ -1,4 +1,10 @@
add_action( 'switch_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) );
+ * > add_action( 'start_previewing_theme', array( 'WP_Theme_JSON_Resolver', 'clean_cached_data' ) );
+ */
add_action( 'switch_theme', 'wp_theme_clean_theme_json_cached_data' );
add_action( 'start_previewing_theme', 'wp_theme_clean_theme_json_cached_data' );
From 9c15bdb8836e1a777fd0f1aeae56b99b3ac12f9c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 18:06:18 +0200
Subject: [PATCH 06/16] Update
lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Co-authored-by: Ari Stathopoulos
---
lib/compat/wordpress-6.2/get-global-styles-and-settings.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
index d3433dfb859780..e70899684280bb 100644
--- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
@@ -20,7 +20,7 @@ function wp_theme_has_theme_json( $use_cache = true ) {
$theme_has_support = null;
}
- if ( isset( $theme_has_support ) ) {
+ if ( null !== $theme_has_support ) {
return $theme_has_support;
}
From c17920f0a3546054ef0ba23d98ced78c1cbd176a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 18:28:50 +0200
Subject: [PATCH 07/16] Load filters
---
lib/load.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/load.php b/lib/load.php
index 67241bbb5206c4..0db2d25761771a 100644
--- a/lib/load.php
+++ b/lib/load.php
@@ -84,6 +84,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.1/persisted-preferences.php';
require __DIR__ . '/compat/wordpress-6.1/get-global-styles-and-settings.php';
require __DIR__ . '/compat/wordpress-6.2/get-global-styles-and-settings.php';
+require __DIR__ . '/compat/wordpress-6.2/default-filters.php';
require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-data-gutenberg.php';
require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-6-1.php';
require __DIR__ . '/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php';
From 3300cb650ef8567504e2842aec5db665948915bc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 18:31:25 +0200
Subject: [PATCH 08/16] Better naming
---
.../wordpress-6.2/get-global-styles-and-settings.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
index e70899684280bb..05f24dde66e5fa 100644
--- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
@@ -9,14 +9,14 @@
/**
* Whether a theme or its parent have a theme.json file.
*
- * @param boolean $use_cache Whether data should be computed from scratch or use the cache, if available
+ * @param boolean $clear_cache Whether the cache should be cleared and theme support recomputed. Default is false.
*
* @return boolean
*/
- function wp_theme_has_theme_json( $use_cache = true ) {
+ function wp_theme_has_theme_json( $clear_cache = false ) {
static $theme_has_support = null;
- if ( false === $use_cache ) {
+ if ( false === $clear_cache ) {
$theme_has_support = null;
}
@@ -43,7 +43,7 @@ function wp_theme_has_theme_json( $use_cache = true ) {
* Clean theme.json related cached data.
*/
function wp_theme_clean_theme_json_cached_data() {
- wp_theme_has_theme_json( false );
+ wp_theme_has_theme_json( true );
WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data();
}
}
From 30790456578f0000c308e5f05cda505fd530ba28 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 18:49:13 +0200
Subject: [PATCH 09/16] Fix lint issues
---
lib/compat/wordpress-6.2/default-filters.php | 17 +++++++++++++++++
phpunit/wp-theme-json.php | 2 +-
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/lib/compat/wordpress-6.2/default-filters.php b/lib/compat/wordpress-6.2/default-filters.php
index ad21a0fbec00ee..ac1ce19b425512 100644
--- a/lib/compat/wordpress-6.2/default-filters.php
+++ b/lib/compat/wordpress-6.2/default-filters.php
@@ -1,4 +1,21 @@
assertFalse( $default );
$this->assertTrue( $has_theme_json_support );
}
-}
+}
\ No newline at end of file
From 1bb36809ac5844cef89acb2408940f89d7fadd9b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 18:57:31 +0200
Subject: [PATCH 10/16] Add -test.php suffix for it to be picked up
---
phpunit/{wp-theme-json.php => wp-theme-json-test.php} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename phpunit/{wp-theme-json.php => wp-theme-json-test.php} (100%)
diff --git a/phpunit/wp-theme-json.php b/phpunit/wp-theme-json-test.php
similarity index 100%
rename from phpunit/wp-theme-json.php
rename to phpunit/wp-theme-json-test.php
From be07c58a3ce4edf055bde934a2fe6ff02c88fc4f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Tue, 25 Oct 2022 19:08:18 +0200
Subject: [PATCH 11/16] Fix lint issues
---
phpunit/wp-theme-json-test.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php
index ef6618fdeac9cb..c654e930d710a6 100644
--- a/phpunit/wp-theme-json-test.php
+++ b/phpunit/wp-theme-json-test.php
@@ -25,7 +25,6 @@ public function test_theme_has_not_theme_json_but_parent_has() {
* @group theme_json
*
* @covers wp_theme_has_theme_json
- *
*/
public function test_switching_themes_recalculates_support() {
// The "default" theme doesn't have theme.json support.
@@ -40,4 +39,4 @@ public function test_switching_themes_recalculates_support() {
$this->assertFalse( $default );
$this->assertTrue( $has_theme_json_support );
}
-}
\ No newline at end of file
+}
From 331a2ef201adc5d3660738d22748161586987098 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Wed, 26 Oct 2022 17:14:10 +0200
Subject: [PATCH 12/16] Better coverage for all use cases
---
.../block-theme-child-no-theme-json/style.css | 8 +++
.../default-child-no-theme-json/style.css | 8 +++
phpunit/wp-theme-json-test.php | 65 ++++++++++++++++---
3 files changed, 73 insertions(+), 8 deletions(-)
create mode 100644 phpunit/data/themedir1/block-theme-child-no-theme-json/style.css
create mode 100644 phpunit/data/themedir1/default-child-no-theme-json/style.css
diff --git a/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css b/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css
new file mode 100644
index 00000000000000..344441288258ec
--- /dev/null
+++ b/phpunit/data/themedir1/block-theme-child-no-theme-json/style.css
@@ -0,0 +1,8 @@
+/*
+Theme Name: Block Theme Child with no theme.json
+Theme URI: https://wordpress.org/
+Description: For testing purposes only.
+Template: block-theme
+Version: 1.0.0
+Text Domain: block-theme-child-no-theme-json
+*/
diff --git a/phpunit/data/themedir1/default-child-no-theme-json/style.css b/phpunit/data/themedir1/default-child-no-theme-json/style.css
new file mode 100644
index 00000000000000..8f971990d9fec0
--- /dev/null
+++ b/phpunit/data/themedir1/default-child-no-theme-json/style.css
@@ -0,0 +1,8 @@
+/*
+Theme Name: Default Child Theme with no theme.json
+Theme URI: https://wordpress.org/
+Description: For testing purposes only.
+Template: default
+Version: 1.0.0
+Text Domain: default-child-no-theme-json
+*/
diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php
index c654e930d710a6..dbbe8a18841457 100644
--- a/phpunit/wp-theme-json-test.php
+++ b/phpunit/wp-theme-json-test.php
@@ -7,16 +7,66 @@
class WP_Theme_Json_Test extends WP_UnitTestCase {
+ /**
+ * Test that it reports correctly themes that have a theme.json.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ */
public function test_theme_has_theme_json() {
- $this->assertSame( true, false );
+ switch_theme( 'block-theme' );
+ $this->assertTrue( wp_theme_has_theme_json() );
+ }
+
+ /**
+ * Test that it reports correctly themes that do not have a theme.json.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ */
+ public function test_theme_has_no_theme_json() {
+ switch_theme( 'default' );
+ $this->assertFalse( wp_theme_has_theme_json() );
+ }
+
+ /**
+ * Test it reports correctly child themes that have a theme.json.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ */
+ public function test_child_theme_has_theme_json() {
+ switch_theme( 'block-theme-child' );
+ $this->assertTrue( wp_theme_has_theme_json() );
}
- public function test_theme_and_parent_do_not_have_theme_json() {
- $this->assertSame( true, false );
+ /**
+ * Test that it reports correctly child themes that do not have a theme.json
+ * and the parent does.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ */
+ public function test_child_theme_has_not_theme_json_but_parent_has() {
+ switch_theme( 'block-theme-child-no-theme-json' );
+ $this->assertTrue( wp_theme_has_theme_json() );
}
- public function test_theme_has_not_theme_json_but_parent_has() {
- $this->assertSame( true, false );
+ /**
+ * Test that it reports correctly child themes that do not have a theme.json
+ * and the parent does not either.
+ *
+ * @group theme_json
+ *
+ * @covers wp_theme_has_theme_json
+ */
+ public function test_neither_child_or_parent_themes_have_theme_json() {
+ switch_theme( 'default-child-no-theme-json' );
+ $this->assertFalse( wp_theme_has_theme_json() );
}
/**
@@ -33,10 +83,9 @@ public function test_switching_themes_recalculates_support() {
// Switch to a theme that does have support.
switch_theme( 'block-theme' );
- $has_theme_json_support = wp_theme_has_theme_json();
+ $block_theme = wp_theme_has_theme_json();
- $this->assertSame( true, false );
$this->assertFalse( $default );
- $this->assertTrue( $has_theme_json_support );
+ $this->assertTrue( $block_theme );
}
}
From 0c181eeabe65d3917ad0ddcce62309459a3ac490 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Wed, 26 Oct 2022 17:32:16 +0200
Subject: [PATCH 13/16] Simplify
---
.../wordpress-6.2/get-global-styles-and-settings.php | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
index 05f24dde66e5fa..b949318149abbe 100644
--- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
@@ -25,13 +25,11 @@ function wp_theme_has_theme_json( $clear_cache = false ) {
}
// Has the own theme a theme.json?
- $candidate = get_stylesheet_directory() . '/theme.json';
- $theme_has_support = is_readable( $candidate );
+ $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
- // Has the parent a theme.json if the theme does not?
+ // Look up the parent if the child does not have a theme.json.
if ( ! $theme_has_support ) {
- $candidate = get_template_directory() . '/theme.json';
- $theme_has_support = is_readable( $candidate );
+ $theme_has_support = is_readable( get_template_directory() . '/theme.json' );
}
return $theme_has_support;
From 174793f65cae82e139e9709ca528f013420d87e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Wed, 26 Oct 2022 17:42:05 +0200
Subject: [PATCH 14/16] Update test for resolver
---
phpunit/class-wp-theme-json-resolver-test.php | 15 +--------------
1 file changed, 1 insertion(+), 14 deletions(-)
diff --git a/phpunit/class-wp-theme-json-resolver-test.php b/phpunit/class-wp-theme-json-resolver-test.php
index 14ce71f3b4ed5b..3746d158f20169 100644
--- a/phpunit/class-wp-theme-json-resolver-test.php
+++ b/phpunit/class-wp-theme-json-resolver-test.php
@@ -125,19 +125,6 @@ public function test_translations_are_applied() {
);
}
- public function test_switching_themes_recalculates_data() {
- // The "default" theme doesn't have theme.json support.
- switch_theme( 'default' );
- $default = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
-
- // Switch to a theme that does have support.
- switch_theme( 'block-theme' );
- $has_theme_json_support = WP_Theme_JSON_Resolver_Gutenberg::theme_has_support();
-
- $this->assertFalse( $default );
- $this->assertTrue( $has_theme_json_support );
- }
-
public function test_add_theme_supports_are_loaded_for_themes_without_theme_json() {
switch_theme( 'default' );
$color_palette = array(
@@ -165,7 +152,7 @@ public function test_add_theme_supports_are_loaded_for_themes_without_theme_json
remove_theme_support( 'custom-line-height' );
remove_theme_support( 'editor-color-palette' );
- $this->assertFalse( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() );
+ $this->assertFalse( wp_theme_has_theme_json() );
$this->assertTrue( $settings['typography']['lineHeight'] );
$this->assertSame( $color_palette, $settings['color']['palette']['theme'] );
}
From 2b570aa9ba6062bce9c57b6ea2eecfef28aab3e9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Wed, 26 Oct 2022 21:02:46 +0200
Subject: [PATCH 15/16] Update
lib/compat/wordpress-6.2/get-global-styles-and-settings.php
Co-authored-by: George Mamadashvili
---
lib/compat/wordpress-6.2/get-global-styles-and-settings.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
index b949318149abbe..4dbd9d0ba8bde1 100644
--- a/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
+++ b/lib/compat/wordpress-6.2/get-global-styles-and-settings.php
@@ -16,7 +16,7 @@
function wp_theme_has_theme_json( $clear_cache = false ) {
static $theme_has_support = null;
- if ( false === $clear_cache ) {
+ if ( true === $clear_cache ) {
$theme_has_support = null;
}
From 92db7ba7fe63b2e1562e4ce6e492ff5edb662e87 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9?= <583546+oandregal@users.noreply.github.com>
Date: Fri, 28 Oct 2022 10:47:21 +0200
Subject: [PATCH 16/16] Properly set up theme directory
---
phpunit/wp-theme-json-test.php | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/phpunit/wp-theme-json-test.php b/phpunit/wp-theme-json-test.php
index dbbe8a18841457..0d92d33faf88de 100644
--- a/phpunit/wp-theme-json-test.php
+++ b/phpunit/wp-theme-json-test.php
@@ -7,6 +7,35 @@
class WP_Theme_Json_Test extends WP_UnitTestCase {
+ public function set_up() {
+ parent::set_up();
+ $this->theme_root = realpath( __DIR__ . '/data/themedir1' );
+
+ $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
+
+ // /themes is necessary as theme.php functions assume /themes is the root if there is only one root.
+ $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
+
+ add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) );
+ add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) );
+ add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) );
+ $this->queries = array();
+ // Clear caches.
+ wp_clean_themes_cache();
+ unset( $GLOBALS['wp_themes'] );
+ }
+
+ public function tear_down() {
+ $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
+ wp_clean_themes_cache();
+ unset( $GLOBALS['wp_themes'] );
+ parent::tear_down();
+ }
+
+ public function filter_set_theme_root() {
+ return $this->theme_root;
+ }
+
/**
* Test that it reports correctly themes that have a theme.json.
*