1

I am sanitizing a text field input via a custom WordPress Setting API page like this...

public function current_issue_sanitize($input) {
    $sanitary_values = array();
    if ( isset( $input['episode'] ) ) {
        $sanitary_values['episode'] = sanitize_text_field( $input['episode'] );
    }

    return $sanitary_values;
}

This is working well but I am now trying to sanitize and integer, is there a sanitize_text_field equivalent for numbers?

2
  • 2
    Why can't you use sanitize_text_field() on integers? If you want to return the int part of the value, you can use $sanitary_values['episode'] = ( int ) sanitize_text_field( $input['episode'] );
    – Johansson
    Commented Feb 21, 2018 at 10:00
  • Related: wordpress.stackexchange.com/questions/168315/… Commented Jan 8, 2023 at 22:07

1 Answer 1

1

If the integer should be a positive number, you can use absint(). See: https://codex.wordpress.org/Function_Reference/absint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.