Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .dev/tests/phpunit/includes/test-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 4 additions & 4 deletions includes/class-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 ) {
Expand Down