Skip to content

Commit

Permalink
Load structured data blocks assets in site editor
Browse files Browse the repository at this point in the history
* Change enqueue method to newer `enqueue_block_assets`. This also affects the frontend, which we do not want, hence the `is_admin` check
* Add styling dependencies on `dashicons` and `forms`, these are missing in the site editor: not sure if a WP components bug, but this solves it
* Add fieldset (`.schema-how-to-duration`) styling (copied from WP common), removing the border around the duration
  • Loading branch information
igorschoester authored and enricobattocchi committed Apr 23, 2024
1 parent 447fe11 commit 01f20eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
6 changes: 5 additions & 1 deletion admin/class-admin-asset-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,11 @@ protected function styles_to_be_registered() {
[
'name' => 'structured-data-blocks',
'src' => 'structured-data-blocks-' . $flat_version,
'deps' => [ 'wp-edit-blocks' ],
'deps' => [
'dashicons',
'forms',
'wp-edit-blocks',
],
],
[
'name' => 'elementor',
Expand Down
6 changes: 6 additions & 0 deletions css/src/structured-data-blocks.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion src/integrations/blocks/structured-data-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(
* @return void
*/
public function register_hooks() {
\add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_assets' ] );
\add_action( 'enqueue_block_assets', [ $this, 'enqueue_block_editor_assets' ] );
$this->register_blocks();
}

Expand Down Expand Up @@ -148,6 +148,11 @@ public function register_blocks() {
* @return void
*/
public function enqueue_block_editor_assets() {
// Bail if not in the admin.
if ( ! \is_admin() ) {
return;
}

/**
* Filter: 'wpseo_enable_structured_data_blocks' - Allows disabling Yoast's schema blocks entirely.
*
Expand Down

0 comments on commit 01f20eb

Please sign in to comment.