WP_Theme::set_pattern_cache()
Sets block pattern cache.
Method of the class: WP_Theme{}
Hooks from the method
Return
null
. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->set_pattern_cache( $patterns );
- $patterns(array) (required)
- Block patterns data to set in cache.
Changelog
Since 6.4.0 | Introduced. |
Since 6.6.0 | Uses transients to cache regardless of site environment. |
WP_Theme::set_pattern_cache() WP Theme::set pattern cache code WP 6.7.1
private function set_pattern_cache( array $patterns ) { $pattern_data = array( 'version' => $this->get( 'Version' ), 'patterns' => $patterns, ); /** * Filters the cache expiration time for theme files. * * @since 6.6.0 * * @param int $cache_expiration Cache expiration time in seconds. * @param string $cache_type Type of cache being set. */ $cache_expiration = (int) apply_filters( 'wp_theme_files_cache_ttl', self::$cache_expiration, 'theme_block_patterns' ); // We don't want to cache patterns infinitely. if ( $cache_expiration <= 0 ) { _doing_it_wrong( __METHOD__, sprintf( /* translators: %1$s: The filter name.*/ __( 'The %1$s filter must return an integer value greater than 0.' ), '<code>wp_theme_files_cache_ttl</code>' ), '6.6.0' ); $cache_expiration = self::$cache_expiration; } set_site_transient( 'wp_theme_files_patterns-' . $this->cache_hash, $pattern_data, $cache_expiration ); }