diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 13a3026268b682..45e63478292616 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -106,7 +106,9 @@ function block_core_navigation_link_render_submenu_icon() { function render_block_core_navigation_link( $attributes, $content, $block ) { // Don't render the block's subtree if it is a draft. if ( - isset( $attributes['id'] ) && is_numeric( $attributes['id'] ) && + isset( $attributes['id'] ) && + is_numeric( $attributes['id'] ) && + isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] ) ) { $post = get_post( $attributes['id'] ); diff --git a/phpunit/class-block-library-navigation-link-test.php b/phpunit/class-block-library-navigation-link-test.php index 65f152fafb7b5a..84a1809076573c 100644 --- a/phpunit/class-block-library-navigation-link-test.php +++ b/phpunit/class-block-library-navigation-link-test.php @@ -146,4 +146,24 @@ function test_returns_link_for_category() { ) !== false ); } + + function test_returns_link_for_plain_link() { + $parsed_blocks = parse_blocks( + '' + ); + $this->assertEquals( 1, count( $parsed_blocks ) ); + + $navigation_link_block = new WP_Block( $parsed_blocks[0], array() ); + $this->assertEquals( + true, + strpos( + gutenberg_render_block_core_navigation_link( + $navigation_link_block->attributes, + array(), + $navigation_link_block + ), + 'My Website' + ) !== false + ); + } }