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>
2 Answers
It turned out to be nonce related: the form didn’t have a nonce. Solved this by adding wp_nonce_field
to the form.