• Resolved werle77

    (@werle77)


    @bungeshea I saw you helped someone else with a similar error. I am hoping you might be able to help me as well.

    I am receiving this error in my logs.

    PHP Warning: number_format() expects parameter 1 to be float, string given in /var/www/mysite.com/htdocs/wp-content/plugins/code-snippets/php/snippet-ops.php(504) : eval()'d code on line 6

    I’m not sure if this is a snippet causing this. If so, how do I know what snippet is causing this issue? Can you help me identify what snippet is causing this error?

    • This topic was modified 1 year, 2 months ago by werle77.
    • This topic was modified 1 year, 2 months ago by werle77.
    • This topic was modified 1 year, 2 months ago by werle77.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Definitely a snippet causing this. You should be able to identify which one by doing a search on the Snippets page for number_format @line:6.

    Thread Starter werle77

    (@werle77)

    Ok, here is the snippet that is causing this error.

    // Return ACF Number Fields Formatted with Commas on the Frontendadd_filter('acf/format_value/name=property_price', 'acf_number_comma', 20, 3);
    add_filter('acf/format_value/name=property_sqft', 'acf_number_comma', 20, 3);
    function acf_number_comma($value, $post_id, $field) {
    $value = number_format($value);
    return $value;
    }

    I am not sure what needs updated here. I inherited this site so I am not 100% sure why the error?

    Plugin Author Shea Bunge

    (@bungeshea)

    Looks like ACF is providing $value as a string, but number_format expects a floating-point value. You should be able to fix this by converting the value before formatting:

    // Return ACF Number Fields Formatted with Commas on the Frontend
    $callback = function ( $value ) {
    	$parsed_value = floatval( $value );
    
    	return $parsed_value ?
    		number_format( $parsed_value ) :
    		$value;
    };
    
    
    add_filter( 'acf/format_value/name=property_price', $callback, 20 );
    add_filter( 'acf/format_value/name=property_sqft', $callback, 20 );

    Thread Starter werle77

    (@werle77)

    That seems to have done the trick. I haven’t seen any updates in my error log, but I will keep monitoring that. Thanks.!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘eval()’d code on line 6’ is closed to new replies.