From 7fa445a36d7736adb012cf47bf48e4f254a9b9d8 Mon Sep 17 00:00:00 2001 From: Faisal Ahammad Date: Thu, 30 Jul 2026 18:01:22 +0600 Subject: [PATCH] fix: prevent wp-edit-post from loading in the customizer block widgets editor - Extend existing widgets.php dependency guards to also cover customize.php, preventing JS conflicts with themes like Blocksy in the Appearance > Customize block widgets editor. - Add PHPUnit test to verify wp-edit-post and wp-editor are stripped from script dependencies when $pagenow is customize.php. Fixes #2627 --- .../includes/test-coblocks-block-assets.php | 38 +++++++++++++++++++ includes/class-coblocks-block-assets.php | 8 ++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.dev/tests/phpunit/includes/test-coblocks-block-assets.php b/.dev/tests/phpunit/includes/test-coblocks-block-assets.php index e7c312a6bb1..826b027d230 100644 --- a/.dev/tests/phpunit/includes/test-coblocks-block-assets.php +++ b/.dev/tests/phpunit/includes/test-coblocks-block-assets.php @@ -119,6 +119,44 @@ public function test_editor_assets_scripts() { } } + /** + * Test that wp-edit-post dependency is stripped on customize.php + * to prevent conflicts with themes like Blocksy in the customizer. + */ + public function test_wp_edit_post_stripped_on_customize_php() { + global $pagenow, $wp_scripts; + + $previous_pagenow = $pagenow ?? null; + + try { + $pagenow = 'customize.php'; + $this->go_to( '/wp-admin/customize.php' ); + + $this->coblocks_block_assets->editor_assets(); + + // coblocks-editor should still be registered. + $this->assertTrue( array_key_exists( 'coblocks-editor', $wp_scripts->registered ) ); + + // wp-edit-post must not appear in coblocks-editor dependencies. + $this->assertNotContains( 'wp-edit-post', $wp_scripts->registered['coblocks-editor']->deps ); + + // wp-edit-post and wp-editor must not appear in any coblocks-N chunk dependencies. + $matching_chunks = 0; + foreach ( $wp_scripts->registered as $handle => $script ) { + if ( preg_match( '/^coblocks-\d+$/', $handle ) ) { + ++$matching_chunks; + $this->assertNotContains( 'wp-edit-post', $script->deps ); + $this->assertNotContains( 'wp-editor', $script->deps ); + } + } + + // Ensure the loop above did not pass vacuously. + $this->assertGreaterThan( 0, $matching_chunks, 'No coblocks-N chunks were registered to verify.' ); + } finally { + $pagenow = $previous_pagenow; + } + } + /** * Test the editor asset scripts localized data */ diff --git a/includes/class-coblocks-block-assets.php b/includes/class-coblocks-block-assets.php index eef7f0e5fe6..1615a28243a 100644 --- a/includes/class-coblocks-block-assets.php +++ b/includes/class-coblocks-block-assets.php @@ -203,8 +203,8 @@ public function editor_assets() { global $pagenow; - // Prevent wp-edit-post and coblocks settings/patterns plugins from loading on the widgets.php page. - if ( 'widgets.php' === $pagenow ) { + // Prevent wp-edit-post and coblocks settings/patterns plugins from loading on the widgets.php or customize.php page. + if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { $script_key = array_search( 'wp-edit-post', $asset_file['dependencies'], true ); if ( false !== $script_key ) { @@ -233,8 +233,8 @@ public function editor_assets() { $filepath = 'dist/' . $name; $asset_file = $this->get_asset_file( $filepath ); - // Prevent wp-editor from loading on the widgets.php page. - if ( 'widgets.php' === $pagenow ) { + // Prevent wp-editor from loading on the widgets.php or customize.php page. + if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { $script_key = array_search( 'wp-editor', $asset_file['dependencies'], true ); if ( false !== $script_key ) {