1. Basic settings API callback.
Using Settings API my $sanitize_callback validating function looks like:
(...)
if($type == "foo") {
$valid_input[$id] = $option[$id];
}
else if($type == "bar") {
$valid_input[$id] = wp_filter_nohtml_kses($input[$id]);
}
(...)
It's almost the same as in this great theme by Chip Bennett: https://github.com/chipbennett/oenology/blob/master/functions/options-register.php#L95
2. Avoiding option updating.
After form submit all options are being updated and it's values are being overwritten with $input.
What if I don't want to update one of them (let's say it's $type
is multiple_settings
) but instead create an array and add new options to it? How do I do that?
I was trying things like:
else if($type == "multiple_settings") {
$valid_input[$id][] = $input[$id]; // creates an array but still overwrites
$valid_input[$id] = array_push($valid_input[$id], $input[$id]); //returns NULL
}
With no luck.
[edit]
Maybe it has something to do with the way I save my settings (return of validation function below)?
$options = get_option('XX_theme_settings');
$valid = array_merge($options,$valid_input);
return $valid;
Thanks!
array('a','b')
and you recieve 'c' in your input you want the new value to bearray('a','b','c')
?$valid_input[$id][] = 'old option'; $valid_input[$id][] = 'newer option'; $valid_input[$id][] = 'latest option';
outputs exactly what I want, but no idea how to use it with $input! :) I believe it should work just fine as$valid_input[$id][] = $input[$id];
but it doesn't.