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 am working with the Theme Customizer API and am going crazy trying to find the stored values. The values successfully save and update on the front-end, so they are obviously registered successfully, however, I'm storing the options as theme specific via this method where $this_theme is set as $this_theme = preg_split('/themes\//', get_stylesheet_directory_uri())[1];. The following code is inside of a foreach loop and iterating over a multi-dimensional array with all of the variable metadata for each option (referenced below as $param['foo']).

I'm using this method for dropdown options for font selection and also for colors, but when doing get_theme_mod($this_theme . '_theme_options') the returned results show the font dropdown options but not the WP_Customize_Color_Control options. I'm going crazy trying to find a divergence between the two and have not found any. Thanks so much!

    $wp_customize->add_setting( $this_theme . '_theme_options['. $setting .']', array(
        'default' => $param['default'],
        'sanitize_callback' => 'sanitize_hex_color',
        'type' => 'option',
        'capability' => 'edit_theme_options',
        'priority' => $i

    ) );

    $wp_customize->add_control(
        new WP_Customize_Color_Control(
            $wp_customize,
            $this_theme . '_theme_options_'. $setting,
            array(
                'label'     => $param['label'],
                'section'   => $param['section'],
                'settings'  => $this_theme . '_theme_options['. $setting  .']',
                'priority'  => $i
            )
        )
    );
share|improve this question

2 Answers 2

up vote 2 down vote accepted

If your settings are stored as Theme Mods, rather than as a Settings API option, then you need to pass the appropriate value to the type parameter to $wp_customize->add_setting():

  • 'option': Settings API option (get_option())
  • 'theme_mod': Theme Mods API option (get_theme_mod())

Try changing this:

$wp_customize->add_setting( $this_theme . '_theme_options['. $setting .']', array(
    'default' => $param['default'],
    'sanitize_callback' => 'sanitize_hex_color',
    'type' => 'option',
    'capability' => 'edit_theme_options',
    'priority' => $i

) );

...to this:

$wp_customize->add_setting( $this_theme . '_theme_options['. $setting .']', array(
    'default' => $param['default'],
    'sanitize_callback' => 'sanitize_hex_color',
    // CHANGE ME HERE
    'type' => 'theme_mod',
    'capability' => 'edit_theme_options',
    'priority' => $i

) );
share|improve this answer
    
I had a feeling that could be it, but everywhere in the documentation told me not to do this. I'll try it now and report back :) –  Brian Apr 1 '13 at 16:09
    
Ok, that works... partially. The odd result is that saving a new value via color picker causes it to appear in the returned result of get_theme_mod(), but I have 5 color options and only the one with a new value saved is returned. No worries if you're not sure either, but since I have your ear I figured I would ask. Your answer is correct regardless and much appreciated! –  Brian Apr 1 '13 at 16:12
1  
Ignore that question, for inquiring minds, I had been led to believe by some docs that the preference for declaring color variables was without the preceding # hash. In fact, the default declarations were failing because the correct format is with hash character, e.g. #fff. –  Brian Apr 1 '13 at 16:37

if you add a setting using 'type' => 'option', then you'll have to use get_option instead of get_theme_mod. See this great article to learn more: http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/

share|improve this answer

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.