From 5e10d30360d69b65a6bd4b670b6fa4095927f1d9 Mon Sep 17 00:00:00 2001 From: selul Date: Wed, 11 Nov 2026 12:10:01 +0200 Subject: [PATCH 01/15] fix: validate template cloud requests --- inc/plugins/class-template-cloud.php | 5 ++- inc/server/class-template-cloud-server.php | 2 +- tests/test-template-cloud.php | 36 ++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/inc/plugins/class-template-cloud.php b/inc/plugins/class-template-cloud.php index 52c51dc37..a1cf07de4 100644 --- a/inc/plugins/class-template-cloud.php +++ b/inc/plugins/class-template-cloud.php @@ -246,8 +246,7 @@ public static function sync_sources() { foreach ( $sources as $source ) { $url = trailingslashit( $source['url'] ) . self::API_ENDPOINT_SUFFIX; $args = array( - 'sslverify' => false, - 'headers' => array( + 'headers' => array( 'X-API-KEY' => $source['key'], ), ); @@ -255,7 +254,7 @@ public static function sync_sources() { if ( function_exists( 'vip_safe_wp_remote_get' ) ) { $response = vip_safe_wp_remote_get( $url, '', 3, 1, 20, $args ); } else { - $response = wp_remote_get( $url, $args ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get + $response = wp_safe_remote_get( $url, $args ); } if ( is_wp_error( $response ) ) { diff --git a/inc/server/class-template-cloud-server.php b/inc/server/class-template-cloud-server.php index 7b3fa90aa..62cb1df53 100644 --- a/inc/server/class-template-cloud-server.php +++ b/inc/server/class-template-cloud-server.php @@ -107,7 +107,7 @@ private function validate_source_and_get_name( $url, $key ) { if ( function_exists( 'vip_safe_wp_remote_get' ) ) { $response = vip_safe_wp_remote_get( $url, '', 3, 1, 20, $args ); } else { - $response = wp_remote_get( $url, $args ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get + $response = wp_safe_remote_get( $url, $args ); } if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) { diff --git a/tests/test-template-cloud.php b/tests/test-template-cloud.php index 91d4b8ec7..098d0cd71 100644 --- a/tests/test-template-cloud.php +++ b/tests/test-template-cloud.php @@ -138,6 +138,42 @@ public function test_validate_source_does_not_disable_ssl_verification() { $method->invoke( $this->server, 'https://example.com', 'test-key' ); $this->assertNotFalse( $captured['sslverify'] ); + $this->assertTrue( $captured['reject_unsafe_urls'] ); + } + + public function test_sync_sources_uses_safe_http_defaults() { + Template_Cloud::save_pattern_sources( + [ + [ + 'key' => 'test-key', + 'url' => 'https://example.com', + 'name' => 'Test Source', + ], + ] + ); + + $captured = array(); + $stub = function ( $preempt, $args ) use ( &$captured ) { + $captured = $args; + + return array( + 'response' => array( 'code' => 200 ), + 'body' => wp_json_encode( + array( + 'success' => true, + 'data' => array(), + 'key_name' => 'Test Source', + ) + ), + ); + }; + + add_filter( 'pre_http_request', $stub, 10, 2 ); + Template_Cloud::sync_sources(); + remove_filter( 'pre_http_request', $stub, 10 ); + + $this->assertTrue( $captured['sslverify'] ); + $this->assertTrue( $captured['reject_unsafe_urls'] ); } public function test_remove_source() { From 3bb3436ce3e8d556af9ef63e14b9f8dfe23adcc0 Mon Sep 17 00:00:00 2001 From: selul Date: Wed, 11 Nov 2026 12:56:54 +0200 Subject: [PATCH 02/15] fix: align template cloud request arguments --- inc/plugins/class-template-cloud.php | 3 +- inc/server/class-template-cloud-server.php | 3 +- tests/fixtures/vip-http.php | 79 ++++++++++++++++++++++ tests/test-template-cloud.php | 33 +++++++++ 4 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/vip-http.php diff --git a/inc/plugins/class-template-cloud.php b/inc/plugins/class-template-cloud.php index a1cf07de4..8b268a074 100644 --- a/inc/plugins/class-template-cloud.php +++ b/inc/plugins/class-template-cloud.php @@ -246,7 +246,8 @@ public static function sync_sources() { foreach ( $sources as $source ) { $url = trailingslashit( $source['url'] ) . self::API_ENDPOINT_SUFFIX; $args = array( - 'headers' => array( + 'reject_unsafe_urls' => true, + 'headers' => array( 'X-API-KEY' => $source['key'], ), ); diff --git a/inc/server/class-template-cloud-server.php b/inc/server/class-template-cloud-server.php index 62cb1df53..5eb6fb388 100644 --- a/inc/server/class-template-cloud-server.php +++ b/inc/server/class-template-cloud-server.php @@ -99,7 +99,8 @@ public function register_routes() { private function validate_source_and_get_name( $url, $key ) { $url = trailingslashit( $url ) . self::API_ENDPOINT_SUFFIX; $args = [ - 'headers' => [ + 'reject_unsafe_urls' => true, + 'headers' => [ 'X-API-KEY' => $key, ], ]; diff --git a/tests/fixtures/vip-http.php b/tests/fixtures/vip-http.php new file mode 100644 index 000000000..5385b56cb --- /dev/null +++ b/tests/fixtures/vip-http.php @@ -0,0 +1,79 @@ + + */ + public static function request( $url, $fallback_value, $threshold, $timeout, $retry, $args ) { + $GLOBALS['otter_vip_requests'][] = array( + 'url' => $url, + 'fallback_value' => $fallback_value, + 'threshold' => $threshold, + 'timeout' => $timeout, + 'retry' => $retry, + 'args' => $args, + ); + + return array( + 'response' => array( 'code' => 200 ), + 'body' => \wp_json_encode( + array( + 'success' => true, + 'data' => array(), + 'key_name' => 'Test Source', + ) + ), + ); + } + } +} + +namespace ThemeIsle\GutenbergBlocks\Server { + use ThemeIsle\GutenbergBlocks\Tests\VIP_HTTP_Stub; + + function function_exists( $function ) { + if ( 'vip_safe_wp_remote_get' === $function && ! empty( $GLOBALS['otter_vip_stub_enabled'] ) ) { + return true; + } + + return \function_exists( $function ); + } + + function vip_safe_wp_remote_get( $url, $fallback_value = '', $threshold = 3, $timeout = 1, $retry = 20, $args = array() ) { + return VIP_HTTP_Stub::request( $url, $fallback_value, $threshold, $timeout, $retry, $args ); + } +} + +namespace ThemeIsle\GutenbergBlocks\Plugins { + use ThemeIsle\GutenbergBlocks\Tests\VIP_HTTP_Stub; + + function function_exists( $function ) { + if ( 'vip_safe_wp_remote_get' === $function && ! empty( $GLOBALS['otter_vip_stub_enabled'] ) ) { + return true; + } + + return \function_exists( $function ); + } + + function vip_safe_wp_remote_get( $url, $fallback_value = '', $threshold = 3, $timeout = 1, $retry = 20, $args = array() ) { + return VIP_HTTP_Stub::request( $url, $fallback_value, $threshold, $timeout, $retry, $args ); + } +} diff --git a/tests/test-template-cloud.php b/tests/test-template-cloud.php index 098d0cd71..1efd5d03b 100644 --- a/tests/test-template-cloud.php +++ b/tests/test-template-cloud.php @@ -10,6 +10,9 @@ class Test_Template_Cloud extends WP_UnitTestCase { public function set_up(): void { parent::set_up(); + require_once __DIR__ . '/fixtures/vip-http.php'; + $GLOBALS['otter_vip_stub_enabled'] = false; + /** @var \WP_REST_Server $wp_rest_server */ global $wp_rest_server; $wp_rest_server = new \Spy_REST_Server; @@ -22,6 +25,8 @@ public function set_up(): void { } public function tear_down(): void { + $GLOBALS['otter_vip_stub_enabled'] = false; + unset( $GLOBALS['otter_vip_requests'] ); delete_option( Template_Cloud::SOURCES_SETTING_KEY ); parent::tear_down(); } @@ -176,6 +181,34 @@ public function test_sync_sources_uses_safe_http_defaults() { $this->assertTrue( $captured['reject_unsafe_urls'] ); } + public function test_vip_requests_preserve_request_defaults() { + $GLOBALS['otter_vip_stub_enabled'] = true; + $GLOBALS['otter_vip_requests'] = array(); + + $reflection = new ReflectionClass( $this->server ); + $method = $reflection->getMethod( 'validate_source_and_get_name' ); + $method->setAccessible( true ); + $method->invoke( $this->server, 'https://example.com', 'test-key' ); + + Template_Cloud::save_pattern_sources( + array( + array( + 'key' => 'test-key', + 'url' => 'https://example.com', + 'name' => 'Test Source', + ), + ) + ); + Template_Cloud::sync_sources(); + + $this->assertCount( 2, $GLOBALS['otter_vip_requests'] ); + + foreach ( $GLOBALS['otter_vip_requests'] as $request ) { + $this->assertTrue( $request['args']['reject_unsafe_urls'] ); + $this->assertSame( 1, $request['timeout'] ); + } + } + public function test_remove_source() { $sources = [ [ From 012b316d4ebbcf24c0aabff55fd6a3f808f21313 Mon Sep 17 00:00:00 2001 From: selul Date: Wed, 11 Nov 2026 19:01:03 +0200 Subject: [PATCH 03/15] Validate custom animation timing values --- src/animation/editor.js | 14 ++++++++--- src/animation/frontend.js | 14 ++++++++--- src/animation/timing.js | 18 +++++++++++++ src/blocks/test/unit/animation-timing.test.js | 25 +++++++++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 src/animation/timing.js create mode 100644 src/blocks/test/unit/animation-timing.test.js diff --git a/src/animation/editor.js b/src/animation/editor.js index 9429593e0..ef2ff7e84 100644 --- a/src/animation/editor.js +++ b/src/animation/editor.js @@ -32,6 +32,8 @@ import { import AnimationPopover from './components/animation-popover.js'; +import { getAnimationTimingValue } from './timing.js'; + import ControlPanelControl from './../blocks/components/control-panel-control/index.js'; import countPlaceholder from './../../assets/images/count-animation.png'; @@ -217,10 +219,14 @@ function AnimationControls({ attributes.className ?.split( ' ' ) .map( ( i ) => { - if ( i.includes( 'o-anim-value-delay-' ) ) { - return `.${ i } { animation-delay: ${ i.replace( 'o-anim-value-delay-', '' ) }; --webkit-animation-delay: ${ i.replace( 'o-anim-value-delay-', '' ) }; }`; - } else if ( i.includes( 'o-anim-value-speed-' ) ) { - return `.${ i } { animation-duration: ${ i.replace( 'o-anim-value-speed-', '' ) }; --webkit-animation-duration: ${ i.replace( 'o-anim-value-speed-', '' ) }; }`; + const delayValue = getAnimationTimingValue( i, 'o-anim-value-delay-' ); + if ( null !== delayValue ) { + return `.${ i } { animation-delay: ${ delayValue }; --webkit-animation-delay: ${ delayValue }; }`; + } + + const speedValue = getAnimationTimingValue( i, 'o-anim-value-speed-' ); + if ( null !== speedValue ) { + return `.${ i } { animation-duration: ${ speedValue }; --webkit-animation-duration: ${ speedValue }; }`; } return ''; }) diff --git a/src/animation/frontend.js b/src/animation/frontend.js index 55bc47b8e..94027df85 100644 --- a/src/animation/frontend.js +++ b/src/animation/frontend.js @@ -1,3 +1,5 @@ +import { getAnimationTimingValue } from './timing.js'; + const animations = [ 'none', 'bounce', @@ -379,9 +381,12 @@ const createCustomAnimationNode = ( elements ) => { // Helper to escape CSS class names (e.g., 2.3 -> 2\.3) const escapeCssClass = className => className.replace(/([!"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g, '\\$1'); - customValuesNode.innerHTML = customDelays.reduce( + customValuesNode.textContent = customDelays.reduce( ( accumulator, cssClass ) => { - const delayValue = cssClass.replace( 'o-anim-value-delay-', '' ); + const delayValue = getAnimationTimingValue( cssClass, 'o-anim-value-delay-' ); + if ( null === delayValue ) { + return accumulator; + } const escapedClass = escapeCssClass( cssClass ); return ( @@ -392,7 +397,10 @@ const createCustomAnimationNode = ( elements ) => { '' ) + '\n' + customSpeeds.reduce( ( accumulator, cssClass ) => { - const speedValue = cssClass.replace( 'o-anim-value-speed-', '' ); + const speedValue = getAnimationTimingValue( cssClass, 'o-anim-value-speed-' ); + if ( null === speedValue ) { + return accumulator; + } const escapedClass = escapeCssClass( cssClass ); return ( diff --git a/src/animation/timing.js b/src/animation/timing.js new file mode 100644 index 000000000..069ba5617 --- /dev/null +++ b/src/animation/timing.js @@ -0,0 +1,18 @@ +const TIMING_VALUE_PATTERN = /^[0-9]*\.?[0-9]+(?:ms|s)$/; + +/** + * Read a supported animation timing value from a class name. + * + * @param {string} className The class name to inspect. + * @param {string} prefix The timing class prefix. + * @return {string|null} The timing value, or null when it is unsupported. + */ +export const getAnimationTimingValue = ( className, prefix ) => { + if ( ! className.startsWith( prefix ) ) { + return null; + } + + const value = className.slice( prefix.length ); + + return TIMING_VALUE_PATTERN.test( value ) ? value : null; +}; diff --git a/src/blocks/test/unit/animation-timing.test.js b/src/blocks/test/unit/animation-timing.test.js new file mode 100644 index 000000000..4d309293f --- /dev/null +++ b/src/blocks/test/unit/animation-timing.test.js @@ -0,0 +1,25 @@ +describe( 'Animation timing values', () => { + afterEach( () => { + document.body.innerHTML = ''; + jest.resetModules(); + } ); + + it( 'ignores malformed custom timing values', () => { + document.body.innerHTML = [ + '
Valid
', + '
Valid
', + '
Invalid
', + '
Invalid
' + ].join( '' ); + + require( '../../../animation/frontend' ); + window.dispatchEvent( new Event( 'load' ) ); + + const timingStyles = document.querySelector( '#o-anim-custom-values' ); + + expect( timingStyles.textContent ).toContain( 'animation-delay: 250ms' ); + expect( timingStyles.textContent ).toContain( 'animation-duration: 1.5s' ); + expect( timingStyles.textContent ).not.toContain( '1second' ); + expect( timingStyles.textContent ).not.toContain( 'fast' ); + } ); +} ); From d85c22e9e3c51421f83e97e82888251865f338e7 Mon Sep 17 00:00:00 2001 From: selul Date: Wed, 11 Nov 2026 19:10:59 +0200 Subject: [PATCH 04/15] Cover editor animation timing styles --- src/blocks/test/e2e/blocks/animations.spec.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/blocks/test/e2e/blocks/animations.spec.js b/src/blocks/test/e2e/blocks/animations.spec.js index 2fb1f2adf..b9a386553 100644 --- a/src/blocks/test/e2e/blocks/animations.spec.js +++ b/src/blocks/test/e2e/blocks/animations.spec.js @@ -127,6 +127,30 @@ test.describe( 'Animations', () => { await expect( editor.canvas.locator( '.o-anim-custom-speed.o-anim-value-speed-2s' ).first() ).toBeVisible(); }); + test( 'ignores unsupported custom values in editor styles', async({ editor, page }) => { + await editor.insertBlock({ + name: 'core/paragraph', + attributes: { + content: 'Animated paragraph', + className: [ + 'animated headShake', + 'o-anim-custom-delay o-anim-value-delay-250ms o-anim-value-delay-1second', + 'o-anim-custom-speed o-anim-value-speed-1.5s o-anim-value-speed-fast' + ].join( ' ' ) + } + }); + + await page.getByRole( 'button', { name: 'Animations' }).click(); + + const animationStyles = editor.canvas.locator( 'style[data-generator="otter-blocks"]' ); + const styleText = async() => ( await animationStyles.allTextContents() ).join( '\n' ); + + await expect.poll( styleText ).toContain( 'animation-delay: 250ms' ); + await expect.poll( styleText ).toContain( 'animation-duration: 1.5s' ); + await expect.poll( styleText ).not.toContain( '1second' ); + await expect.poll( styleText ).not.toContain( 'fast' ); + }); + test( 'count and typing help popovers show their own image', async({ editor, page }) => { await editor.insertBlock({ name: 'core/paragraph' }); From 6e0122488d95a3a605af5dc94c000a1ae51cdd6c Mon Sep 17 00:00:00 2001 From: selul Date: Wed, 11 Nov 2026 20:14:06 +0200 Subject: [PATCH 05/15] Preserve supported animation timing classes --- src/animation/frontend.js | 4 ++-- src/blocks/test/unit/animation-timing.test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/animation/frontend.js b/src/animation/frontend.js index 94027df85..821257a74 100644 --- a/src/animation/frontend.js +++ b/src/animation/frontend.js @@ -346,7 +346,7 @@ const createCustomAnimationNode = ( elements ) => { if ( classes.contains( 'o-anim-custom-delay' ) ) { let delay; for ( const className of classes ) { - if ( className.includes( 'o-anim-value-delay-' ) ) { + if ( null !== getAnimationTimingValue( className, 'o-anim-value-delay-' ) ) { delay = className; break; } @@ -359,7 +359,7 @@ const createCustomAnimationNode = ( elements ) => { if ( classes.contains( 'o-anim-custom-speed' ) ) { let speed; for ( const className of classes ) { - if ( className.includes( 'o-anim-value-speed-' ) ) { + if ( null !== getAnimationTimingValue( className, 'o-anim-value-speed-' ) ) { speed = className; break; } diff --git a/src/blocks/test/unit/animation-timing.test.js b/src/blocks/test/unit/animation-timing.test.js index 4d309293f..db1eef85e 100644 --- a/src/blocks/test/unit/animation-timing.test.js +++ b/src/blocks/test/unit/animation-timing.test.js @@ -22,4 +22,21 @@ describe( 'Animation timing values', () => { expect( timingStyles.textContent ).not.toContain( '1second' ); expect( timingStyles.textContent ).not.toContain( 'fast' ); } ); + + it( 'keeps supported timing values after unsupported classes', () => { + document.body.innerHTML = [ + '
Delay
', + '
Speed
' + ].join( '' ); + + require( '../../../animation/frontend' ); + window.dispatchEvent( new Event( 'load' ) ); + + const timingStyles = document.querySelector( '#o-anim-custom-values' ); + + expect( timingStyles.textContent ).toContain( 'animation-delay: 250ms' ); + expect( timingStyles.textContent ).toContain( 'animation-duration: 1.5s' ); + expect( timingStyles.textContent ).not.toContain( '1second' ); + expect( timingStyles.textContent ).not.toContain( 'fast' ); + } ); } ); From 67256cbe9ae60a0b6601501243995169ec07f4c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:01:01 +0200 Subject: [PATCH 06/15] build(deps-dev): bump php-stubs/woocommerce-stubs from 11.2.1 to 11.2.2 (#3173) Bumps [php-stubs/woocommerce-stubs](https://github.com/php-stubs/woocommerce-stubs) from 11.2.1 to 11.2.2. - [Commits](https://github.com/php-stubs/woocommerce-stubs/compare/v11.2.1...v11.2.2) --- updated-dependencies: - dependency-name: php-stubs/woocommerce-stubs dependency-version: 11.2.2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- composer.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index d848135e5..0a27b7e3a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ed7d2f988ffce5c2a5150505b5329207", + "content-hash": "c01ca8d521c97d9b29fb7fce95c0002f", "packages": [ { "name": "codeinwp/themeisle-sdk", @@ -977,16 +977,16 @@ }, { "name": "php-stubs/woocommerce-stubs", - "version": "v11.2.1", + "version": "v11.2.2", "source": { "type": "git", "url": "https://github.com/php-stubs/woocommerce-stubs.git", - "reference": "8cfdb86cad90da64441317e1bebe5f71a437a074" + "reference": "d5c232c183c09689d75c177b01bef60e6dd53639" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/8cfdb86cad90da64441317e1bebe5f71a437a074", - "reference": "8cfdb86cad90da64441317e1bebe5f71a437a074", + "url": "https://api.github.com/repos/php-stubs/woocommerce-stubs/zipball/d5c232c183c09689d75c177b01bef60e6dd53639", + "reference": "d5c232c183c09689d75c177b01bef60e6dd53639", "shasum": "" }, "require": { @@ -1015,9 +1015,9 @@ ], "support": { "issues": "https://github.com/php-stubs/woocommerce-stubs/issues", - "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v11.2.1" + "source": "https://github.com/php-stubs/woocommerce-stubs/tree/v11.2.2" }, - "time": "2026-10-09T20:26:55+00:00" + "time": "2026-11-04T21:47:17+00:00" }, { "name": "php-stubs/wordpress-stubs", From 9ded2252a90912defe76617300315280d6d68278 Mon Sep 17 00:00:00 2001 From: selul Date: Thu, 12 Nov 2026 03:08:57 +0200 Subject: [PATCH 07/15] fix: stop repeated synced pattern expansion --- inc/class-blocks-css.php | 29 ++++++++++++++++++++++---- tests/test-blocks-css.php | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/inc/class-blocks-css.php b/inc/class-blocks-css.php index 12fd7f4c1..b80c311c5 100644 --- a/inc/class-blocks-css.php +++ b/inc/class-blocks-css.php @@ -219,6 +219,19 @@ protected function is_standalone() { * @access public */ public function cycle_through_blocks( $inner_blocks, $id ) { + return $this->collect_css_from_blocks( $inner_blocks, $id, array() ); + } + + /** + * Collect custom CSS while tracking the current synced-pattern chain. + * + * @param array> $inner_blocks Blocks to inspect. + * @param int $id Post ID. + * @param array $seen_refs Synced-pattern IDs in the current chain. + * + * @return string + */ + private function collect_css_from_blocks( $inner_blocks, $id, $seen_refs ) { $style = ''; foreach ( $inner_blocks as $block ) { @@ -232,7 +245,13 @@ public function cycle_through_blocks( $inner_blocks, $id ) { } if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { - $reusable_block = get_post( $block['attrs']['ref'] ); + $reference_id = absint( $block['attrs']['ref'] ); + + if ( isset( $seen_refs[ $reference_id ] ) ) { + continue; + } + + $reusable_block = get_post( $reference_id ); if ( ! $reusable_block || 'wp_block' !== $reusable_block->post_type ) { return ''; @@ -242,13 +261,15 @@ public function cycle_through_blocks( $inner_blocks, $id ) { return ''; } - $blocks = parse_blocks( $reusable_block->post_content ); + $blocks = parse_blocks( $reusable_block->post_content ); + $next_seen_refs = $seen_refs; + $next_seen_refs[ $reference_id ] = true; - $style .= $this->cycle_through_blocks( $blocks, $reusable_block->ID ); + $style .= $this->collect_css_from_blocks( $blocks, $reusable_block->ID, $next_seen_refs ); } if ( ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { - $style .= $this->cycle_through_blocks( $block['innerBlocks'], $id ); + $style .= $this->collect_css_from_blocks( $block['innerBlocks'], $id, $seen_refs ); } } diff --git a/tests/test-blocks-css.php b/tests/test-blocks-css.php index 26c60754e..ec3695a06 100644 --- a/tests/test-blocks-css.php +++ b/tests/test-blocks-css.php @@ -240,4 +240,47 @@ public function test_archive_left_to_otter_when_active() { $this->assertStringNotContainsString( '.ticss-second{color:blue}', $this->render( new Blocks_CSS() ) ); } + + /** + * Synced patterns stop expanding when they reference themselves. + */ + public function test_synced_pattern_cycle_is_ignored() { + $pattern_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + ) + ); + + wp_update_post( + array( + 'ID' => $pattern_id, + 'post_content' => $this->block_with_css( '.ticss-pattern{color:red}' ) . '', + ) + ); + + $blocks = parse_blocks( '' ); + $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $pattern_id ); + + $this->assertSame( '.ticss-pattern{color:red}', $css ); + } + + /** + * Separate references to one synced pattern each contribute their CSS. + */ + public function test_repeated_synced_pattern_references_are_preserved() { + $pattern_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => $this->block_with_css( '.ticss-pattern{color:red}' ), + ) + ); + + $reference = ''; + $blocks = parse_blocks( $reference . $reference ); + $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $pattern_id ); + + $this->assertSame( '.ticss-pattern{color:red}.ticss-pattern{color:red}', $css ); + } } From 9e9feac0769d92898999da0d2893ab0f639059e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 18:15:10 +0200 Subject: [PATCH 08/15] fix: stop synced pattern cycles when loading pattern fonts and styles --- inc/css/class-block-frontend.php | 42 +++++++++---- tests/test-css-handler.php | 105 +++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+), 11 deletions(-) diff --git a/inc/css/class-block-frontend.php b/inc/css/class-block-frontend.php index 7d738d6a7..6ced1d660 100644 --- a/inc/css/class-block-frontend.php +++ b/inc/css/class-block-frontend.php @@ -46,6 +46,13 @@ class Block_Frontend extends Base_CSS { */ private $total_inline_size = 0; + /** + * Synced-pattern IDs being expanded in the current chain. + * + * @var array + */ + private $expanding_refs = array(); + /** * Initialize the class */ @@ -207,13 +214,34 @@ public function get_fonts( $fonts_list = array() ) { * @access public */ public function enqueue_reusable_fonts( $blocks ) { + $this->expand_reusable_blocks( $blocks, array( $this, 'enqueue_google_fonts' ) ); + } + + /** + * Run a callback for each synced pattern referenced in the blocks, skipping + * patterns already being expanded in the current chain. + * + * @param array> $blocks Blocks to inspect. + * @param callable(int): void $callback Receives the pattern ID. + * + * @return void + */ + private function expand_reusable_blocks( $blocks, callable $callback ) { foreach ( $blocks as $block ) { if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { - $this->enqueue_google_fonts( $block['attrs']['ref'] ); + $reference_id = absint( $block['attrs']['ref'] ); + + if ( isset( $this->expanding_refs[ $reference_id ] ) ) { + continue; + } + + $this->expanding_refs[ $reference_id ] = true; + $callback( $reference_id ); + unset( $this->expanding_refs[ $reference_id ] ); } if ( isset( $block['innerBlocks'] ) && ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { - $this->enqueue_reusable_fonts( $block['innerBlocks'] ); + $this->expand_reusable_blocks( $block['innerBlocks'], $callback ); } } } @@ -353,15 +381,7 @@ function () use ( $file_name, $file_url ) { * @access public */ public function enqueue_reusable_styles( $blocks ) { - foreach ( $blocks as $block ) { - if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { - $this->enqueue_styles( $block['attrs']['ref'] ); - } - - if ( isset( $block['innerBlocks'] ) && ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { - $this->enqueue_reusable_styles( $block['innerBlocks'] ); - } - } + $this->expand_reusable_blocks( $blocks, array( $this, 'enqueue_styles' ) ); } /** diff --git a/tests/test-css-handler.php b/tests/test-css-handler.php index d83575105..a3c59521e 100644 --- a/tests/test-css-handler.php +++ b/tests/test-css-handler.php @@ -161,6 +161,111 @@ public function test_widgets_css_fallback_print_escapes_style_tag(): void { $this->assertStringContainsString( '\\3c\\2fstyle', $output ); } + /** + * Fonts of a synced pattern that references itself are loaded without endless expansion. + */ + public function test_synced_pattern_cycle_fonts_are_loaded_once(): void { + $pattern_id = $this->create_self_referencing_pattern(); + update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + + Block_Frontend::instance()->enqueue_reusable_fonts( parse_blocks( '' ) ); + + $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $pattern_id, 'enqueued' ) ); + } + + /** + * Styles of a synced pattern that references itself are loaded without endless expansion. + */ + public function test_synced_pattern_cycle_styles_are_loaded_once(): void { + $pattern_id = $this->create_self_referencing_pattern(); + $file_path = $this->seed_post_stylesheet( $pattern_id, '.ticss-cycle{color:red}' ); + + remove_all_actions( 'wp_footer' ); + + try { + Block_Frontend::instance()->enqueue_reusable_styles( parse_blocks( '' ) ); + + ob_start(); + do_action( 'wp_footer' ); + $output = (string) ob_get_clean(); + } finally { + unlink( $file_path ); + } + + $this->assertStringContainsString( '.ticss-cycle{color:red}', $output ); + } + + /** + * Separate references to one synced pattern each load its styles. + */ + public function test_repeated_synced_pattern_styles_are_loaded_per_reference(): void { + $pattern_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => '

Pattern

', + ) + ); + $file_path = $this->seed_post_stylesheet( $pattern_id, '.ticss-repeat{color:blue}' ); + $reference = ''; + + remove_all_actions( 'wp_footer' ); + + try { + Block_Frontend::instance()->enqueue_reusable_styles( parse_blocks( $reference . $reference ) ); + + ob_start(); + do_action( 'wp_footer' ); + $output = (string) ob_get_clean(); + } finally { + unlink( $file_path ); + } + + $this->assertSame( 2, substr_count( $output, '.ticss-repeat{color:blue}' ), $output ); + } + + /** + * Create a published synced pattern whose content references itself. + * + * @return int Pattern ID. + */ + private function create_self_referencing_pattern(): int { + $pattern_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + ) + ); + + wp_update_post( + array( + 'ID' => $pattern_id, + 'post_content' => '

Pattern

', + ) + ); + + return $pattern_id; + } + + /** + * Give a post the saved CSS and stylesheet file a previous save would have left. + * + * @param int $post_id Post ID. + * @param string $css Saved CSS. + * @return string The stylesheet path. + */ + private function seed_post_stylesheet( int $post_id, string $css ): string { + $file_name = 'post-v2-' . $post_id . '-test'; + $dir = wp_upload_dir( null, false )['basedir'] . '/themeisle-gutenberg/'; + + update_post_meta( $post_id, '_themeisle_gutenberg_block_styles', $css ); + update_post_meta( $post_id, '_themeisle_gutenberg_block_stylesheet', $file_name ); + wp_mkdir_p( $dir ); + file_put_contents( $dir . $file_name . '.css', $css ); + + return $dir . $file_name . '.css'; + } + /** * Remove the stylesheet and meta generate_css_file() wrote for a post. * From 01ed9cd9726eadf413eb46d0cc53e2008886f6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 18:28:54 +0200 Subject: [PATCH 09/15] fix: keep a separate pattern chain per loader, release it on errors, and keep negative references unresolved --- inc/class-blocks-css.php | 2 +- inc/css/class-block-frontend.php | 34 +++---- tests/test-blocks-css.php | 53 ++++++++++- tests/test-css-handler.php | 150 +++++++++++++++++++++++++------ 4 files changed, 194 insertions(+), 45 deletions(-) diff --git a/inc/class-blocks-css.php b/inc/class-blocks-css.php index b80c311c5..f18c597bc 100644 --- a/inc/class-blocks-css.php +++ b/inc/class-blocks-css.php @@ -245,7 +245,7 @@ private function collect_css_from_blocks( $inner_blocks, $id, $seen_refs ) { } if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { - $reference_id = absint( $block['attrs']['ref'] ); + $reference_id = (int) $block['attrs']['ref']; if ( isset( $seen_refs[ $reference_id ] ) ) { continue; diff --git a/inc/css/class-block-frontend.php b/inc/css/class-block-frontend.php index 6ced1d660..9d7099e14 100644 --- a/inc/css/class-block-frontend.php +++ b/inc/css/class-block-frontend.php @@ -47,9 +47,9 @@ class Block_Frontend extends Base_CSS { private $total_inline_size = 0; /** - * Synced-pattern IDs being expanded in the current chain. + * Synced-pattern IDs being expanded in the current chain, per loader method. * - * @var array + * @var array> */ private $expanding_refs = array(); @@ -214,34 +214,38 @@ public function get_fonts( $fonts_list = array() ) { * @access public */ public function enqueue_reusable_fonts( $blocks ) { - $this->expand_reusable_blocks( $blocks, array( $this, 'enqueue_google_fonts' ) ); + $this->expand_reusable_blocks( $blocks, 'enqueue_google_fonts' ); } /** - * Run a callback for each synced pattern referenced in the blocks, skipping - * patterns already being expanded in the current chain. + * Run a loader method for each synced pattern referenced in the blocks, + * skipping patterns that method is already expanding in the current chain. * - * @param array> $blocks Blocks to inspect. - * @param callable(int): void $callback Receives the pattern ID. + * @param array> $blocks Blocks to inspect. + * @param 'enqueue_google_fonts'|'enqueue_styles' $loader Method that receives the pattern ID. * * @return void */ - private function expand_reusable_blocks( $blocks, callable $callback ) { + private function expand_reusable_blocks( $blocks, $loader ) { foreach ( $blocks as $block ) { if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { - $reference_id = absint( $block['attrs']['ref'] ); + $reference_id = (int) $block['attrs']['ref']; - if ( isset( $this->expanding_refs[ $reference_id ] ) ) { + if ( isset( $this->expanding_refs[ $loader ][ $reference_id ] ) ) { continue; } - $this->expanding_refs[ $reference_id ] = true; - $callback( $reference_id ); - unset( $this->expanding_refs[ $reference_id ] ); + $this->expanding_refs[ $loader ][ $reference_id ] = true; + + try { + $this->$loader( $reference_id ); + } finally { + unset( $this->expanding_refs[ $loader ][ $reference_id ] ); + } } if ( isset( $block['innerBlocks'] ) && ! empty( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) { - $this->expand_reusable_blocks( $block['innerBlocks'], $callback ); + $this->expand_reusable_blocks( $block['innerBlocks'], $loader ); } } } @@ -381,7 +385,7 @@ function () use ( $file_name, $file_url ) { * @access public */ public function enqueue_reusable_styles( $blocks ) { - $this->expand_reusable_blocks( $blocks, array( $this, 'enqueue_styles' ) ); + $this->expand_reusable_blocks( $blocks, 'enqueue_styles' ); } /** diff --git a/tests/test-blocks-css.php b/tests/test-blocks-css.php index ec3695a06..105cdd9b1 100644 --- a/tests/test-blocks-css.php +++ b/tests/test-blocks-css.php @@ -255,14 +255,63 @@ public function test_synced_pattern_cycle_is_ignored() { wp_update_post( array( 'ID' => $pattern_id, - 'post_content' => $this->block_with_css( '.ticss-pattern{color:red}' ) . '', + 'post_content' => $this->block_with_css( '.ticss-pattern{color:red}' ) . '' . $this->block_with_css( '.ticss-after{color:green}' ), ) ); $blocks = parse_blocks( '' ); $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $pattern_id ); - $this->assertSame( '.ticss-pattern{color:red}', $css ); + $this->assertSame( '.ticss-pattern{color:red}.ticss-after{color:green}', $css ); + } + + /** + * Synced patterns stop expanding when a nested block references a pattern earlier in the chain. + */ + public function test_indirect_synced_pattern_cycle_is_ignored() { + $first_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + ) + ); + $second_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => $this->block_with_css( '.ticss-second{color:blue}' ) . '
', + ) + ); + + wp_update_post( + array( + 'ID' => $first_id, + 'post_content' => $this->block_with_css( '.ticss-first{color:red}' ) . '', + ) + ); + + $blocks = parse_blocks( '' ); + $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $first_id ); + + $this->assertSame( '.ticss-first{color:red}.ticss-second{color:blue}', $css ); + } + + /** + * A negative reference does not load the pattern with the matching positive ID. + */ + public function test_negative_synced_pattern_reference_is_not_resolved() { + $pattern_id = self::factory()->post->create( + array( + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => $this->block_with_css( '.ticss-pattern{color:red}' ), + ) + ); + + $blocks = parse_blocks( '' ); + $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $pattern_id ); + + $this->assertSame( '', $css ); } /** diff --git a/tests/test-css-handler.php b/tests/test-css-handler.php index a3c59521e..5310441dc 100644 --- a/tests/test-css-handler.php +++ b/tests/test-css-handler.php @@ -162,28 +162,69 @@ public function test_widgets_css_fallback_print_escapes_style_tag(): void { } /** - * Fonts of a synced pattern that references itself are loaded without endless expansion. + * Font loading stops at a nested reference back to an earlier pattern and goes on with later references. */ - public function test_synced_pattern_cycle_fonts_are_loaded_once(): void { - $pattern_id = $this->create_self_referencing_pattern(); - update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + public function test_synced_pattern_cycle_fonts_stop_at_the_cycle(): void { + list( $first_id, $second_id, $third_id ) = $this->create_pattern_cycle(); + foreach ( array( $first_id, $second_id, $third_id ) as $pattern_id ) { + update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + } - Block_Frontend::instance()->enqueue_reusable_fonts( parse_blocks( '' ) ); + Block_Frontend::instance()->enqueue_reusable_fonts( parse_blocks( '' ) ); - $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $pattern_id, 'enqueued' ) ); + $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $first_id, 'enqueued' ) ); + $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $second_id, 'enqueued' ) ); + $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $third_id, 'enqueued' ) ); } /** - * Styles of a synced pattern that references itself are loaded without endless expansion. + * Style loading stops at a nested reference back to an earlier pattern and goes on with later references. */ - public function test_synced_pattern_cycle_styles_are_loaded_once(): void { - $pattern_id = $this->create_self_referencing_pattern(); - $file_path = $this->seed_post_stylesheet( $pattern_id, '.ticss-cycle{color:red}' ); + public function test_synced_pattern_cycle_styles_stop_at_the_cycle(): void { + list( $first_id, $second_id, $third_id ) = $this->create_pattern_cycle(); + $file_paths = array( + $this->seed_post_stylesheet( $first_id, '.ticss-first{color:red}' ), + $this->seed_post_stylesheet( $second_id, '.ticss-second{color:blue}' ), + $this->seed_post_stylesheet( $third_id, '.ticss-third{color:green}' ), + ); remove_all_actions( 'wp_footer' ); try { - Block_Frontend::instance()->enqueue_reusable_styles( parse_blocks( '' ) ); + Block_Frontend::instance()->enqueue_reusable_styles( parse_blocks( '' ) ); + + ob_start(); + do_action( 'wp_footer' ); + $output = (string) ob_get_clean(); + } finally { + array_map( 'unlink', $file_paths ); + } + + $this->assertStringContainsString( '.ticss-first{color:red}', $output ); + $this->assertStringContainsString( '.ticss-third{color:green}', $output ); + } + + /** + * A pattern whose fonts are loading can still have its styles loaded. + */ + public function test_style_loading_is_not_blocked_by_font_loading_of_the_same_pattern(): void { + $pattern_id = $this->create_pattern( '

Pattern

' ); + $reference = parse_blocks( '' ); + $file_path = $this->seed_post_stylesheet( $pattern_id, '.ticss-nested{color:red}' ); + update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + + remove_all_actions( 'wp_footer' ); + add_filter( + 'otter_blocks_google_fonts_url', + function ( $url ) use ( $reference ) { + Block_Frontend::instance()->enqueue_reusable_styles( $reference ); + + return $url; + } + ); + + try { + Block_Frontend::instance()->enqueue_reusable_fonts( $reference ); ob_start(); do_action( 'wp_footer' ); @@ -192,20 +233,60 @@ public function test_synced_pattern_cycle_styles_are_loaded_once(): void { unlink( $file_path ); } - $this->assertStringContainsString( '.ticss-cycle{color:red}', $output ); + $this->assertStringContainsString( '.ticss-nested{color:red}', $output ); + } + + /** + * A font load that throws does not leave the pattern marked as being expanded. + */ + public function test_failed_font_load_does_not_skip_the_pattern_later(): void { + $pattern_id = $this->create_pattern( '

Pattern

' ); + $reference = parse_blocks( '' ); + $throw = true; + update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + + add_filter( + 'otter_blocks_google_fonts_url', + function ( $url ) use ( &$throw ) { + if ( $throw ) { + $throw = false; + throw new RuntimeException( 'Font URL failed.' ); + } + + return $url; + } + ); + + try { + Block_Frontend::instance()->enqueue_reusable_fonts( $reference ); + } catch ( RuntimeException $exception ) { + $this->assertSame( 'Font URL failed.', $exception->getMessage() ); + } + + $this->assertFalse( $throw, 'The first font load must reach the throwing filter.' ); + + Block_Frontend::instance()->enqueue_reusable_fonts( $reference ); + + $this->assertTrue( wp_style_is( 'otter-google-fonts-' . $pattern_id, 'enqueued' ) ); + } + + /** + * A negative reference does not load the fonts of the pattern with the matching positive ID. + */ + public function test_negative_synced_pattern_reference_loads_no_fonts(): void { + $pattern_id = $this->create_pattern( '

Pattern

' ); + update_post_meta( $pattern_id, '_themeisle_gutenberg_block_fonts', array( array( 'fontfamily' => 'Roboto', 'fontvariant' => array( '400' ) ) ) ); + + Block_Frontend::instance()->enqueue_reusable_fonts( parse_blocks( '' ) ); + + $this->assertFalse( wp_style_is( 'otter-google-fonts-' . $pattern_id, 'enqueued' ) ); } /** * Separate references to one synced pattern each load its styles. */ public function test_repeated_synced_pattern_styles_are_loaded_per_reference(): void { - $pattern_id = self::factory()->post->create( - array( - 'post_type' => 'wp_block', - 'post_status' => 'publish', - 'post_content' => '

Pattern

', - ) - ); + $pattern_id = $this->create_pattern( '

Pattern

' ); $file_path = $this->seed_post_stylesheet( $pattern_id, '.ticss-repeat{color:blue}' ); $reference = ''; @@ -225,26 +306,41 @@ public function test_repeated_synced_pattern_styles_are_loaded_per_reference(): } /** - * Create a published synced pattern whose content references itself. + * Create a published synced pattern. * + * @param string $content Pattern content. * @return int Pattern ID. */ - private function create_self_referencing_pattern(): int { - $pattern_id = self::factory()->post->create( + private function create_pattern( string $content = '' ): int { + return self::factory()->post->create( array( - 'post_type' => 'wp_block', - 'post_status' => 'publish', + 'post_type' => 'wp_block', + 'post_status' => 'publish', + 'post_content' => $content, ) ); + } + + /** + * Create patterns first -> second -> first, where the second also references a third pattern after the cycle. + * Both references of the second pattern sit inside one Group block, the reference back to the first one first. + * + * @return int[] First, second and third pattern IDs. + */ + private function create_pattern_cycle(): array { + $paragraph = '

Pattern

'; + $first_id = $this->create_pattern(); + $third_id = $this->create_pattern( $paragraph ); + $second_id = $this->create_pattern( '
' ); wp_update_post( array( - 'ID' => $pattern_id, - 'post_content' => '

Pattern

', + 'ID' => $first_id, + 'post_content' => $paragraph . '', ) ); - return $pattern_id; + return array( $first_id, $second_id, $third_id ); } /** From a8e785520d2f71efaea9e9f2f82e326aebe5b170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 18:36:17 +0200 Subject: [PATCH 10/15] fix: skip synced pattern references that are not positive IDs --- inc/class-blocks-css.php | 2 +- inc/css/class-block-frontend.php | 3 ++- tests/test-blocks-css.php | 10 +++++----- tests/test-css-handler.php | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/inc/class-blocks-css.php b/inc/class-blocks-css.php index f18c597bc..01189c49c 100644 --- a/inc/class-blocks-css.php +++ b/inc/class-blocks-css.php @@ -247,7 +247,7 @@ private function collect_css_from_blocks( $inner_blocks, $id, $seen_refs ) { if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { $reference_id = (int) $block['attrs']['ref']; - if ( isset( $seen_refs[ $reference_id ] ) ) { + if ( $reference_id <= 0 || isset( $seen_refs[ $reference_id ] ) ) { continue; } diff --git a/inc/css/class-block-frontend.php b/inc/css/class-block-frontend.php index 9d7099e14..b50cac172 100644 --- a/inc/css/class-block-frontend.php +++ b/inc/css/class-block-frontend.php @@ -231,7 +231,8 @@ private function expand_reusable_blocks( $blocks, $loader ) { if ( 'core/block' === $block['blockName'] && ! empty( $block['attrs']['ref'] ) ) { $reference_id = (int) $block['attrs']['ref']; - if ( isset( $this->expanding_refs[ $loader ][ $reference_id ] ) ) { + // A non-positive ID is malformed; WordPress meta lookups would read it as its absolute value. + if ( $reference_id <= 0 || isset( $this->expanding_refs[ $loader ][ $reference_id ] ) ) { continue; } diff --git a/tests/test-blocks-css.php b/tests/test-blocks-css.php index 105cdd9b1..6e82f9fc8 100644 --- a/tests/test-blocks-css.php +++ b/tests/test-blocks-css.php @@ -279,7 +279,7 @@ public function test_indirect_synced_pattern_cycle_is_ignored() { array( 'post_type' => 'wp_block', 'post_status' => 'publish', - 'post_content' => $this->block_with_css( '.ticss-second{color:blue}' ) . '
', + 'post_content' => $this->block_with_css( '.ticss-second{color:blue}' ) . '
' . $this->block_with_css( '.ticss-nested{color:green}' ) . '
', ) ); @@ -293,11 +293,11 @@ public function test_indirect_synced_pattern_cycle_is_ignored() { $blocks = parse_blocks( '' ); $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $first_id ); - $this->assertSame( '.ticss-first{color:red}.ticss-second{color:blue}', $css ); + $this->assertSame( '.ticss-first{color:red}.ticss-second{color:blue}.ticss-nested{color:green}', $css ); } /** - * A negative reference does not load the pattern with the matching positive ID. + * A negative reference is skipped: it loads neither the pattern with the matching positive ID nor drops its siblings. */ public function test_negative_synced_pattern_reference_is_not_resolved() { $pattern_id = self::factory()->post->create( @@ -308,10 +308,10 @@ public function test_negative_synced_pattern_reference_is_not_resolved() { ) ); - $blocks = parse_blocks( '' ); + $blocks = parse_blocks( $this->block_with_css( '.ticss-before{color:blue}' ) . '' . $this->block_with_css( '.ticss-after{color:green}' ) ); $css = ( new Blocks_CSS() )->cycle_through_blocks( $blocks, $pattern_id ); - $this->assertSame( '', $css ); + $this->assertSame( '.ticss-before{color:blue}.ticss-after{color:green}', $css ); } /** diff --git a/tests/test-css-handler.php b/tests/test-css-handler.php index 5310441dc..3e44695fa 100644 --- a/tests/test-css-handler.php +++ b/tests/test-css-handler.php @@ -201,7 +201,8 @@ public function test_synced_pattern_cycle_styles_stop_at_the_cycle(): void { } $this->assertStringContainsString( '.ticss-first{color:red}', $output ); - $this->assertStringContainsString( '.ticss-third{color:green}', $output ); + // Once from the third pattern's own loader, once from the second pattern's saved-CSS read, which does not expand references. + $this->assertSame( 2, substr_count( $output, '.ticss-third{color:green}' ), $output ); } /** @@ -280,6 +281,7 @@ public function test_negative_synced_pattern_reference_loads_no_fonts(): void { Block_Frontend::instance()->enqueue_reusable_fonts( parse_blocks( '' ) ); $this->assertFalse( wp_style_is( 'otter-google-fonts-' . $pattern_id, 'enqueued' ) ); + $this->assertFalse( wp_style_is( 'otter-google-fonts--' . $pattern_id, 'enqueued' ) ); } /** From 02c5599e1b130ad7a4d5eb8fb0a38dc5cdb6b0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 20:09:02 +0200 Subject: [PATCH 11/15] feat: opt into the Themeisle SDK Support Hub --- composer.json | 2 +- composer.lock | 4 +- otter-blocks.php | 39 +++++++ readme.md | 2 +- readme.txt | 2 +- src/blocks/test/e2e/blocks/dashboard.spec.js | 17 +++ src/dashboard/components/Sidebar.js | 14 ++- tests/test-support-hub.php | 111 +++++++++++++++++++ 8 files changed, 182 insertions(+), 9 deletions(-) create mode 100644 tests/test-support-hub.php diff --git a/composer.json b/composer.json index a06437e3c..e2bfee152 100644 --- a/composer.json +++ b/composer.json @@ -73,7 +73,7 @@ }, "minimum-stability": "dev", "require": { - "codeinwp/themeisle-sdk": "^3.3.65", + "codeinwp/themeisle-sdk": "^3.3.70", "tubalmartin/cssmin": "^4.1", "wptt/webfont-loader": "^1.1", "sabberworm/php-css-parser": "^8.4", diff --git a/composer.lock b/composer.lock index 0a27b7e3a..67a965ca1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c01ca8d521c97d9b29fb7fce95c0002f", + "content-hash": "f7d4a66bc361fcc3052821cc86d88804", "packages": [ { "name": "codeinwp/themeisle-sdk", @@ -3143,5 +3143,5 @@ "platform-overrides": { "php": "7.4" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/otter-blocks.php b/otter-blocks.php index 71cb2b081..68c4958a9 100644 --- a/otter-blocks.php +++ b/otter-blocks.php @@ -90,6 +90,45 @@ function () { } ); +/* + * Opts into the SDK Support Hub: one Help button on Otter's screens and the + * deactivation window. The dashboard and Form Submissions screens already fire + * `themeisle_internal_page`, so no `pages` list is needed. + */ +add_filter( + 'otter_blocks_support_hub_metadata', + function () { + return array( + 'is_pro' => \ThemeIsle\GutenbergBlocks\Pro::is_pro_active(), + 'links' => array( + array( + 'icon' => 'book-alt', + 'text' => __( 'Documentation', 'otter-blocks' ), + 'url' => \ThemeIsle\GutenbergBlocks\Pro::get_docs_url(), + ), + array( + 'icon' => 'groups', + 'text' => __( 'Community Forum', 'otter-blocks' ), + 'url' => 'https://wordpress.org/support/plugin/otter-blocks/', + ), + ), + ); + } +); + +/* + * Otter also fires `themeisle_internal_page` in the block editor, which would put + * the Help button on every post, site and widget editor. Keep it to Otter's screens. + */ +add_filter( + 'otter_blocks_hide_support_hub', + function ( $hide ) { + global $pagenow; + + return $hide || in_array( $pagenow, array( 'post.php', 'post-new.php', 'site-editor.php', 'widgets.php' ), true ); + } +); + add_filter( 'themeisle_sdk_compatibilities/' . basename( OTTER_BLOCKS_PATH ), function ( $compatibilities ) { diff --git a/readme.md b/readme.md index a5832f3c9..89d85c1dc 100644 --- a/readme.md +++ b/readme.md @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme. ### Where can I get help? ### -If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. +If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. ### What are the Patterns and how can I use them? ### diff --git a/readme.txt b/readme.txt index c8d29109e..b6775c199 100644 --- a/readme.txt +++ b/readme.txt @@ -330,7 +330,7 @@ Sure, Otter is compatible with any WordPress theme. = Where can I get help? = -If you encounter any difficulties or if you have questions about Otter, you can create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. +If you encounter any difficulties or if you have questions about Otter, you can ask our support team from the **Help** button on the Otter dashboard, or create a ticket on our [support forum](https://wordpress.org/support/plugin/otter-blocks/). Also, feel free to check our [documentation](https://docs.themeisle.com/article/1478-otter-blocks-documentation) to find out more about the features within the plugin and how to use it to its full potential. = What are the Patterns and how can I use them? = diff --git a/src/blocks/test/e2e/blocks/dashboard.spec.js b/src/blocks/test/e2e/blocks/dashboard.spec.js index e10d35b24..b106609b3 100644 --- a/src/blocks/test/e2e/blocks/dashboard.spec.js +++ b/src/blocks/test/e2e/blocks/dashboard.spec.js @@ -170,4 +170,21 @@ test.describe( 'Dashboard', () => { await countdownCard.getByRole( 'checkbox' ).click(); await expect( countdownCard.getByRole( 'checkbox' ) ).toBeChecked(); }); + + test( 'free sidebar opens the Help panel and keeps the community forum', async({ page }) => { + const contact = page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }); + + await expect( contact ).toHaveAttribute( 'data-ti-support', 'dashboard' ); + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Community Forum' }) ).toHaveAttribute( 'href', 'https://wordpress.org/support/plugin/otter-blocks/' ); + + await contact.click(); + + await expect( page.locator( '.ti-support-panel' ) ).toBeVisible(); + }); + + test( 'block editor shows no Help launcher', async({ admin, page }) => { + await admin.createNewPost(); + + await expect( page.locator( '.ti-support-launcher' ) ).toHaveCount( 0 ); + }); }); diff --git a/src/dashboard/components/Sidebar.js b/src/dashboard/components/Sidebar.js index 2c94f7f5e..482317428 100644 --- a/src/dashboard/components/Sidebar.js +++ b/src/dashboard/components/Sidebar.js @@ -76,9 +76,7 @@ const Sidebar = ({ setTab }) => { const isProLicenseActive = Boolean( window.otterObj.hasPro ) && 'valid' === window.otterObj?.license?.valid; - - const supportLink = isProLicenseActive ? 'https://store.themeisle.com/' : 'https://wordpress.org/support/plugin/otter-blocks'; - const supportLabel = isProLicenseActive ? __( 'Contact Pro Support', 'otter-blocks' ) : __( 'Support', 'otter-blocks' ); + const forumLink = 'https://wordpress.org/support/plugin/otter-blocks/'; return ( @@ -122,7 +120,15 @@ const Sidebar = ({ title={ __( 'Useful links', 'otter-blocks' ) } > diff --git a/tests/test-support-hub.php b/tests/test-support-hub.php new file mode 100644 index 000000000..4a8689fc0 --- /dev/null +++ b/tests/test-support-hub.php @@ -0,0 +1,111 @@ +assertIsArray( $data ); + $this->assertSame( array( 'is_pro', 'links' ), array_keys( $data ) ); + } + + /** + * The footer links point to Otter's docs and wordpress.org forum. + */ + public function test_links_point_to_otter() { + $links = apply_filters( 'otter_blocks_support_hub_metadata', array() )['links']; + + $this->assertSame( + array( + 'https://docs.themeisle.com/otter-page-builder-blocks-extensions/otter-blocks-documentation', + 'https://wordpress.org/support/plugin/otter-blocks/', + ), + wp_list_pluck( $links, 'url' ) + ); + foreach ( $links as $link ) { + $this->assertNotEmpty( $link['icon'] ); + $this->assertNotEmpty( $link['text'] ); + } + } + + /** + * Messages are tagged as Pro only while the Pro license is valid. + */ + public function test_is_pro_needs_a_valid_license() { + add_filter( 'product_otter_license_status', array( $this, 'expired_license' ) ); + $this->assertFalse( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); + remove_filter( 'product_otter_license_status', array( $this, 'expired_license' ) ); + + add_filter( 'product_otter_license_status', array( $this, 'valid_license' ) ); + $this->assertSame( Pro::is_pro_installed(), apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); + remove_filter( 'product_otter_license_status', array( $this, 'valid_license' ) ); + } + + /** + * The Help button stays off the block editors, which also count as Otter screens. + * + * @dataProvider editor_screens + * + * @param string $pagenow Admin page file. + */ + public function test_hub_is_hidden_in_block_editors( $pagenow ) { + $GLOBALS['pagenow'] = $pagenow; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + $this->assertTrue( apply_filters( 'otter_blocks_hide_support_hub', false ) ); + } + + /** + * Block editor admin pages. + * + * @return array> + */ + public function editor_screens() { + return array( + 'post editor' => array( 'post.php' ), + 'new post' => array( 'post-new.php' ), + 'site editor' => array( 'site-editor.php' ), + 'widget editor' => array( 'widgets.php' ), + ); + } + + /** + * The Help button shows on Otter's own screens, and a site can still hide it. + */ + public function test_hub_is_shown_on_otter_screens() { + $GLOBALS['pagenow'] = 'admin.php'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited + + $this->assertFalse( apply_filters( 'otter_blocks_hide_support_hub', false ) ); + $this->assertTrue( apply_filters( 'otter_blocks_hide_support_hub', true ) ); + } + + /** + * A license status the SDK reports for an expired key. + * + * @return string + */ + public function expired_license() { + return 'expired'; + } + + /** + * A license status the SDK reports for a valid key. + * + * @return string + */ + public function valid_license() { + return 'valid'; + } +} From bb4cc90a1cad7dbb1e720167caa655a69d9fc2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 20:16:15 +0200 Subject: [PATCH 12/15] fix: read the stored Pro license for the Support Hub Pro flag --- otter-blocks.php | 4 +++- tests/test-support-hub.php | 47 ++++++++++++++++---------------------- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/otter-blocks.php b/otter-blocks.php index 68c4958a9..e2f405d18 100644 --- a/otter-blocks.php +++ b/otter-blocks.php @@ -99,7 +99,9 @@ function () { 'otter_blocks_support_hub_metadata', function () { return array( - 'is_pro' => \ThemeIsle\GutenbergBlocks\Pro::is_pro_active(), + // The SDK reads this while loading Otter, before Otter Pro's Licenser adds the + // product_otter_license_status filter, so read the stored license directly. + 'is_pro' => defined( 'OTTER_PRO_BASEFILE' ) && class_exists( '\ThemeisleSDK\Modules\Licenser' ) && \ThemeisleSDK\Modules\Licenser::is_valid( OTTER_PRO_BASEFILE ), 'links' => array( array( 'icon' => 'book-alt', diff --git a/tests/test-support-hub.php b/tests/test-support-hub.php index 4a8689fc0..f06966a67 100644 --- a/tests/test-support-hub.php +++ b/tests/test-support-hub.php @@ -5,8 +5,6 @@ * @package gutenberg-blocks */ -use ThemeIsle\GutenbergBlocks\Pro; - /** * Support Hub opt-in tests. */ @@ -42,16 +40,29 @@ public function test_links_point_to_otter() { } /** - * Messages are tagged as Pro only while the Pro license is valid. + * Messages are tagged as Pro only while the stored Pro license is valid, whatever + * the order in which the SDK loads Otter and Otter Pro. + * + * @runInSeparateProcess + * @preserveGlobalState disabled */ - public function test_is_pro_needs_a_valid_license() { - add_filter( 'product_otter_license_status', array( $this, 'expired_license' ) ); + public function test_is_pro_reads_the_stored_pro_license() { + if ( ! defined( 'OTTER_PRO_BASEFILE' ) ) { + define( 'OTTER_PRO_BASEFILE', dirname( __DIR__ ) . '/plugins/otter-pro/otter-pro.php' ); + } + // The test bootstrap loads Composer before WordPress, so the SDK's load.php skips itself. + $sdk = dirname( __DIR__ ) . '/vendor/codeinwp/themeisle-sdk/src/'; + foreach ( array( 'Loader.php', 'Product.php', 'Common/Abstract_module.php', 'Modules/Licenser.php' ) as $file ) { + require_once $sdk . $file; + } + // No Licenser filter is registered, as when Otter loads before Otter Pro. + remove_all_filters( 'product_otter_license_status' ); + + update_option( 'otter_pro_license_data', (object) array( 'license' => 'expired' ) ); $this->assertFalse( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); - remove_filter( 'product_otter_license_status', array( $this, 'expired_license' ) ); - add_filter( 'product_otter_license_status', array( $this, 'valid_license' ) ); - $this->assertSame( Pro::is_pro_installed(), apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); - remove_filter( 'product_otter_license_status', array( $this, 'valid_license' ) ); + update_option( 'otter_pro_license_data', (object) array( 'license' => 'valid' ) ); + $this->assertTrue( apply_filters( 'otter_blocks_support_hub_metadata', array() )['is_pro'] ); } /** @@ -90,22 +101,4 @@ public function test_hub_is_shown_on_otter_screens() { $this->assertFalse( apply_filters( 'otter_blocks_hide_support_hub', false ) ); $this->assertTrue( apply_filters( 'otter_blocks_hide_support_hub', true ) ); } - - /** - * A license status the SDK reports for an expired key. - * - * @return string - */ - public function expired_license() { - return 'expired'; - } - - /** - * A license status the SDK reports for a valid key. - * - * @return string - */ - public function valid_license() { - return 'valid'; - } } From 2fc146fe2e382e63401c5c0e2460ac85fba25770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 20:33:24 +0200 Subject: [PATCH 13/15] test: run the Support Hub license test in the main process --- tests/test-support-hub.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test-support-hub.php b/tests/test-support-hub.php index f06966a67..c9fa03c88 100644 --- a/tests/test-support-hub.php +++ b/tests/test-support-hub.php @@ -42,9 +42,6 @@ public function test_links_point_to_otter() { /** * Messages are tagged as Pro only while the stored Pro license is valid, whatever * the order in which the SDK loads Otter and Otter Pro. - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function test_is_pro_reads_the_stored_pro_license() { if ( ! defined( 'OTTER_PRO_BASEFILE' ) ) { From 5739406f4d0e01a35602900726f425616888997c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Thu, 12 Nov 2026 21:01:04 +0200 Subject: [PATCH 14/15] test: switch off the stubbed Pro license for the free sidebar case --- src/blocks/test/e2e/blocks/dashboard.spec.js | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/blocks/test/e2e/blocks/dashboard.spec.js b/src/blocks/test/e2e/blocks/dashboard.spec.js index b106609b3..1efecc109 100644 --- a/src/blocks/test/e2e/blocks/dashboard.spec.js +++ b/src/blocks/test/e2e/blocks/dashboard.spec.js @@ -171,15 +171,29 @@ test.describe( 'Dashboard', () => { await expect( countdownCard.getByRole( 'checkbox' ) ).toBeChecked(); }); - test( 'free sidebar opens the Help panel and keeps the community forum', async({ page }) => { - const contact = page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }); + test( 'free sidebar opens the Help panel and keeps the community forum', async({ admin, otterUtils, page }) => { + // Global setup stubs a valid Pro license, which shows Contact Pro Support instead. + await otterUtils.deactivatePro(); - await expect( contact ).toHaveAttribute( 'data-ti-support', 'dashboard' ); - await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Community Forum' }) ).toHaveAttribute( 'href', 'https://wordpress.org/support/plugin/otter-blocks/' ); + try { + await admin.visitAdminPage( 'admin.php?page=otter' ); + + const contact = page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }); + + await expect( contact ).toHaveAttribute( 'data-ti-support', 'dashboard' ); + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Community Forum' }) ).toHaveAttribute( 'href', 'https://wordpress.org/support/plugin/otter-blocks/' ); + + await contact.click(); - await contact.click(); + await expect( page.locator( '.ti-support-panel' ) ).toBeVisible(); + } finally { + await otterUtils.activatePro(); + } + }); - await expect( page.locator( '.ti-support-panel' ) ).toBeVisible(); + test( 'licensed Pro sidebar keeps Contact Pro Support', async({ page }) => { + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Pro Support' }) ).toHaveAttribute( 'href', 'https://store.themeisle.com/' ); + await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }) ).toHaveCount( 0 ); }); test( 'block editor shows no Help launcher', async({ admin, page }) => { From a60d51ac7e9fe3746fa9373254955e6a78b7a7c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vytis=20Bulkevi=C4=8Dius?= Date: Fri, 13 Nov 2026 09:49:44 +0200 Subject: [PATCH 15/15] test: make the Support Hub visibility checks fail without the change --- src/blocks/test/e2e/blocks/dashboard.spec.js | 7 ++-- tests/test-support-hub.php | 35 ++++++++------------ 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/blocks/test/e2e/blocks/dashboard.spec.js b/src/blocks/test/e2e/blocks/dashboard.spec.js index 1efecc109..b62d72f18 100644 --- a/src/blocks/test/e2e/blocks/dashboard.spec.js +++ b/src/blocks/test/e2e/blocks/dashboard.spec.js @@ -196,9 +196,12 @@ test.describe( 'Dashboard', () => { await expect( page.locator( '.otter-info-links' ).getByRole( 'link', { name: 'Contact Support' }) ).toHaveCount( 0 ); }); - test( 'block editor shows no Help launcher', async({ admin, page }) => { + test( 'Help launcher shows on the dashboard but not in the block editor', async({ admin, page }) => { + await expect( page.locator( '.ti-support-launcher' ) ).toBeVisible(); + await admin.createNewPost(); - await expect( page.locator( '.ti-support-launcher' ) ).toHaveCount( 0 ); + // The SDK prints this container in admin_footer whenever the hub loads. + await expect( page.locator( '#ti-support-hub' ) ).toHaveCount( 0 ); }); }); diff --git a/tests/test-support-hub.php b/tests/test-support-hub.php index c9fa03c88..65159c621 100644 --- a/tests/test-support-hub.php +++ b/tests/test-support-hub.php @@ -63,39 +63,32 @@ public function test_is_pro_reads_the_stored_pro_license() { } /** - * The Help button stays off the block editors, which also count as Otter screens. + * The Help button stays off the block editors, which also count as Otter screens, and shows on Otter's own screens. * - * @dataProvider editor_screens + * @dataProvider admin_screens * * @param string $pagenow Admin page file. + * @param bool $hidden Whether the Help button is hidden there. */ - public function test_hub_is_hidden_in_block_editors( $pagenow ) { + public function test_hub_is_hidden_only_in_block_editors( $pagenow, $hidden ) { $GLOBALS['pagenow'] = $pagenow; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited - $this->assertTrue( apply_filters( 'otter_blocks_hide_support_hub', false ) ); + $this->assertSame( $hidden, apply_filters( 'otter_blocks_hide_support_hub', false ) ); } /** - * Block editor admin pages. + * Admin pages and whether the Help button is hidden on them. * - * @return array> + * @return array */ - public function editor_screens() { + public function admin_screens() { return array( - 'post editor' => array( 'post.php' ), - 'new post' => array( 'post-new.php' ), - 'site editor' => array( 'site-editor.php' ), - 'widget editor' => array( 'widgets.php' ), + 'post editor' => array( 'post.php', true ), + 'new post' => array( 'post-new.php', true ), + 'site editor' => array( 'site-editor.php', true ), + 'widget editor' => array( 'widgets.php', true ), + 'Otter screen' => array( 'admin.php', false ), + 'post list' => array( 'edit.php', false ), ); } - - /** - * The Help button shows on Otter's own screens, and a site can still hide it. - */ - public function test_hub_is_shown_on_otter_screens() { - $GLOBALS['pagenow'] = 'admin.php'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited - - $this->assertFalse( apply_filters( 'otter_blocks_hide_support_hub', false ) ); - $this->assertTrue( apply_filters( 'otter_blocks_hide_support_hub', true ) ); - } }