wp_star_rating

The timeline below displays how wordpress function wp_star_rating has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Outputs a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string.
    $rating = (float) str_replace(',', '.', $parsed_args['rating']);
    // Convert percentage to star rating, 0..5 in .5 increments.
    if ('percent' === $parsed_args['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed.
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($parsed_args['number']) {
        /* translators: Hidden accessibility text. 1: The rating, 2: The number of ratings. */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($parsed_args['number']));
    } else {
        /* translators: Hidden accessibility text. %s: The rating. */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($parsed_args['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 6.1

/**
 * Outputs a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string.
    $rating = (float) str_replace(',', '.', $parsed_args['rating']);
    // Convert percentage to star rating, 0..5 in .5 increments.
    if ('percent' === $parsed_args['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed.
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($parsed_args['number']) {
        /* translators: 1: The rating, 2: The number of ratings. */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($parsed_args['number']));
    } else {
        /* translators: %s: The rating. */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($parsed_args['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 5.4

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string.
    $rating = (float) str_replace(',', '.', $parsed_args['rating']);
    // Convert percentage to star rating, 0..5 in .5 increments.
    if ('percent' === $parsed_args['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed.
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($parsed_args['number']) {
        /* translators: 1: The rating, 2: The number of ratings. */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($parsed_args['number']));
    } else {
        /* translators: %s: The rating. */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($parsed_args['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 5.3

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $parsed_args = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string
    $rating = (float) str_replace(',', '.', $parsed_args['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' === $parsed_args['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($parsed_args['number']) {
        /* translators: 1: The rating, 2: The number of ratings. */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $parsed_args['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($parsed_args['number']));
    } else {
        /* translators: %s: The rating. */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($parsed_args['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 5.1

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string
    $rating = (float) str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' === $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: the rating, 2: the number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: %s: the rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 4.9

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
 *                             or percentage. Default 0.
 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                             or, 'percent'. Default 'rating'.
 *     @type int       $number The number of ratings that makes up this rating. Default 0.
 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
 *                             of echoing it. Default true.
 * }
 * @return string Star rating HTML.
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Non-English decimal places when the $rating is coming from a string
    $rating = (float) str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' === $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: The rating, 2: The number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 4.6

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
 *                          or percentage. Default 0.
 *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                          or, 'percent'. Default 'rating'.
 *     @type int    $number The number of ratings that makes up this rating. Default 0.
 *     @type bool   $echo   Whether to echo the generated markup. False to return the markup instead
 *                          of echoing it. Default true.
 * }
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Non-english decimal places when the $rating is coming from a string
    $rating = str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' == $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: The rating, 2: The number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full" aria-hidden="true"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half" aria-hidden="true"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty" aria-hidden="true"></div>', $empty_stars);
    $output .= '</div>';
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 4.5

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
 *                          or percentage. Default 0.
 *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                          or, 'percent'. Default 'rating'.
 *     @type int    $number The number of ratings that makes up this rating. Default 0.
 *     @type bool   $echo   Whether to echo the generated markup. False to return the markup instead
 *                          of echoing it. Default true.
 * }
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Non-english decimal places when the $rating is coming from a string
    $rating = str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' == $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: The rating, 2: The number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty"></div>', $empty_stars);
    $output .= '</div>';
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 4.4

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @since 4.4.0 Introduced the `echo` parameter.
 *
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
 *                          or percentage. Default 0.
 *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                          or, 'percent'. Default 'rating'.
 *     @type int    $number The number of ratings that makes up this rating. Default 0.
 *     @type bool   $echo   Whether to echo the generated markup. False to return the markup instead
 *                          of echoing it. Default true.
 * }
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0, 'echo' => true);
    $r = wp_parse_args($args, $defaults);
    // Non-english decimal places when the $rating is coming from a string
    $rating = str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' == $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: The rating, 2: The number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    $output = '<div class="star-rating" title="' . esc_attr($title) . '">';
    $output .= '<span class="screen-reader-text">' . $title . '</span>';
    $output .= str_repeat('<div class="star star-full"></div>', $full_stars);
    $output .= str_repeat('<div class="star star-half"></div>', $half_stars);
    $output .= str_repeat('<div class="star star-empty"></div>', $empty_stars);
    $output .= '</div>';
    if ($r['echo']) {
        echo $output;
    }
    return $output;
}

WordPress Version: 4.0

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
 *                          or percentage. Default 0.
 *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                          or, 'percent'. Default 'rating'.
 *     @type int    $number The number of ratings that makes up this rating. Default 0.
 * }
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0);
    $r = wp_parse_args($args, $defaults);
    // Non-english decimal places when the $rating is coming from a string
    $rating = str_replace(',', '.', $r['rating']);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' == $r['type']) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($r['number']) {
        /* translators: 1: The rating, 2: The number of ratings */
        $format = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $r['number']);
        $title = sprintf($format, number_format_i18n($rating, 1), number_format_i18n($r['number']));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    echo '<div class="star-rating" title="' . esc_attr($title) . '">';
    echo '<span class="screen-reader-text">' . $title . '</span>';
    echo str_repeat('<div class="star star-full"></div>', $full_stars);
    echo str_repeat('<div class="star star-half"></div>', $half_stars);
    echo str_repeat('<div class="star star-empty"></div>', $empty_stars);
    echo '</div>';
}

WordPress Version: 3.8

/**
 * Output a HTML element with a star rating for a given rating.
 *
 * Outputs a HTML element with the star rating exposed on a 0..5 scale in
 * half star increments (ie. 1, 1.5, 2 stars). Optionally, if specified, the
 * number of ratings may also be displayed by passing the $number parameter.
 *
 * @since 3.8.0
 * @param array $args {
 *     Optional. Array of star ratings arguments.
 *
 *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
 *                          or percentage. Default 0.
 *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
 *                          or, 'percent'. Default 'rating'.
 *     @type int    $number The number of ratings that makes up this rating. Default 0.
 * }
 */
function wp_star_rating($args = array())
{
    $defaults = array('rating' => 0, 'type' => 'rating', 'number' => 0);
    $r = wp_parse_args($args, $defaults);
    extract($r, EXTR_SKIP);
    // Non-english decimal places when the $rating is coming from a string
    $rating = str_replace(',', '.', $rating);
    // Convert Percentage to star rating, 0..5 in .5 increments
    if ('percent' == $type) {
        $rating = round($rating / 10, 0) / 2;
    }
    // Calculate the number of each type of star needed
    $full_stars = floor($rating);
    $half_stars = ceil($rating - $full_stars);
    $empty_stars = 5 - $full_stars - $half_stars;
    if ($number) {
        /* translators: 1: The rating, 2: The number of ratings */
        $title = _n('%1$s rating based on %2$s rating', '%1$s rating based on %2$s ratings', $number);
        $title = sprintf($title, number_format_i18n($rating, 1), number_format_i18n($number));
    } else {
        /* translators: 1: The rating */
        $title = sprintf(__('%s rating'), number_format_i18n($rating, 1));
    }
    echo '<div class="star-rating" title="' . esc_attr($title) . '">';
    echo str_repeat('<div class="star star-full"></div>', $full_stars);
    echo str_repeat('<div class="star star-half"></div>', $half_stars);
    echo str_repeat('<div class="star star-empty"></div>', $empty_stars);
    echo '</div>';
}