[wp-hackers] Plugin options being cleared on save

Chris Jean gaarai at gaarai.com
Mon Oct 18 19:17:58 UTC 2010

Keep in mind that if you have any checkboxes in your form, that 
unchecked checkbox variables will be missing from the $_POST variable 
(or however else your code checks it). So, if you find that your 
checkbox is always checked after being saved in a checked state, you 
will have to manually confirm the absence of checkbox variables and 
manually set that variable to an off state (unset its position in the 
array, set it to blank, etc).

For example:

$settings = get_option( 'option_name' );
$settings = array_merge( $settings, $_POST );

if ( ! isset( $_POST['checkbox_name'] ) )
     $settings['checkbox_name'] = '';

Chris Jean (AKA gaarai&  chrisbliss18)
Coder for http://ithemes.com/

On 10/18/2010 12:53 PM, Otto wrote:
> You don't need to include it as a hidden field, just remember that
> your callback function has to return the entire array. It's going
> straight into the database from there. So make sure you pull any
> options you want to preserve out of the DB and put them in the new
> array. Might be simplest to just pull out the existing array then
> update it with the incoming options instead.
> -Otto

More information about the wp-hackers mailing list