Skip to content
Merged
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
13 changes: 13 additions & 0 deletions compat/block-editor/widget-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,22 @@ private function prepare_widget_data() : void {
$this->so_widgets = array_merge( $so_widgets, $third_party_widgets );
}

/**
* Enqueue block editor assets for SiteOrigin Widget Blocks.
*
* This method enqueues the necessary scripts and styles for the block editor.
* It also localizes widget data for use in the editor.
*/
public function enqueue_widget_block_editor_assets() {
$current_screen = function_exists( 'get_current_screen' ) ? get_current_screen() : false;

if (
empty( $current_screen ) ||
! in_array( $current_screen->base, array( 'post', 'site-editor', 'widgets' ) )
) {
return;
}

wp_enqueue_script(
'sowb-register-widget-blocks',
plugins_url( 'register-widget-blocks' . SOW_BUNDLE_JS_SUFFIX . '.js', __FILE__ ),
Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/wb-form-field-site-editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,22 @@ test(
}
}
);

/**
* Validates that editor scripts aren't being loaded on the frontend.
*
* @param {Object} page The Playwright page object.
*/
test(
'Test that editor scripts are not loaded on the frontend.',
async ( { page } ) => {
await page.goto( '/' );

const hasBlockCss = await page.$( '#sowb-widget-block-css' ) !== null;
const hasBlockJs = await page.$( '#sowb-widget-block-js' ) !== null;

expect( hasBlockCss ).toBe( false );
expect( hasBlockJs ).toBe( false );

}
);