/**
 * This function takes care of copying theme mods as options in our array,
 * cleaning up the db from our theme-mods and then triggering the compiler.
 */
function stachestack_customizer_copy_options()
{
    global $ss_settings;
    $sections = stachestack_customizer_fields();
    foreach ($sections as $section) {
        $fields = $section['fields'];
        foreach ($fields as $field => $args) {
            $value = get_theme_mod($field);
            // Backgrounds are an array of options, so we have to include each one of them separately
            if ('background' == $args['type']) {
                // If we're changing the 'body_bg' setting, save the option to 'html_bg' as well.
                if ('body_bg' == $field) {
                    $ss_settings['html_bg']['background-color'] = $value;
                    // Use lumosity difference to find a text color with great readability
                    if (StacheStack_Color::lumosity_difference($value, '#ffffff') > 5) {
                        $text = '#ffffff';
                    } elseif (StacheStack_Color::lumosity_difference($value, '#222222') > 5) {
                        $text = '#222222';
                    }
                    $ss_settings['font_base']['color'] = $text;
                    $ss_settings['font_h1']['color'] = $text;
                    $ss_settings['font_h2']['color'] = $text;
                    $ss_settings['font_h3']['color'] = $text;
                    $ss_settings['font_h4']['color'] = $text;
                    $ss_settings['font_h5']['color'] = $text;
                    $ss_settings['font_h6']['color'] = $text;
                }
                // Copy the theme_mod to our settings array
                $ss_settings[$field]['background-color'] = $value;
                // Clean up theme mods
                remove_theme_mod($field);
            } elseif ('font' == $args['type']) {
                // Copy the theme_mod to our settings array
                $ss_settings[$field]['font-family'] = $value;
                // Clean up theme mods
                remove_theme_mod($field);
            } else {
                // Copy the theme_mod to our settings array
                $ss_settings[$field] = $value;
                // Clean up theme mods
                remove_theme_mod($field);
            }
        }
    }
    update_option(STACHESTACK_OPT_NAME, $ss_settings);
    $compiler = new StacheStack_Less_PHP();
    add_action('customize_save_after', array($compiler, 'makecss'), 77);
}
function stachestack_lumosity_difference($hex1, $hex2)
{
    _stachestack_deprecated_function(__FUNCTION__, '3.2', 'StacheStack_Color::lumosity_difference()');
    return StacheStack_Color::lumosity_difference($hex1, $hex2);
}