WP_Theme::set_pattern_cache()privateWP 6.4.0

Sets block pattern cache.

Метод класса: WP_Theme{}

Хуки из метода

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->set_pattern_cache( $patterns );
$patterns(массив) (обязательный)
Block patterns data to set in cache.

Список изменений

С версии 6.4.0 Введена.
С версии 6.6.0 Uses transients to cache regardless of site environment.

Код WP_Theme::set_pattern_cache() WP 6.6.2

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