[wp-hackers] Plugin options being cleared on save

Scott Bressler sbressler at gmail.com
Mon Oct 18 19:27:54 UTC 2010


Hmm, well, this would be in the sanitization callback, right? So it'd be
array_merge with the passed parameter. Otherwise, makes sense. I've actually
always just written my code with array_key_exists for checkboxes, but it
definitely does make more sense to just set to 0 if missing.

On Mon, Oct 18, 2010 at 12:17 PM, Chris Jean <gaarai at gaarai.com> wrote:

> 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/
> http://gaarai.com/
> @chrisjean
>
>
>
> 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
>>
>  _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list