Editor: Simplify return shape and logic of _wp_get_block_patterns().

Follow up to [56765].

Props spacedmonkey.
Fixes #59490.

Built from https://develop.svn.wordpress.org/trunk@56771


git-svn-id: http://core.svn.wordpress.org/trunk@56283 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz
2023-10-03 18:19:23 +00:00
parent 22923ffb9d
commit 3bc56b3de0
3 changed files with 49 additions and 29 deletions

View File

@@ -825,7 +825,40 @@ final class WP_Theme implements ArrayAccess {
}
/**
* Clear block pattern cache.
* Gets block pattern cache.
*
* @since 6.4.0
*
* @return array|false Returns an array of patterns if cache is found, otherwise false.
*/
public function get_pattern_cache() {
if ( ! $this->exists() ) {
return false;
}
$pattern_data = get_transient( 'wp_theme_patterns_' . $this->stylesheet );
if ( is_array( $pattern_data ) && $pattern_data['version'] === $this->get( 'Version' ) ) {
return $pattern_data['patterns'];
}
return false;
}
/**
* Sets block pattern cache.
*
* @since 6.4.0
*
* @param array $patterns Block patterns data to set in cache.
*/
public function set_pattern_cache( array $patterns ) {
$pattern_data = array(
'version' => $this->get( 'Version' ),
'patterns' => $patterns,
);
set_transient( 'wp_theme_patterns_' . $this->stylesheet, $pattern_data );
}
/**
* Clears block pattern cache.
*
* @since 6.4.0
*/