From 3fd8476f583183a1a0ebb757ac302b0884b2e144 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Thu, 28 May 2026 18:39:42 +0530 Subject: [PATCH 1/4] feat: add tailwind support for blocks --- inc/Core/Assets.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inc/Core/Assets.php b/inc/Core/Assets.php index 6446fda0..d8322c48 100644 --- a/inc/Core/Assets.php +++ b/inc/Core/Assets.php @@ -62,11 +62,25 @@ public function __construct() { * @since 1.0.0 */ public function register_hooks(): void { + add_action( 'after_setup_theme', [ $this, 'add_editor_styles' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'register_assets' ] ); add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_assets' ] ); add_filter( 'render_block', [ $this, 'enqueue_block_specific_assets' ], 10, 2 ); } + /** + * Register Tailwind stylesheet for the block editor. + * + * @since 1.0.0 + * + * @action after_setup_theme + */ + public function add_editor_styles(): void { + if ( $this->tailwind_enabled ) { + add_editor_style( $this->assets_dir . '/css/frontend/tailwind.css' ); + } + } + /** * Register assets. * From 40ec02fdfdc35aca187070453ec81d3a41bd3fe1 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Thu, 28 May 2026 19:25:39 +0530 Subject: [PATCH 2/4] chore: add tests --- tests/php/inc/Core/AssetsTest.php | 74 +++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/php/inc/Core/AssetsTest.php b/tests/php/inc/Core/AssetsTest.php index 1d296997..b9b3d364 100644 --- a/tests/php/inc/Core/AssetsTest.php +++ b/tests/php/inc/Core/AssetsTest.php @@ -32,6 +32,15 @@ public function set_up(): void { $this->instance = new Assets(); } + /** + * Tear down test. + */ + public function tear_down(): void { + wp_dequeue_style( 'elementary-theme-tailwind' ); + wp_deregister_style( 'elementary-theme-tailwind' ); + parent::tear_down(); + } + /** * Test class exists. */ @@ -52,8 +61,73 @@ public function test_implements_registrable(): void { public function test_register_hooks(): void { $this->instance->register_hooks(); + $this->assertGreaterThan( 0, has_action( 'after_setup_theme', [ $this->instance, 'add_editor_styles' ] ) ); $this->assertGreaterThan( 0, has_action( 'wp_enqueue_scripts', [ $this->instance, 'register_assets' ] ) ); $this->assertGreaterThan( 0, has_action( 'wp_enqueue_scripts', [ $this->instance, 'enqueue_assets' ] ) ); $this->assertGreaterThan( 0, has_filter( 'render_block', [ $this->instance, 'enqueue_block_specific_assets' ] ) ); } + + /** + * Test add_editor_styles registers the Tailwind stylesheet when Tailwind is enabled. + */ + public function test_add_editor_styles_when_tailwind_enabled(): void { + global $editor_styles; + $before = (array) $editor_styles; + + add_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); + $instance = new Assets(); + $instance->add_editor_styles(); + remove_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); + + $added = array_diff( (array) $editor_styles, $before ); + $found = array_filter( $added, fn( string $s ): bool => str_contains( $s, 'tailwind.css' ) ); + $this->assertNotEmpty( $found ); + } + + /** + * Test add_editor_styles does not register the Tailwind stylesheet when Tailwind is disabled. + */ + public function test_add_editor_styles_when_tailwind_disabled(): void { + global $editor_styles; + $before = (array) $editor_styles; + + add_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); + $instance = new Assets(); + $instance->add_editor_styles(); + remove_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); + + $added = array_diff( (array) $editor_styles, $before ); + $found = array_filter( $added, fn( string $s ): bool => str_contains( $s, 'tailwind.css' ) ); + $this->assertEmpty( $found ); + } + + /** + * Test enqueue_assets enqueues the Tailwind stylesheet on the frontend when enabled. + */ + public function test_enqueue_assets_enqueues_tailwind_when_enabled(): void { + add_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); + $instance = new Assets(); + + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css' ); + $instance->enqueue_assets(); + + remove_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); + + $this->assertTrue( wp_style_is( 'elementary-theme-tailwind', 'enqueued' ) ); + } + + /** + * Test enqueue_assets does not enqueue the Tailwind stylesheet on the frontend when disabled. + */ + public function test_enqueue_assets_does_not_enqueue_tailwind_when_disabled(): void { + add_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); + $instance = new Assets(); + + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css' ); + $instance->enqueue_assets(); + + remove_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); + + $this->assertFalse( wp_style_is( 'elementary-theme-tailwind', 'enqueued' ) ); + } } From 342416ad56ba4a70752612d3a4ac88929671b28d Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Fri, 29 May 2026 20:38:39 +0530 Subject: [PATCH 3/4] test: egister_style version fix --- tests/php/inc/Core/AssetsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php/inc/Core/AssetsTest.php b/tests/php/inc/Core/AssetsTest.php index b9b3d364..e89a1b4b 100644 --- a/tests/php/inc/Core/AssetsTest.php +++ b/tests/php/inc/Core/AssetsTest.php @@ -108,7 +108,7 @@ public function test_enqueue_assets_enqueues_tailwind_when_enabled(): void { add_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); $instance = new Assets(); - wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css' ); + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], false ); $instance->enqueue_assets(); remove_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); @@ -123,7 +123,7 @@ public function test_enqueue_assets_does_not_enqueue_tailwind_when_disabled(): v add_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); $instance = new Assets(); - wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css' ); + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], false ); $instance->enqueue_assets(); remove_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); From a08ee5639894023c86e422092f128cf5d1a04be4 Mon Sep 17 00:00:00 2001 From: Swanand01 Date: Fri, 29 May 2026 20:40:36 +0530 Subject: [PATCH 4/4] test: register_style version fix --- tests/php/inc/Core/AssetsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php/inc/Core/AssetsTest.php b/tests/php/inc/Core/AssetsTest.php index e89a1b4b..b6f7be2c 100644 --- a/tests/php/inc/Core/AssetsTest.php +++ b/tests/php/inc/Core/AssetsTest.php @@ -108,7 +108,7 @@ public function test_enqueue_assets_enqueues_tailwind_when_enabled(): void { add_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); $instance = new Assets(); - wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], false ); + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], '1.0.0' ); $instance->enqueue_assets(); remove_filter( 'elementary_theme_tailwind_enabled', '__return_true' ); @@ -123,7 +123,7 @@ public function test_enqueue_assets_does_not_enqueue_tailwind_when_disabled(): v add_filter( 'elementary_theme_tailwind_enabled', '__return_false' ); $instance = new Assets(); - wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], false ); + wp_register_style( 'elementary-theme-tailwind', 'https://example.com/tailwind.css', [], '1.0.0' ); $instance->enqueue_assets(); remove_filter( 'elementary_theme_tailwind_enabled', '__return_false' );