Skip to content

Post Terms Block: Custom Taxonomies variations are not registered correctly #52569

@gaambo

Description

@gaambo

Description

In #39837 (fix for #32924) support was added so that for all public taxonomies, variations of the core/post-terms block were added. But the hook to check for public taxonomies is run on init with a default priority of 10.
It's safe to asume, that this will run before many plugins will have registered their custom taxonomies, because the core init hook is added earlier and 10 is the default priority (so many developers will register it on 10 as well).

Proposed solution:

  1. Run the complete register_block_core_post_terms on a priority later than 10 (eg 100)
  2. Split the function and add variations for all public taxonomies in the editor in JavaScript (performance for fetching all taxonomies?)
  3. Split the function and add variations add a later point via PHP (not possible because server side version to register block variations is missing)

All other core blocks are registered on priority 10, so I think it would be a bit odd to run the register function for only this block on a later priority. Also of course we can't be 100% sure if on priority 100 all custom taxonomies are already registered (since developers also can use later priorities). So I guess I actually favor solution 2. Is there precedent for any solution like this?

I ran into this problem multiple times, and in the original PR @mrleemon originally found this bug.

Step-by-step reproduction instructions

Negative test:

  1. Register a custom taxonomy (example code from developer.wordpress.org).
  2. Go into site-editor and try to search for a block named like the custom taxonomy (eg "Courses").
  3. Block is not available, only the default "Tags" and "Categories" is available

Positive test:

  1. Register a custom taxonomy (example code from developer.wordpress.org) but change add_action priority to something lower than 10 (eg 9)
  2. Go into site-editor and try to search for a blog named as the custom taxonomy (eg "Courses").
  3. Block is available

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 5.2

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

    Labels

    Needs TestingNeeds further testing to be confirmed.[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions