I am struggling to get my settings page to save my options. I've got it showing up correctly and it hits the sanitize function
register_setting(
'my_options', // Option group
'my_settings', // Option name
array($this, 'sanitize') // Sanitize
);
When I run the debugger on the sanitize function, $input is null:
public function sanitize($input)
{
$new_input = array();
$new_input = $input;
//Sanitize the input actually
return $new_input;
}
The form itself is called like this:
<form id="my-admin-form" method="post" action="options.php">
<!-- Submission Notices -->
<div class="status-box notice notice-info" style="display: none;"></div>
<?php
settings_fields('my_options');
do_settings_sections('my_section');
submit_button();
?>
</form>
I am struggling to get my settings page to save my options. I've got it showing up correctly and it hits the sanitize function
register_setting(
'my_options', // Option group
'my_settings', // Option name
array($this, 'sanitize') // Sanitize
);
When I run the debugger on the sanitize function, $input is null:
public function sanitize($input)
{
$new_input = array();
$new_input = $input;
//Sanitize the input actually
return $new_input;
}
The form itself is called like this:
<form id="my-admin-form" method="post" action="options.php">
<!-- Submission Notices -->
<div class="status-box notice notice-info" style="display: none;"></div>
<?php
settings_fields('my_options');
do_settings_sections('my_section');
submit_button();
?>
</form>
It turned out to be nonce related: the form didn't have a nonce. Solved this by adding wp_nonce_field
to the form.
I had a similar problem even after I added the nonce.
The mistake I'd made was that the input names need to be an array, for example:
<input id="my_option[key]" type="text" name="my_option[key]" value="<?php !empty(my_option[key]) ? my_option[key] : NULL; ?>">