WP_Theme_JSON_Resolver::has_same_registered_blocks()protected staticWP 6.1.0

Checks whether the registered blocks were already processed for this origin.

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

Хуков нет.

Возвращает

true|false. True on success, false otherwise.

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

$result = WP_Theme_JSON_Resolver::has_same_registered_blocks( $origin );
$origin(строка) (обязательный)
Data source for which to cache the blocks. Valid values are 'core', 'blocks', 'theme', and 'user'.

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

С версии 6.1.0 Введена.

Код WP_Theme_JSON_Resolver::has_same_registered_blocks() WP 6.5.2

protected static function has_same_registered_blocks( $origin ) {
	// Bail out if the origin is invalid.
	if ( ! isset( static::$blocks_cache[ $origin ] ) ) {
		return false;
	}

	$registry = WP_Block_Type_Registry::get_instance();
	$blocks   = $registry->get_all_registered();

	// Is there metadata for all currently registered blocks?
	$block_diff = array_diff_key( $blocks, static::$blocks_cache[ $origin ] );
	if ( empty( $block_diff ) ) {
		return true;
	}

	foreach ( $blocks as $block_name => $block_type ) {
		static::$blocks_cache[ $origin ][ $block_name ] = true;
	}

	return false;
}