The problem here was caused because I was using a sanitize callback declared in register_settings()
(the on_save_chages()
function below).
This callback will ultimatly update the database with whatever value is returned, creating the fgw_login
key if it does not exist.
To ensure that I always had my default empty array if required I made the following simple change, returning an empty array when the options were reset as opposed to nothing –
/**
* Sanitize the option on save
*/
public function on_save_settings($input){
/** Check to see if the options should be restored to default */
if(isset($_POST['delete'])) :
delete_option('fgw_login');
return array(); /** <-- THIS IS ALL I HAD TO DO */
endif;
if(!isset($_POST['submit'])) return; // Ensure the user is supposed to be here
{more stuff here, but not relevant}
}
While the problem exposed my code for not making the proper checks, I’m glad that I was afforded the oppurtunity to delve into the Settings API in greater depth and encourage any users of it’s awesomeness to do the same 🙂