' . esc_html( $text ) . ''; } $extra['class'] = trim( 'rooster-lms-section ' . (string) ( $extra['class'] ?? '' ) ); return '
' . $heading . $body . '
'; } public static function heading_attributes( array $raw ): array { return array( 'heading' => isset( $raw['heading'] ) && is_scalar( $raw['heading'] ) ? sanitize_text_field( (string) $raw['heading'] ) : '', 'showHeading' => ! isset( $raw['showHeading'] ) || (bool) $raw['showHeading'], 'headingLevel' => max( 2, min( 6, isset( $raw['headingLevel'] ) ? (int) $raw['headingLevel'] : 2 ) ), ); } public static function course_post( array $raw ): int { return isset( $raw['coursePost'] ) ? max( 0, (int) $raw['coursePost'] ) : 0; } public static function choice( array $raw, string $key, array $choices ): string { $value = isset( $raw[ $key ] ) && is_string( $raw[ $key ] ) ? $raw[ $key ] : ''; return in_array( $value, $choices, true ) ? $value : $choices[0]; } public static function flag( array $raw, string $key, bool $default ): bool { return isset( $raw[ $key ] ) ? (bool) $raw[ $key ] : $default; } public static function editor_empty( string $name, ?\WP_Block $block, string $message ): string { if ( ! Presentation::is_editor_preview() ) { return ''; } return '

' . esc_html( $message ) . '

'; } public static function stars( float $average, string $size = '' ): string { $average = max( 0.0, min( 5.0, round( $average, 2 ) ) ); /* translators: %s: the average rating, e.g. 4.5. */ $label = sprintf( __( 'Rated %s out of 5', 'rooster-lms' ), self::decimal( $average ) ); $style = '--rl-stars-value:' . $average . ';--rl-stars-gaps:' . min( 4, (int) floor( $average ) ); return ''; } public static function rating_line( ?float $average, int $count ): string { if ( null === $average || $count <= 0 ) { return ''; } /* translators: %s: number of ratings. */ $ratings = sprintf( _n( '%s rating', '%s ratings', $count, 'rooster-lms' ), Format::number( $count ) ); return '' . self::stars( $average, 'sm' ) . '' . ' (' . esc_html( $ratings ) . ')'; } public static function badge( array $badge ): string { $color = (string) sanitize_hex_color( (string) $badge['color'] ); $style = '' !== $color ? ' style="' . esc_attr( '--rl-badge:' . $color ) . '"' : ''; return '' . esc_html( $badge['label'] ) . ''; } public static function featured(): string { return '' . esc_html_x( 'Featured', 'course', 'rooster-lms' ) . ''; } public static function decimal( float $n ): string { return number_format_i18n( $n, 1 ); } public static function heart( int $course_id, bool $saved, string $title ): string { self::enqueue_script(); /* translators: %s: course title. */ $label = sprintf( __( 'Save "%s"', 'rooster-lms' ), $title ); $path = 'M12 21s-7.5-4.6-9.5-9.2C1.2 8.6 3.3 5 6.8 5c2 0 3.5 1.1 5.2 3 1.7-1.9 3.2-3 5.2-3 3.5 0 5.6 3.6 4.3 6.8C19.5 16.4 12 21 12 21z'; return ''; } public static function enqueue(): void { if ( wp_style_is( self::HANDLE, 'registered' ) ) { wp_enqueue_style( self::HANDLE ); } } public static function enqueue_script(): void { self::enqueue(); if ( wp_script_is( self::HANDLE, 'registered' ) ) { wp_enqueue_script( self::HANDLE ); } } }