context['postId'] ) ? $block->context['postId'] : get_the_ID() ); if ( ! $academy_course || ! $academy_course['reviews_enabled'] ) { return; } $academy_average = (float) $academy_course['rating']['average']; $academy_count = (int) $academy_course['rating']['count']; if ( ! empty( $attributes['hideWhenEmpty'] ) && 0 === $academy_count ) { return; } // Filled and empty star colours: hex, rgb(a) or a theme palette colour. $academy_style = ''; foreach ( [ 'starColor' => '--academy-star-color', 'emptyStarColor' => '--academy-star-empty-color' ] as $academy_key => $academy_var ) { if ( ! empty( $attributes[ $academy_key ] ) && preg_match( '/^(#[0-9a-f]{3,8}|rgba?\([\d\s.,%]+\)|var\(--wp--preset--color--[a-z0-9-]+\))$/i', $attributes[ $academy_key ] ) ) { $academy_style .= $academy_var . ':' . $attributes[ $academy_key ] . ';'; } } // One star: filled once the course has a rating, beside the average. $academy_single = isset( $attributes['starCount'] ) && 'one' === $attributes['starCount']; $academy_fill = $academy_single ? ( $academy_count > 0 ? 100 : 0 ) : max( 0, min( 100, $academy_average / 5 * 100 ) ); $academy_wrapper = get_block_wrapper_attributes( [ 'style' => $academy_style, 'class' => $academy_single ? 'is-single-star' : '', ] ); ?>
>