Plugins: In wp_star_rating()
, use explicit type casting for $rating
to avoid a "non-numeric value encountered" warning in PHP 7.1.
Clarify in the function DocBlock that `$rating` can be a float. Props afragen. Fixes #41484. git-svn-id: https://develop.svn.wordpress.org/trunk@41184 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5cb91857ab
commit
bf39951441
@ -2094,14 +2094,15 @@ function _local_storage_notice() {
|
|||||||
* @param array $args {
|
* @param array $args {
|
||||||
* Optional. Array of star ratings arguments.
|
* Optional. Array of star ratings arguments.
|
||||||
*
|
*
|
||||||
* @type int $rating The rating to display, expressed in either a 0.5 rating increment,
|
* @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
|
||||||
* or percentage. Default 0.
|
* or percentage. Default 0.
|
||||||
* @type string $type Format that the $rating is in. Valid values are 'rating' (default),
|
* @type string $type Format that the $rating is in. Valid values are 'rating' (default),
|
||||||
* or, 'percent'. Default 'rating'.
|
* or, 'percent'. Default 'rating'.
|
||||||
* @type int $number The number of ratings that makes up this rating. Default 0.
|
* @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
|
* @type bool $echo Whether to echo the generated markup. False to return the markup instead
|
||||||
* of echoing it. Default true.
|
* of echoing it. Default true.
|
||||||
* }
|
* }
|
||||||
|
* @return string Star rating HTML.
|
||||||
*/
|
*/
|
||||||
function wp_star_rating( $args = array() ) {
|
function wp_star_rating( $args = array() ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
@ -2112,11 +2113,11 @@ function wp_star_rating( $args = array() ) {
|
|||||||
);
|
);
|
||||||
$r = wp_parse_args( $args, $defaults );
|
$r = wp_parse_args( $args, $defaults );
|
||||||
|
|
||||||
// Non-english decimal places when the $rating is coming from a string
|
// Non-English decimal places when the $rating is coming from a string
|
||||||
$rating = str_replace( ',', '.', $r['rating'] );
|
$rating = (float) str_replace( ',', '.', $r['rating'] );
|
||||||
|
|
||||||
// Convert Percentage to star rating, 0..5 in .5 increments
|
// Convert Percentage to star rating, 0..5 in .5 increments
|
||||||
if ( 'percent' == $r['type'] ) {
|
if ( 'percent' === $r['type'] ) {
|
||||||
$rating = round( $rating / 10, 0 ) / 2;
|
$rating = round( $rating / 10, 0 ) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user