$this->get_schema_string(), 'fontSize' => $this->get_schema_string(), 'lineHeight' => $this->get_schema_string(), 'style' => array( 'type' => 'object' ), ) ); } /** * Returns the featured category. * * @param array $attributes Block attributes. Default empty array. * @return \WP_Term|null */ protected function get_item( $attributes ) { $id = absint( $attributes['categoryId'] ?? 0 ); $category = get_term( $id, 'product_cat' ); if ( ! $category || is_wp_error( $category ) ) { return null; } return $category; } /** * Returns the name of the featured category. * * @param \WP_Term $category Featured category. * @return string */ protected function get_item_title( $category ) { return $category->name; } /** * Returns the featured category image URL. * * @param \WP_Term $category Term object. * @param string $size Image size, defaults to 'full'. * @return string */ protected function get_item_image( $category, $size = 'full' ) { $image = ''; $image_id = get_term_meta( $category->term_id, 'thumbnail_id', true ); if ( $image_id ) { $image = wp_get_attachment_image_url( $image_id, $size ); } return $image; } /** * Renders the featured category attributes. * * @param \WP_Term $category Term object. * @param array $attributes Block attributes. Default empty array. * @return string */ 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( '