Automattic\WooCommerce\Blocks

BlockTypesController::is_woocommerce_block_metadata │ private │ WC 1.0

Check whether block metadata belongs to a block bundled with WooCommerce.

Method of the class: BlockTypesController{}

No Hooks.

Returns

bool. Whether the metadata file is in the WooCommerce blocks directory.

Usage

// private - for code of main (parent) class only
$result = $this->is_woocommerce_block_metadata( $metadata );
$metadata(array) (required)
Block metadata.

BlockTypesController::is_woocommerce_block_metadata() code WC 11.3.0

private function is_woocommerce_block_metadata( $metadata ) {
	static $blocks_path = null;

	if ( null === $blocks_path ) {
		$resolved_path = realpath( WC_ABSPATH . 'assets/client/blocks' );
		$blocks_path   = false === $resolved_path
			? ''
			: trailingslashit( wp_normalize_path( $resolved_path ) );
	}

	if ( '' === $blocks_path || empty( $metadata['file'] ) ) {
		return false;
	}

	return str_starts_with(
		wp_normalize_path( $metadata['file'] ),
		$blocks_path
	);
}