Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/wp-includes/class-wp-block-patterns-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,22 @@ public function get_registered( $pattern_name ) {
return null;
}

$key = 'registered_block_pattern_' . $pattern_name;
$cached_pattern = wp_cache_get( $key, '', false, $found );
if ( $found ) {
return $cached_pattern;
}

$pattern = $this->registered_patterns[ $pattern_name ];
if ( ! isset( $pattern['content'] ) && isset( $pattern['file_path'] ) ) {
ob_start();
include $pattern['file_path'];
$pattern['content'] = ob_get_clean();
$this->registered_patterns[ $pattern_name ]['content'] = $pattern['content'];
}

$pattern['content'] = $this->prepare_content( $pattern, get_hooked_blocks() );

wp_cache_set( $key, $pattern );
return $pattern;
}

Expand Down Expand Up @@ -231,6 +237,14 @@ public function get_all_registered( $outside_init_only = false ) {
}
continue;
}

$key = 'registered_block_pattern_' . $index;
$cached_pattern = wp_cache_get( $key, '', false, $found );
if ( $found ) {
$patterns[ $index ] = $cached_pattern;
continue;
}

if ( ! isset( $pattern['content'] ) && isset( $pattern['file_path'] ) ) {
ob_start();
include $pattern['file_path'];
Expand All @@ -242,6 +256,8 @@ public function get_all_registered( $outside_init_only = false ) {
}
}
$patterns[ $index ]['content'] = $this->prepare_content( $pattern, $hooked_blocks );

wp_cache_set( $key, $patterns[ $index ] );
}
return $patterns;
}
Expand Down