WC_Brands_Block_Templates::get_block_templates()publicWC 1.0

Add the Block template in the template query results needed by FSE Triggered by get_block_templates action

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

Хуков нет.

Возвращает

WP_Block_Template[]. Array of the matched Block Templates to render.

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

$WC_Brands_Block_Templates = new WC_Brands_Block_Templates();
$WC_Brands_Block_Templates->get_block_templates( $query_result, $query, $template_type );
$query_result(массив) (обязательный)
The list of templates to render in the query.
$query(массив) (обязательный)
The current query parameters.
$template_type(строка) (обязательный)
The post_type for the template. Normally wp_template or wp_template_part.

Код WC_Brands_Block_Templates::get_block_templates() WC 9.6.1

public function get_block_templates( $query_result, $query, $template_type ) {
	// We don't want to run this if we are looking for template-parts. Like the header.
	if ( 'wp_template' !== $template_type ) {
		return $query_result;
	}

	$post_id = isset( $_REQUEST['postId'] ) ? wc_clean( wp_unslash( $_REQUEST['postId'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	$slugs   = $query['slug__in'] ?? array();

	// Only add the template if  asking for Product Brands.
	if (
		in_array( 'taxonomy-product_brand', $slugs, true ) ||
		( ! $post_id && ! count( $slugs ) ) ||
		( ! count( $slugs ) && $this->is_taxonomy_product_brand_template( $post_id ) )
	) {
		$query_result[] = $this->get_product_brands_template( $template_type );
	}

	return $query_result;
}