5 ) { $rating = 5.0; } return round( $rating * 2 ) / 2; } /** * Render a compact star string for admin/list contexts (supports half stars). * * @param mixed $rating Rating from 0 to 5. * @return string Filled/half/empty star glyphs, already safe for output. */ public static function stars_text( $rating ) { $rating = self::clamp_rating( $rating ); if ( $rating <= 0 ) { return ''; } $full = (int) floor( $rating ); $half = ( $rating - $full ) >= 0.5; $empty = 5 - $full - ( $half ? 1 : 0 ); return str_repeat( "\xE2\x98\x85", $full ) . ( $half ? "\xC2\xBD" : '' ) . str_repeat( "\xE2\x98\x86", max( 0, $empty ) ); } }