Automattic\WooCommerce\Blocks\BlockTypes

FeaturedCategory::render_attributesprotectedWC 1.0

Renders the featured category attributes.

Method of the class: FeaturedCategory{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_attributes( $category, $attributes );
$category(WP_Term) (required)
Term object.
$attributes(array) (required)
Block attributes.
Default: empty array

FeaturedCategory::render_attributes() code WC 10.6.2

protected function render_attributes( $category, $attributes ) {
	$output = '';

	// Backwards compatibility: Only render legacy attributes if `editMode` exists as boolean value
	// This allows us to distinguish between old and new version of the block (which accept inner blocks).
	if ( array_key_exists( 'editMode', $attributes ) && is_bool( $attributes['editMode'] ) ) {
		$legacy_title = sprintf(
			'<h2 class="wc-block-featured-category__title">%s</h2>',
			wp_kses_post( $category->name )
		);

		$output .= $legacy_title;

		if (
			! isset( $attributes['showDesc'] ) ||
			( isset( $attributes['showDesc'] ) && false !== $attributes['showDesc'] )
		) {
			$desc_str = sprintf(
				'<div class="wc-block-featured-category__description">%s</div>',
				wc_format_content( wp_kses_post( $category->description ) )
			);
			$output  .= $desc_str;
		}
	}

	return $output;
}