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.

This question already has an answer here:

I've been following this great tutorial (http://wp.tutsplus.com/tutorials/theme-development/digging-into-the-theme-customizer-overview/) and now I have set the Theme customizer.

As far as I understand the settings I assign in the customizer are saved in the database every time the user "saves" in the theme customizer page. Which means that after activating the theme for the first time and before going to the customizer, the settings are not saved.

My question is, How can I save the settings just after the user activates the theme? (the $wp_customize->add_setting default value)

Pd. I've been looking for some time, and got this hooks: "after_setup_theme", "switch_theme", but I cant figure out how to do it.

Edit: The "duplicate question" answers how to provide a fallback when there is no setting available. Although it might be a workaround, I would like to know how to save (register) the settings when activating the theme.

share|improve this question
Read the answer to the duplicate question till the very end - it does provide a permanent solution. –  Johannes Pille Oct 6 '13 at 10:59
Thanks, Its geting confusing for me on how to do what suggested in the duplicate (add_option) with theme customizer. Anyway I gave up and Im using the fallback solution. –  Alvaro Oct 6 '13 at 11:33
add comment

marked as duplicate by s_ha_dum, brasofilo, Eugene Manuilov, toscho Oct 6 '13 at 8:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

You need only use the default value on the wp_customize and that is all

$wp_customize->add_setting('mytextoption', array(
    'default'        => 'defaultvalue',
    'capability'     => 'edit_theme_options',
    'type'           => 'option',

replace defaultvalue for the value you want, and when the user activate the theme this line will register the default value on the DB only when not exist on the DB

share|improve this answer
So you mean the first register doesnt happen when pressing save in the customizer for the first time, but when activating the theme. right? –  Alvaro Oct 6 '13 at 8:58
add comment

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