From c968b2bf7a9a9a054b2b6a1194abddafb7e6b103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Fri, 10 Nov 2023 14:57:51 +0100 Subject: [PATCH] Add comment with explanation about the change --- src/BlockPatterns.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/BlockPatterns.php b/src/BlockPatterns.php index 2f7dd79c84b..daad220348a 100644 --- a/src/BlockPatterns.php +++ b/src/BlockPatterns.php @@ -233,6 +233,16 @@ public function register_block_patterns() { // The actual pattern content is the output of the file. ob_start(); + + /* + For patterns that can have AI-generated content, we need to get its content from the dictionary and pass + it to the pattern file through the "$content" and "$images" variables. + This is to avoid having to access the dictionary for each pattern when it's registered or inserted. + Before the "$content" and "$images" variables were populated in each pattern. Since the pattern + registration happens in the init hook, the dictionary was being access one for each pattern and + for each page load. This way we only do it once on registration. + For more context: https://github.com/woocommerce/woocommerce-blocks/pull/11733 + */ if ( ! is_null( $pattern_data_from_dictionary ) ) { $content = $pattern_data_from_dictionary['content']; $images = $pattern_data_from_dictionary['images'] ?? array();