-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Description
Similar to #52569 the navigiation link block creates a variation for all post types. But the hook to check for public post types (especially those with show_in_nav_menus set to true) 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 post types, because the core init hook is added earlier and 10 is the default priority (so many developers will register it on 10 as well).
File:
| add_action( 'init', 'register_block_core_navigation_link' ); |
Proposed solution:
- Run the complete
register_block_core_navigation_linkon a priority later than 10 (eg 100) - Split the function and add variations for all public post types in the editor in JavaScript (performance for fetching all post types?)
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 post types 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?
See also discussion in #52569
My attention was brought to this bug by @[email protected].
Step-by-step reproduction instructions
Negative test:
- Register a custom post type (example code from developer.wordpress.org).
add_action('init', function () {
register_post_type(
'wporg_product',
array(
'labels' => array(
'name' => __('Products', 'textdomain'),
'singular_name' => __('Product', 'textdomain'),
'item_link' => __('Product Link', 'textdomain')
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'show_in_nav_menus' => true
)
);
}, 11);Important: Set the item_link label or the block variation is called Post Link.
2. Go into site-editor and add a navigation block
3. try to search for a block named like the custom taxonomy (eg "Product Link").
4. Block is not available, only the default "Post Link" and "Pages Link" will be availab.e
Positive test:
- Register a custom post type (example code from developer.wordpress.org).
add_action('init', function () {
register_post_type(
'wporg_product',
array(
'labels' => array(
'name' => __('Products', 'textdomain'),
'singular_name' => __('Product', 'textdomain'),
'item_link' => __('Product Link', 'textdomain')
),
'public' => true,
'has_archive' => true,
'show_in_rest' => true,
'show_in_nav_menus' => true
)
);
}, 9);Important: Set the item_link label or the block variation is called Post Link.
Important: change add_action priority to something lower than 10 (eg 9)
2. Go into site-editor and add a navigation block
3. try to search for a block named like the custom taxonomy (eg "Product Link").
4. 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