/** * Update Fields * @see WP_Widget->update */ function update($new_instance, $old_instance) { $instance = array(); foreach ($this->fields as $section) { if (isset($section['id']) && !in_array($section['type'], spyropress_exclude_option_types())) { $key = trim($section['id']); $type = $section['type']; if (isset($new_instance[$key])) { $new_value = $new_instance[$key]; $instance[$key] = spyropress_validate_setting($new_value, $type, $key, $section); } } } return $this->after_validate_fields($instance); }
/** * Compile CSS */ function spyropress_compile_dynamic_styles($settings, $values, $meta = false) { global $spyropress, $wp_filesystem; // check if (empty($settings) || empty($values)) { return; } // path to stylesheets $less_file = $spyropress->template_path . 'assets/css/dynamic.less'; $css_file = dynamic_css_path() . 'dynamic.css'; // no dir if (!$wp_filesystem->exists(dynamic_css_path())) { $wp_filesystem->mkdir(untrailingslashit(dynamic_css_path())); } if (!$wp_filesystem->is_readable($less_file)) { return; } // get $insertion from dynamic.less $insertion = $wp_filesystem->get_contents($less_file); $insertion = spyropress_normalize_css($insertion); $regex = "/{{([a-zA-Z0-9\\_\\-\\#\\|\\=]+)}}/"; $fontFamilyNames = array(); // Match custom CSS preg_match_all($regex, $insertion, $matches); // Loop through CSS foreach ($matches[0] as $option) { $value = ''; $option_marker = str_replace(array('{{', '}}'), '', $option); $option_array = explode('|', $option_marker); $option_id = $option_array[0]; $option_type = $settings[$option_id]['type']; if (!in_array($option_type, spyropress_exclude_option_types())) { // get the value if ($meta) { global $post; $value = get_post_meta($post->ID, $option_id, true); } elseif (isset($values[$option_id])) { $value = $values[$option_id]; } if (!isset($option_array[1])) { $value = spyropress_generate_css_by_type($value, $option_type, $settings[$option_id], $fontFamilyNames); } else { $value = $value[$option_array[1]]; } // insert CSS, even if the value is empty if (is_string($value)) { $insertion = stripslashes(str_replace($option, $value, $insertion)); } else { $insertion = stripslashes(str_replace($option, '', $insertion)); } } // end if } // end foreach if (!empty($fontFamilyNames)) { $r = update_option('_spyropress_google_fontfamilies', array_unique($fontFamilyNames)); } return $insertion; }