Closed bobbingwide closed 1 year ago
My primary menu worked since I didn't use the id
attribute at all.
I added a Category link for FSE.
The generated HTML is:
<!-- wp:navigation {"orientation":"horizontal"} -->
<!-- wp:navigation-link {"label":"Block news","type":"category","description":"Block news - news about blocks","id":39,"url":"https://blocks.wp.a2z/category/block-news/"} /-->
<!-- wp:navigation-link {"label":"News","type":"category","description":"News in general - not necessarily about blocks.","id":469,"url":"https://blocks.wp.a2z/category/news/"} /-->
<!-- wp:navigation-link {"label":"FSE","type":"category","id":613,"url":"https://blocks.wp.a2z/category/fse/"} /-->
<!-- /wp:navigation -->
The Warning was only produced twice. I'd expected to see 3 messages. The reason I didn't see the warning for the new link was that the post found for the id was an attachment. For the other two 39 was a revision and 469 didn't exist.
As a quick hack I changed the code to check the value of $attributes['type']
if ( isset( $attributes['id'] ) && is_numeric( $attributes['id'] ) && isset( $attributes['type'] ) ) {
if ( 'post' === $attributes['type'] ) {
$post = get_post( $attributes['id'] );
if ( 'publish' !== $post->post_status ) {
return '';
}
}
}
id
attributes.As a quick hack I changed the code to check the value of $attributes['type']
This hack's no good for the long term....
When the navigation link is a "Link" variation the type
attribute is not set. So the above code would not check the post status.
Variation | type attribute | id attribute is? |
---|---|---|
Link | probably a post | |
Post Link | post | post ID |
Page Link | page | post ID |
Category Link | category | term ID |
Tag link | tag | term ID |
It might make more sense if the type
for Tag Link matched the taxonomy name ( post_tag ) rather than the default for the permalink base ( tag ).
A simpler workaround for the Fizzie theme, which already overrides the navigation link is to update fizzie_fiddle_nav_atts()
to unset the id
attribute before calling gutenberg_render_block_core_navigation_link()
.
The original issue for this is https://github.com/WordPress/gutenberg/issues/28712 24814 is a follow on.
24814 is a follow on.
PR 28999 is another follow on that addresses the $attribute['type']
is not set for Navigation Link.
Delivered in v0.4.0
https://blocks.wp.a2z/block/navigation-link-core-navigation-link/category-link-core-navigation-link/
Warning: Attempt to read property "post_status" on null in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\build\block-library\blocks\navigation-link.php on line 110
Warning: Attempt to read property "post_status" on null in C:\apache\htdocs\wordpress\wp-content\plugins\gutenberg\build\block-library\blocks\navigation-link.php on line 110
Editing the post produced the same warnings, then on interacting with the Core Navigation block ( horizontal ) I got "This block has encountered an error and cannot be previewed". 12 Errors in the console log.
There were 5 empty social links in the menu. I removed these and the warnings still appeared. No menu items were visible. Both of the links appeared to be valid.![image](https://user-images.githubusercontent.com/2474435/109295262-57ad5600-7826-11eb-899f-86d16ae8f3ab.png)
Neither link had a Description, Link title or Link rel
The problem was that the
$attributes['id']
values ( 469 for Block News and 39 for News ) don't refer to posts These are the values of theterm_id
for the categories.