1

I am working on a Plugin. I am using Settings API like below.

register_setting( 'sports_api_key', 'sports_api_key' );

How can I sanitize settings API Text value here ?

1

1 Answer 1

2

Add a third parameter, which is an $args array, and add your sanitization callback in there:

register_setting( 
    'sports_api_key', 
    'sports_api_key', 
    array(
        'sanitization_callback' => 'sanitize_text_field'
    )
);

This is enough for your use case, the sanitize_text_field function already exists, so you don't need to create it.

More information here for how to add a sanitization callback and here to sanitize text fields.

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.