WP_Theme::set_pattern_cache( array $patterns )

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

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

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

User Contributed Notes

You must log in before being able to contribute a note or feedback.