From 6152d4811518c986d62ac6d43b1cbbf9fe32a3a2 Mon Sep 17 00:00:00 2001 From: Dovid Levine Date: Tue, 29 Oct 2024 11:02:45 +0200 Subject: [PATCH] fix: explicitly return `null` instead of coercing voids in WP_Navigation_Block_Renderer --- src/wp-includes/blocks/navigation.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks/navigation.php b/src/wp-includes/blocks/navigation.php index fa9bb5a56f801..5db30e8f37499 100644 --- a/src/wp-includes/blocks/navigation.php +++ b/src/wp-includes/blocks/navigation.php @@ -224,7 +224,7 @@ private static function get_inner_blocks_html( $attributes, $inner_blocks ) { * @since 6.5.0 * * @param array $attributes The block attributes. - * @return WP_Block_List Returns the inner blocks for the navigation block. + * @return ?WP_Block_List Returns the inner blocks for the navigation block. */ private static function get_inner_blocks_from_navigation_post( $attributes ) { $navigation_post = get_post( $attributes['ref'] ); @@ -251,6 +251,9 @@ private static function get_inner_blocks_from_navigation_post( $attributes ) { // context which could be refined. return new WP_Block_List( $blocks, $attributes ); } + + // Return null if there are no valid posts. + return null; } /** @@ -1269,7 +1272,7 @@ function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_ * * @deprecated 6.3.0 Use WP_Navigation_Fallback::get_classic_menu_fallback() instead. * - * @return object WP_Term The classic navigation. + * @return ?\WP_Term The classic navigation. */ function block_core_navigation_get_classic_menu_fallback() { @@ -1306,6 +1309,8 @@ static function ( $a, $b ) { ); return $classic_nav_menus[0]; } + + return null; } /**