Gutenberg: block patterns missing when use allowed_block_types_all filter wp 5.8
-
Hi,
I have been successfully using the allowed_block_types filter on a few projects over the past year or so, in order to restrict blocks for clients.
It has been working fine and is still working OK for the purpose of allowing only certain blocks.
However, on a recent WordPress update (5.8 I think) using this filter has stopped my registered block patterns from showing in the editor.
I have looked as best I can in the release notes, google and forums – I notice that the filter is deprecated and replaced with allowed_block_types_all but that doesn’t help.
I can also confirm that it happens on clean twentytwentyone install with the following example test code:
function filter_allowed_block_types_when_post_provided( $allowed_block_types, $editor_context ) { if ( ! empty( $editor_context->post ) ) { return array( 'core/group', 'core/image', 'core/paragraph', 'core/columns', 'core/heading', 'core/list', 'core/gallery', 'core/quote', 'core/video', 'core/pullquote', 'core/media-text', 'core/separator', 'core/search', 'core/embed', 'core/spacer', 'core-embed/twitter', 'core-embed/youtube', 'core-embed/facebook', 'core-embed/instagram', 'core/table', 'core/html', 'core/shortcode', ); } return $allowed_block_types; } add_filter( 'allowed_block_types_all', 'filter_allowed_block_types_when_post_provided', 10, 2 ); function wpdocs_register_my_patterns() { register_block_pattern( 'wpdocs-my-plugin/my-awesome-pattern', array( 'title' => __( 'Two buttons TEST', 'wpdocs-my-plugin' ), 'description' => _x( 'Two horizontal buttons, the left button is filled in, and the right button is outlined.', 'Block pattern description', 'wpdocs-my-plugin' ), 'content' => "<!-- wp:buttons {\"align\":\"center\"} -->\n<div class=\"wp-block-buttons aligncenter\"><!-- wp:button {\"backgroundColor\":\"very-dark-gray\",\"borderRadius\":0} -->\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link has-background has-very-dark-gray-background-color no-border-radius\">" . esc_html__( 'Button One', 'wpdocs-my-plugin' ) . "</a></div>\n<!-- /wp:button -->\n\n<!-- wp:button {\"textColor\":\"very-dark-gray\",\"borderRadius\":0,\"className\":\"is-style-outline\"} -->\n<div class=\"wp-block-button is-style-outline\"><a class=\"wp-block-button__link has-text-color has-very-dark-gray-color no-border-radius\">" . esc_html__( 'Button Two', 'wpdocs-my-plugin' ) . "</a></div>\n<!-- /wp:button --></div>\n<!-- /wp:buttons -->", ) ); } add_action( 'init', 'wpdocs_register_my_patterns' );
Would appreciate if anyone can help or has advice?
The page I need help with: [log in to see the link]
- The topic ‘Gutenberg: block patterns missing when use allowed_block_types_all filter wp 5.8’ is closed to new replies.