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
    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'] ); – Jack Johansson Feb 21 '18 at 10:00
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, privacy policy and cookie policy

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