WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.47k stars 4.18k forks source link

Can't conditionally load blocks when registering a block pattern #57320

Open MaggieCabrera opened 10 months ago

MaggieCabrera commented 10 months ago

Description

Blocks are not registered when creating a block pattern, so we can no longer conditionally load blocks depending on if they are registered or not. If something has changed and this is no longer possible, we should update the handbook.

Step-by-step reproduction instructions

  1. Install a plugin that installs a non-core block. I used Starscape.
  2. Follow the instructions in the handbook under Conditionally loading third-party blocks but replace the core/paragraph with the non-core block.
  3. The block should render, but it doesn't

Screenshots, screen recording, code snippet

This is the code that should go inside the pattern file

<?php if ( WP_Block_Type_Registry::get_instance()->is_registered( 'a8c/starscape' ) ) : ?>
    <!-- wp:paragraph {"align":"center"} -->
    <p class="has-text-align-center"><?php esc_html_e( "My starscape block should go here", 'themeslug' ) ?></p>
    <!-- /wp:paragraph -->
<?php endif ?>

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

t-hamano commented 10 months ago

I was able to reproduce it. I've tested it with multiple third-party blocks, but conditional read doesn't seem to work.