I absolutely hate this error. And do not understand it at all.
So this is my code, what you want to focus on is the foreach loop:
public function reset_theme_options(){
if($this->is_theme_options_array()){
foreach($this->_theme_option['admin_options'] as $option_name=>$value){
if($value != false){
delete_option($option_name);
$http = new AisisCore_Http_Http();
wp_safe_redirect($http->get_current_url());
}
}
$this->_update_option();
}else{
$this->_theme_option = array();
$this->_update_option();
}
}
Essentially all I am doing is getting the name of the options, so lets say you store all your options for your theme in 'My_theme', which is an array of settings.
All I do is take that and delete it - it works as is.
The problem is that I am then essentially (from wp_safe_redirect()
) refreshing the page, I could do this through javascript and such but I think this way is better.
So everything works, I get my success message, the options are reset with the following hitch:
Warning: Cannot modify header information - headers already sent by (output started at /var/www/wordpress/wp-admin/menu-header.php:94) in /var/www/wordpress/wp-includes/pluggable.php on line 876
Ok so I click the reset button again and everything works as it should.
My steps in this error are:
(first start with a clean slate, no options saved) - save some options, hit submit. Then after the page refreshes, click reset, boom error, options still saved, click reset again, boom options reset.
Help?