Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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';
var_dump($options);
foreach ($options as $value) {
    var_dump($value['id']);
    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
add comment

Your Answer

 
discard

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.