diff --git a/src/wp-includes/global-styles-and-settings.php b/src/wp-includes/global-styles-and-settings.php index 1258f1f4e3..032913db44 100644 --- a/src/wp-includes/global-styles-and-settings.php +++ b/src/wp-includes/global-styles-and-settings.php @@ -222,7 +222,13 @@ function wp_get_global_stylesheet( $types = array() ) { * @see wp_add_global_styles_for_blocks */ $origins = array( 'default', 'theme', 'custom' ); - if ( ! $supports_theme_json ) { + /* + * If the theme doesn't have theme.json but supports both appearance tools and color palette, + * the 'theme' origin should be included so color palette presets are also output. + */ + if ( ! $supports_theme_json && ( current_theme_supports( 'appearance-tools' ) || current_theme_supports( 'border' ) ) && current_theme_supports( 'editor-color-palette' ) ) { + $origins = array( 'default', 'theme' ); + } elseif ( ! $supports_theme_json ) { $origins = array( 'default' ); } $styles_rest = $tree->get_stylesheet( $types, $origins ); diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 24b564debb..7a5438951c 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -127,6 +127,9 @@ class WP_Test_REST_Themes_Controller extends WP_Test_REST_Controller_Testcase { self::delete_user( self::$subscriber_id ); self::delete_user( self::$contributor_id ); self::delete_user( self::$admin_id ); + + remove_theme_support( 'editor-gradient-presets' ); + remove_theme_support( 'editor-color-palette' ); } /** diff --git a/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php b/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php index 3035467a01..a3b6ce0c2f 100644 --- a/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php +++ b/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php @@ -18,6 +18,13 @@ class Tests_Theme_WpGetGlobalStylesheet extends WP_Theme_UnitTestCase { */ private $remove_theme_support_at_teardown = false; + /** + * Flag to indicate whether to remove 'border' theme support at tear_down(). + * + * @var bool + */ + private $remove_border_support_at_teardown = false; + /** * Flag to indicate whether to switch back to the default theme at tear down. * @@ -40,6 +47,12 @@ class Tests_Theme_WpGetGlobalStylesheet extends WP_Theme_UnitTestCase { switch_theme( WP_DEFAULT_THEME ); } + if ( $this->remove_border_support_at_teardown ) { + $this->remove_border_support_at_teardown = false; + remove_theme_support( 'border' ); + remove_theme_support( 'editor-color-palette' ); + } + parent::tear_down(); } @@ -246,6 +259,64 @@ class Tests_Theme_WpGetGlobalStylesheet extends WP_Theme_UnitTestCase { $this->assertNotSame( $css, wp_get_global_stylesheet(), 'Caching was used despite theme development mode' ); } + /** + * Tests that theme color palette presets are output when appearance tools are enabled via theme support. + * + * @ticket 60134 + */ + public function test_theme_color_palette_presets_output_when_border_support_enabled() { + + $args = array( + array( + 'name' => 'Black', + 'slug' => 'nice-black', + 'color' => '#000000', + ), + array( + 'name' => 'Dark Gray', + 'slug' => 'dark-gray', + 'color' => '#28303D', + ), + array( + 'name' => 'Green', + 'slug' => 'haunted-green', + 'color' => '#D1E4DD', + ), + array( + 'name' => 'Blue', + 'slug' => 'soft-blue', + 'color' => '#D1DFE4', + ), + array( + 'name' => 'Purple', + 'slug' => 'cool-purple', + 'color' => '#D1D1E4', + ), + ); + + // Add theme support for appearance tools. + add_theme_support( 'border' ); + add_theme_support( 'editor-color-palette', $args ); + $this->remove_border_support_at_teardown = true; + + // Check for both the variable declaration and its use as a value. + $variables = wp_get_global_stylesheet( array( 'variables' ) ); + + $this->assertStringContainsString( '--wp--preset--color--nice-black: #000000', $variables ); + $this->assertStringContainsString( '--wp--preset--color--dark-gray: #28303D', $variables ); + $this->assertStringContainsString( '--wp--preset--color--haunted-green: #D1E4DD', $variables ); + $this->assertStringContainsString( '--wp--preset--color--soft-blue: #D1DFE4', $variables ); + $this->assertStringContainsString( '--wp--preset--color--cool-purple: #D1D1E4', $variables ); + + $presets = wp_get_global_stylesheet( array( 'presets' ) ); + + $this->assertStringContainsString( 'var(--wp--preset--color--nice-black)', $presets ); + $this->assertStringContainsString( 'var(--wp--preset--color--dark-gray)', $presets ); + $this->assertStringContainsString( 'var(--wp--preset--color--haunted-green)', $presets ); + $this->assertStringContainsString( 'var(--wp--preset--color--soft-blue)', $presets ); + $this->assertStringContainsString( 'var(--wp--preset--color--cool-purple)', $presets ); + } + /** * Adds the 'editor-font-sizes' theme support with custom font sizes. *