Add echo parameter for wp_star_rating().

See #34080.

git-svn-id: https://develop.svn.wordpress.org/trunk@35005 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2015-10-10 06:42:19 +00:00
parent aacde02ed4
commit 9487469f80

View File

@@ -1984,6 +1984,8 @@ function _local_storage_notice() {
* 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.
*
@@ -1992,13 +1994,16 @@ function _local_storage_notice() {
* @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',
'type' => 'rating',
'number' => 0,
'echo' => true,
);
$r = wp_parse_args( $args, $defaults );
@@ -2024,12 +2029,18 @@ function wp_star_rating( $args = array() ) {
$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>';
$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;
}
/**