Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Add comment with explanation about the change
Browse files Browse the repository at this point in the history
  • Loading branch information
albarin committed Nov 10, 2023
1 parent f621afc commit c968b2b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c968b2b

Please sign in to comment.