WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


In response to Chip, here's what I have (stubbed, obviously):

function lblg_sanitize_options( $input ){
global $lblg_shortname, $lblg_default_options;

echo "Input: ";

If I do something similar using, e.g., Oenology and do a print_r($input);, I get the expected Array( etc.


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?


Might the various slugs/shortnames/pagenames be conflicting somehow?


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?

share|improve this question
Can you post (pastebin, etc.) your entire options code? Trying to piecemeal this might not be effective. – Chip Bennett May 12 '11 at 15:59
Chip: the code is lousy with debug messages, so it won't work at the moment, but here's an intermediate Hg format. bitbucket.org/zamoose/lblg/src/60ba9a5d09c9/functions.php bitbucket.org/zamoose/lblg/src/60ba9a5d09c9/includes/functions/… and bitbucket.org/zamoose/lblg/src/60ba9a5d09c9/includes/functions/… – ZaMoose May 12 '11 at 17:17
Or you could hg clone http://bitbucket.org/zamoose/lblg – ZaMoose May 12 '11 at 17:17

The $input variable is not passed to the validate function by default. You need to declare it, e.g. not this:

function mytheme_validate_settings() {}

But rather, this:

function mytheme_validate_settings( $input ) {}

(Or maybe I'm the only one who's made that bone-headed mistake before?) :)


The other thing to check: does the $optiongroup in register_setting() match the argument passed to settings_fields() in your form markup?

share|improve this answer
No, I've got that. I'm actually taking a page from your Oenology setup, it's just not working. – ZaMoose May 12 '11 at 13:29
Next thing to check: $optiongroup. See edit. – Chip Bennett May 12 '11 at 13:42
Check the edits above. – ZaMoose May 12 '11 at 15:35
Where is the $optiongroup passed into add_settings_field()? – Felix Eve May 15 '14 at 10:29
Arr, I see, it has to match the variable passed into settings_fields(), not add_settings_field(). – Felix Eve May 15 '14 at 20:46
up vote 1 down vote accepted

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.

share|improve this answer
That's the trickiest part sometimes, isn't it? – Chip Bennett May 20 '11 at 23:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.