I’m trying to be a good thememaker and pass all my settings through the Settings API, but I’m running into some difficulty in the sanitization callback function.
The core of the problem is this: the $input variable, passed in by default, is empty. My $_POST[options group] is coming through just fine (it has everything I’d expect to see in $input) but, again, $input is empty. Where do I even start looking to debug this?
EDIT 1
In response to Chip, here’s what I have (stubbed, obviously):
function lblg_sanitize_options( $input ){
global $lblg_shortname, $lblg_default_options;
echo "Input: ";
print_r($input);
If I do something similar using, e.g., Oenology and do a print_r($input);
, I get the expected Array(
etc.
EDIT 2
Here’s the results of print_r($_REQUEST);
for my theme:
Array ( [option_page] => lblg_options [action] => update [_wpnonce] => 1f96eb2410 [_wp_http_referer] => /wp-admin/themes.php?page=lblg_options [lblg_options] => Array ( [layout_stylesheet] => Select a layout: [alt_stylesheet] => *none* [use_custom_header] => true [display_footer_copyright] => true [footer_copyright] => [footer_credit_text] => [save] => Save changes ) )
And here it is for Oenology:
Array ( [option_page] => theme_oenology_options [action] => update [_wpnonce] => 748c46a1a1 [_wp_http_referer] => /wp-admin/themes.php?page=oenology-settings [theme_oenology_options] => Array ( [header_nav_menu_position] => below [header_nav_menu_depth] => 1 [display_social_icons] => on [rss_feed] => rss2 [facebook_profile] => [flickr_profile] => [linkedin_profile] => [myspace_profile] => [twitter_profile] => [youtube_profile] => [display_footer_credit] => false [submit-general] => Save Settings ) )
I can’t spot the difference. Can you?
EDIT 3
Might the various slugs/shortnames/pagenames be conflicting somehow?
EDIT 4
Here’s what I’m doing for registration:
function lblg_admin_init(){
global $lblg_shortname;
register_setting( 'lblg_options', $lblg_shortname . '_lblg_options', 'lblg_sanitize_options' );
}
Here’s what I’m calling out, intra-options-form:
settings_fields( 'lblg_options' );
do_settings_sections( 'lblg_options' );
The settings themselves are all being registered in a big loop, in a fashion similar to this:
add_settings_field( $key, $value['name'], '', 'lblg_options', $section );
Further thoughts?
The
$input
variable is not passed to the validate function by default. You need to declare it, e.g. not this:But rather, this:
(Or maybe I’m the only one who’s made that bone-headed mistake before?) 🙂
EDIT:
The other thing to check: does the
$optiongroup
inregister_setting()
match the argument passed tosettings_fields()
in your form markup?Answering my own question by way of an answer Chip has embedded in his excellent settings tutorial, namely: it’s all about Correlating Function Arguments. Apparently some of the variable names/options group names I was using weren’t lining up correctly.