WPDIR

WPDIR
Everything and everyone WordPress

how to sanitize a decimal number in WordPress?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #904 Reply
    Sarah
    Guest

    I tried to add settings in the Customizer that are numbers with decimal point (period) and sanitize will fail or NULL my value, any function in WordPress to sanitize for decimal numbers and not only basic integers

    #905 Reply
    Anthony
    Guest

    If you are using absint than you must stop using that because it will reject any number that is negative or decimal range

    #906 Reply
    Brian
    Guest

    @OP you need to write your own sanitize function for float numbers then:

    https://wordpress.stackexchange.com/questions/225825/customizer-sanitize-callback-for-input-type-number

    #907 Reply
    Roy
    Guest
    function sanitize_float( $input ) {
        return filter_var($input, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
    }
    #908 Reply
    Denise
    Guest

    this guy also failed from cause of absint

    https://wordpress.stackexchange.com/questions/311152/customizer-how-to-sanitize-a-decimal-number-range

    seems PHP needs to have more options for sanitize functions.

    even WP is limited options.

    #7498 Reply
    Tyler
    Guest

    If you are using absint than you must stop using that because it will reject any number that is negative or decimal range

    I learned something new today!

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: how to sanitize a decimal number in WordPress?