Skip to content

register_block_core_navigation_link should not be do as init hook #49678

@obache

Description

@obache

Description

register_block_core_navigation_link() of navigation-link block will use registered post_type and taxonomy, then register variations of navigation-link block. It will be done as init hook with default priority now.

But from functions references

register_post_type(): Post type registrations should not be hooked before the ‘init’ action.
register_taxnomy(): Do not use before the ‘init’ hook.

So custom post types and taxonomies may not be registered yet at register_block_core_navigation_link() doing, and such post type links and taxonomy archive links are not appeared as blocks for navigation menu.

In "Registering Custom Post Types" of "Plugin Handbook", custom post type is registered as init hook with default priority 10, so it should be usual timing to register custom post type for plugins , but archive link for such registered post type will not be appeared as blocks. If post types is registered as init hook with priority 9, such post types will be appeared.

register_block_core_navigation_link() should be done after init hook, or lower priority.

Step-by-step reproduction instructions

  1. register a custom post type in init hook with default priority
  2. add navigation menu in Post Edit admin screen
  3. in navigation block settings "Menu", try to add block and "Browse all blocks" in left side navi "block inserter"
  4. registered custom post type is not in "THEMES" blocks.

Screenshots, screen recording, code snippet

No response

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions