0

I'm working with the customize section of my theme framework. And I'm trying to get the preview settings in PHP when using refresh, but I only know how to access the saved settings.


Short Story

I want to get the value like this:

if (is_customize_preview()) {
    $outputUrl = get_template_directory_uri() . '/css/styleTemp.css';
    $color1 = //How do I get the preview value??
} else {
    $outputUrl = get_template_directory_uri() . '/css/style.css';   
    $color1 = get_theme_mod('rhyme_color_1', '#000');
}
//Does less compilation to $outputUrl Css file

wp_enqueue_style('main-style', $outputUrl);

Long Story

The reason I am doing it with refresh is so that I can connect the theme_mods to less variables, that I compile on the server. I am then serving the compiled css to the site.

I'm creating the setting

$wp_customize->add_setting(
    'rhyme_color_1',
    array(
        'default'     => '#000000',
        'transport'   => 'refresh',
        'type' => 'theme_mod',
        'capability'     => 'edit_theme_options',
        'sanitize_callback' => 'sanitize_hex_color'
    )
);

Creating the control

    $wp_customize->add_control(
    new WP_Customize_Color_Control(
        $wp_customize,
        'color_1',
        array(
            'label'      => __( 'Color 1', 'rhyme' ),
            'section'    => 'colors',
            'settings'   => 'rhyme_color_1'
        )
    )
);

Getting settings

$color1 = get_theme_mod('rhyme_color_1', '#000');

When I use the get_theme_mod, I only get the saved value not the preview one. So when the user edits a value, he does not see any changes until he saves and updates the page.

1 Answer 1

0

It seems that the problem was that I was adding the function to 'init' and where the preview was not updated. Adding it to wp_enqueue_script solved my issue.

Changed

add_action('init', 'autoCompileLess');

to

add_action('wp_enqueue_scripts', 'autoCompileLess');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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