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

My theme options save routine is below. I'm finding that if the $value['id'] being passed from my options array has a period in it, the data does not get passed and the options appear to break at that point. Should I opt for another character or is there a workaround for using the period character in an option name?

For example, this works fine:

 "id" => "myTheme_color|sidebar",

but this does not (no data is passed for the value):

 "id" => "myTheme_color.sidebar",

The save function is:

function mytheme_add_admin(){
global $themename, $shortname, $options; 
if ( $_GET['page'] == basename(__FILE__) )
    if ( 'save' == $_REQUEST['action'] ) 
        foreach ($options as $value) 
            update_option( $value['id'], stripslashes($_REQUEST[$value['id']]) ); 
        foreach ($options as $value) 
            if( isset( $_REQUEST[ $value['id'] ] ) ) 
                update_option( $value['id'], stripslashes($_REQUEST[ $value['id'] ])  ); 
            echo $value['id'].": ".$_REQUEST[$value['id']]."<br>";
            echo $value['id'].": ".stripslashes($_REQUEST[$value['id']])."<br>";
share|improve this question
You're doing two times the same thing (2xforeach) and the previous variant might just overwrite the option if the not set in $_REQUEST. Probably this is the issue? – hakre Nov 23 '10 at 23:13
Not sure why I had that there, but I've removed it and it does no good. Apparently you can't use periods in options names when using a for loop on the options array at save time. – Scott B Nov 26 '10 at 4:10
up vote 1 down vote accepted

Dots and spaces are replaced by PHP for array indexes via POST and GET. That may cause your problem.

share|improve this answer
Thanks! That explains it. – Scott B Nov 28 '10 at 15:32

I am not sure what the issue is here, this test code works fine for me:

$options = array( 'test_option' => array('id' => 'myTheme_color.sidebar') );
$test = 'test';
foreach ($options as $value) {
    update_option( $value['id'], $test );

From quick look at source code the most likely point for update_option to fail is if SQL query to insert it fails.

My suggestions are to run $wpdb->print_error() after operation to check for failed query and hook into update_option_{$option} and updated_option actions to see if they are firing (source).

share|improve this answer
And if you have not done it, add `define('WP_DEBUG', TRUE); on the testbed. This might reveal more information with $wpdb as well. – hakre Nov 26 '10 at 11:32

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.