Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allowed_block_types filter for a Custom post type doesn't add the inserter if 'core/paragraph' is not included in the list #9199

Closed
garciaalvaro opened this issue Aug 21, 2018 · 4 comments
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed

Comments

@garciaalvaro
Copy link

Describe the bug
Limiting the allowed block types (as described here) needs 'core/paragraph' to be included in the list, otherwise the inserter does not appear. I noticed this behaviour only with Custom Post Types. It seems to work correctly with the default Post.

To Reproduce
Steps to reproduce the behavior:

  1. Register a Custom post type.
  2. Include the allowed_block_types filter:
function my_plugin_allowed_block_types( $allowed_block_types, $post ) {
    if ( $post->post_type !== 'my_custom_post_type' ) {
        return $allowed_block_types;
    }
    return array( 'core/image', 'core/gallery' );
}
add_filter( 'allowed_block_types', 'my_plugin_allowed_block_types', 10, 2 );
  1. Create a new Custom post
  2. No inserter bar appears, the only way to add blocks is using the top left button.

Expected behavior
The inserter bar should appear.

Screenshots

Additional context

  • WordPress 4.9.8
  • Gutenberg 3.6.2
@designsimply
Copy link
Member

There is an open task to add a default appender that is not paragraph based at #8589, and I would like to consolidate there because I think it will resolve this issue as well. Please let me know if that's not the case!

@designsimply designsimply added [Feature] Inserter The main way to insert blocks using the + button in the editing interface [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed labels Aug 21, 2018
@garciaalvaro
Copy link
Author

Thanks for the answer. Im still getting to fully understand how the plugin works.
But if I understood correctly the link you provide is related to nested blocks. This issue however is about allowed type of blocks in the editor (root level?), although the issue might also happen inside nested blocks.

The thing is, it works correctly in default Posts. Even if there is no 'core/paragraph', the inserter appears and only the allowed blocks show in the menu. But in Custom Post types the behaviour is as described (the inserter doesn't appear).

Hope it makes sense, please let me know otherwise.

@designsimply
Copy link
Member

I asked for clarification in a comment on the issue to see whether that solution would also cover CPTs in addition to nested/inner blocks.

@garciaalvaro
Copy link
Author

Great, Thanks @designsimply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed
Projects
None yet
Development

No branches or pull requests

2 participants