WordPress / gutenberg

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

`register_block_core_navigation_link` should not be do as `init` hook #49678

Open obache opened 1 year ago

obache commented 1 year ago

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

ndiego commented 1 year ago

I have been able to replicate this issue. For reference, this feature was introduced in #29095.

gaambo commented 1 year ago

FYI: This has been fixed in https://github.com/WordPress/gutenberg/pull/54801

obache commented 1 year ago

How about unregister_post_type() and unregister_taxonomy() ?

gaambo commented 1 year ago

How about unregister_post_type() and unregister_taxonomy() ?

@obache That's a great point that I've missed. I've added a new PR which fixes this as well: https://github.com/WordPress/gutenberg/pull/56100

annezazu commented 11 months ago

As part of this larger sweep of high priority issues, I'm removing the label here as the main part of the issue has been resolved with an additional PR in progress and already approved to iterate. Re-running the jobs to see if we can get that merged sooner rather than later. Let me know if you need more help getting this through @gaambo too :)

gaambo commented 10 months ago

56100 is now merged so unregistering post types / taxonomies also works correctly now 🙂