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.

I have recently starting integrating the wordpress customizer into my theme.

Given the fact that i already had a theme options page, i use these values as default values of my new options (in the add_setting parameter).

All my new options are held into a variable called 'theme_options' which is an array of values.

The problem i have is that a user has to visit the customization page and click "save" on his first install to populate the 'theme_options' variable.

I am wondering if there is a way to initialize this field on theme activation directly (just like many theme options framework do).

Thanks in advance !

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

I believe that all you need to do is pass defaults to get_option

function init_theme_options() {
  // check to see if theme options are set
  // Not sure how your options are organized but...
  $defaults = array(
    'opt1' => 'stuff1',
    'opt2' => 'stuff2'
  )
  $theme_options = get_option('theme_option_name',$defaults);
}

If you want to see a very complicated version of this, look at how Twenty Eleven does it.

share|improve this answer
    
Thank you ! I think you're right, it should be done with get_option. –  gnrocks Jan 16 '13 at 4:13
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.