diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index 1dcb2996a8e15d..ef4cb429c62cbd 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -338,7 +338,7 @@ function block_core_navigation_link_register_variation( $variation ) { return; } - $navigation_block_type->variations[] = $variation; + $navigation_block_type->variations = array_merge( $navigation_block_type->variations, array( $variation ) ); } /** @@ -356,14 +356,15 @@ function block_core_navigation_link_unregister_variation( $name ) { return; } // Search for the variation and remove it from the array. - foreach ( $navigation_block_type->variations as $i => $variation ) { + $variations = $navigation_block_type->variations; + foreach ( $variations as $i => $variation ) { if ( $variation['name'] === $name ) { - unset( $navigation_block_type->variations[ $i ] ); + unset( $variations[ $i ] ); break; } } // Reindex array after removing one variation. - $navigation_block_type->variations = array_values( $navigation_block_type->variations ); + $navigation_block_type->variations = array_values( $variations ); } /**