From 9487469f8068706454decb09fe7170a8900d6e40 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 10 Oct 2015 06:42:19 +0000 Subject: [PATCH] Add `echo` parameter for `wp_star_rating()`. See #34080. git-svn-id: https://develop.svn.wordpress.org/trunk@35005 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/template-functions.php | 25 ++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/includes/template-functions.php b/src/wp-admin/includes/template-functions.php index 81e8534c6c..0918bfd86c 100644 --- a/src/wp-admin/includes/template-functions.php +++ b/src/wp-admin/includes/template-functions.php @@ -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 '
'; - echo '' . $title . ''; - echo str_repeat( '
', $full_stars ); - echo str_repeat( '
', $half_stars ); - echo str_repeat( '
', $empty_stars); - echo '
'; + $output = '
'; + $output .= '' . $title . ''; + $output .= str_repeat( '
', $full_stars ); + $output .= str_repeat( '
', $half_stars ); + $output .= str_repeat( '
', $empty_stars ); + $output .= '
'; + + if ( $r['echo'] ) { + echo $output; + } + + return $output; } /**