You aren’t returning data from the sanitize function:
function kns_sanitize_options( $input ) {
$input['option1'] = sanitize_text_field( $input['option1'] );
$input['option2'] = sanitize_text_field( $input['option2'] );
}
There is therefore nothing to save. Try:
function kns_sanitize_options( $input ) {
$input['option1'] = sanitize_text_field( $input['option1'] );
$input['option2'] = sanitize_text_field( $input['option2'] );
return $input;
}
Secondly, you’ve registered the name of your options as kns_products_options
register_setting( 'kns_products_settings_group', 'kns_products_options', 'kns_sanitize_options');
But you are using kns_options
in the form.
<input type="text" id="option1" name="kns_options[option1]" //...
The API doesn’t know how to find the data so $input
in your sanitization callback is always null
. Make that name attribute match the name you registered.
<input type="text" id="option1" name="kns_products_options[option1]" //...