Automattic\WooCommerce\Blocks\Utils

BlockTemplateUtils::filter_block_templates_by_feature_flag()public staticWC 1.0

Filter block templates by feature flag.

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

Хуков нет.

Возвращает

WP_Block_Template[]. An array of block template objects.

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

$result = BlockTemplateUtils::filter_block_templates_by_feature_flag( $block_templates );
$block_templates(WP_Block_Template[]) (обязательный)
An array of block template objects.

Код BlockTemplateUtils::filter_block_templates_by_feature_flag() WC 7.5.1

public static function filter_block_templates_by_feature_flag( $block_templates ) {
	$feature_gating = new FeatureGating();
	$flag           = $feature_gating->get_flag();

	/**
	 * An array of block templates with slug as key and flag as value.
	 *
	 * @var array
	*/
	$block_templates_with_feature_gate = array();

	return array_filter(
		$block_templates,
		function( $block_template ) use ( $flag, $block_templates_with_feature_gate ) {
			if ( isset( $block_templates_with_feature_gate[ $block_template->slug ] ) ) {
				return $block_templates_with_feature_gate[ $block_template->slug ] <= $flag;
			}
			return true;
		}
	);
}