/** * Creates a backup of your theme mods * * @since 3.0.0 */ function wpex_backup_mods() { update_option('wpex_total_customizer_backup', wpex_get_mods()); }
/** * Generates inline CSS for styling options * * @since 1.0.0 */ public function loop_through_inline_css($return = 'css') { // Define vars $add_css = ''; $elements_to_alter = ''; $preview_styles = ''; // Get customizer settings $settings = wp_list_pluck($this->sections, 'settings'); // Return if there aren't any settings if (empty($settings)) { return; } // Loop through settings and find inline_css foreach ($settings as $settings_array) { foreach ($settings_array as $setting) { // Store setting ID and default value $setting_id = $setting['id']; // no need to check cause it's required $default = isset($setting['default']) ? $setting['default'] : false; $inline_css = isset($setting['inline_css']) ? $setting['inline_css'] : null; $theme_mod = wpex_get_mod($setting_id, $default); // If mod is equal to default and part of the mods let's remove it // This is a good place since we are looping through all settings anyway if ($this->remove_default_mods) { $get_all_mods = wpex_get_mods(); if ($theme_mod == $default && $get_all_mods && isset($get_all_mods[$setting_id])) { remove_theme_mod($setting_id); } } // These are required for outputting custom CSS if (!$theme_mod || !$inline_css) { continue; } // Get inline_css params $sanitize = isset($inline_css['sanitize']) ? $inline_css['sanitize'] : ''; $target = isset($inline_css['target']) ? $inline_css['target'] : ''; $alter = isset($inline_css['alter']) ? $inline_css['alter'] : ''; $important = isset($inline_css['important']) ? '!important' : false; $media_query = isset($inline_css['media_query']) ? $inline_css['media_query'] : false; // Add to preview_styles array if ('preview_styles' == $return) { $preview_styles['customizer-' . $setting_id] = ''; } // Target and alter vars are required, if they are empty continue onto the next setting if (!$target || !$alter) { continue; } // Sanitize data if ($sanitize) { $theme_mod = wpex_sanitize_data($theme_mod, $sanitize); } else { $theme_mod = $theme_mod; } // Set to array if not $target = is_array($target) ? $target : array($target); // Loop through items foreach ($target as $element) { // Add to elements list if not already for CSS output only if ('css' == $return && !isset($elements_to_alter[$element])) { $elements_to_alter[$element] = array('css' => ''); } // Return CSS or js if (is_array($alter)) { // Loop through elements to alter foreach ($alter as $alter_val) { // Inline CSS if ('css' == $return) { // If it has a media query it's its own thing if ($media_query) { $add_css .= '@media only screen and ' . $media_query . '{' . $element . '{ ' . $alter_val . ':' . $theme_mod . $important . '; }}'; } else { $elements_to_alter[$element]['css'] .= $alter_val . ':' . $theme_mod . $important . ';'; } } elseif ('preview_styles' == $return) { // If it has a media query it's its own thing if ($media_query) { $preview_styles['customizer-' . $setting_id] .= '@media only screen and ' . $media_query . '{' . $element . '{ ' . $alter_val . ':' . $theme_mod . $important . '; }}'; } else { $preview_styles['customizer-' . $setting_id] .= $element . '{ ' . $alter_val . ':' . $theme_mod . $important . '; }'; } } } } else { // Inline CSS if ('css' == $return) { // If it has a media query it's its own thing if ($media_query) { $add_css .= '@media only screen and ' . $media_query . '{' . $element . '{ ' . $alter . ':' . $theme_mod . $important . '; }}'; } else { $elements_to_alter[$element]['css'] .= $alter . ':' . $theme_mod . $important . ';'; } } elseif ('preview_styles' == $return) { // If it has a media query it's its own thing if ($media_query) { $preview_styles['customizer-' . $setting_id] .= '@media only screen and ' . $media_query . '{' . $element . '{ ' . $alter . ':' . $theme_mod . $important . '; }}'; } else { $preview_styles['customizer-' . $setting_id] .= $element . '{ ' . $alter . ':' . $theme_mod . $important . '; }'; } } } } } // End settings_array } // End settings loop // Loop through elements for CSS only if ('css' == $return && $elements_to_alter) { foreach ($elements_to_alter as $element => $array) { if (isset($array['css'])) { $add_css .= $element . '{' . $array['css'] . '}'; } } } // Return inline css if ('css' == $return) { return $add_css; } // Return preview styles if ('preview_styles' == $return) { return $preview_styles; } }