Make WordPress Core

Changeset 41184


Ignore:
Timestamp:
07/29/2017 08:34:26 PM (7 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/template.php

    r40967 r41184  
    20952095 *     Optional. Array of star ratings arguments.
    20962096 *
    2097  *     @type int    $rating The rating to display, expressed in either a 0.5 rating increment,
    2098  *                          or percentage. Default 0.
    2099  *     @type string $type   Format that the $rating is in. Valid values are 'rating' (default),
    2100  *                          or, 'percent'. Default 'rating'.
    2101  *     @type int    $number The number of ratings that makes up this rating. Default 0.
    2102  *     @type bool   $echo   Whether to echo the generated markup. False to return the markup instead
    2103  *                          of echoing it. Default true.
     2097 *     @type int|float $rating The rating to display, expressed in either a 0.5 rating increment,
     2098 *                             or percentage. Default 0.
     2099 *     @type string    $type   Format that the $rating is in. Valid values are 'rating' (default),
     2100 *                             or, 'percent'. Default 'rating'.
     2101 *     @type int       $number The number of ratings that makes up this rating. Default 0.
     2102 *     @type bool      $echo   Whether to echo the generated markup. False to return the markup instead
     2103 *                             of echoing it. Default true.
    21042104 * }
     2105 * @return string Star rating HTML.
    21052106 */
    21062107function wp_star_rating( $args = array() ) {
     
    21132114    $r = wp_parse_args( $args, $defaults );
    21142115
    2115     // Non-english decimal places when the $rating is coming from a string
    2116     $rating = str_replace( ',', '.', $r['rating'] );
     2116    // Non-English decimal places when the $rating is coming from a string
     2117    $rating = (float) str_replace( ',', '.', $r['rating'] );
    21172118
    21182119    // Convert Percentage to star rating, 0..5 in .5 increments
    2119     if ( 'percent' == $r['type'] ) {
     2120    if ( 'percent' === $r['type'] ) {
    21202121        $rating = round( $rating / 10, 0 ) / 2;
    21212122    }
Note: See TracChangeset for help on using the changeset viewer.