W3cubDocs

/WordPress

WP_Theme::set_pattern_cache( array $patterns )

Sets block pattern cache.

Parameters

$patternsarrayrequired
Block patterns data to set in cache.

Source

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 );
}

Hooks

apply_filters( ‘wp_theme_files_cache_ttl’, int $cache_expiration, string $cache_type )

Filters the cache expiration time for theme files.

Changelog

Version Description
6.6.0 Uses transients to cache regardless of site environment.
6.4.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme/set_pattern_cache