/** * @deprecated */ function woocommerce_format_hex($hex) { return wc_format_hex($hex); }
/** * Test wc_format_hex(). * * @since 2.2 */ public function test_wc_format_hex() { $this->assertEquals('#CCCCCC', wc_format_hex('CCC')); $this->assertEquals('#CCCCCC', wc_format_hex('#CCC')); $this->assertEquals(null, wc_format_hex(null)); }
/** * Save settings */ public function save() { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); if (isset($_POST['qsot_frontend_css_form_bg'])) { // Save settings $colors = array(); foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) { $colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : ''; } foreach (array('good_msg', 'bad_msg', 'remove') as $K) { foreach (array('_bg', '_border', '_text') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } foreach (array('past_calendar_item', 'calendar_item') as $K) { foreach (array('_bg', '_border', '_text', '_text_hover') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); $options = qsot_options::instance(); $options->{'qsot-event-frontend-colors'} = $colors; if ($old_colors != $colors) { QSOT::compile_frontend_styles(); } } } }
/** * Save settings */ public function save() { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); if (isset($_POST['woocommerce_frontend_css_primary'])) { // Save settings $primary = !empty($_POST['woocommerce_frontend_css_primary']) ? wc_format_hex($_POST['woocommerce_frontend_css_primary']) : ''; $secondary = !empty($_POST['woocommerce_frontend_css_secondary']) ? wc_format_hex($_POST['woocommerce_frontend_css_secondary']) : ''; $highlight = !empty($_POST['woocommerce_frontend_css_highlight']) ? wc_format_hex($_POST['woocommerce_frontend_css_highlight']) : ''; $content_bg = !empty($_POST['woocommerce_frontend_css_content_bg']) ? wc_format_hex($_POST['woocommerce_frontend_css_content_bg']) : ''; $subtext = !empty($_POST['woocommerce_frontend_css_subtext']) ? wc_format_hex($_POST['woocommerce_frontend_css_subtext']) : ''; $colors = array('primary' => $primary, 'secondary' => $secondary, 'highlight' => $highlight, 'content_bg' => $content_bg, 'subtext' => $subtext); // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'woocommerce'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); update_option('woocommerce_frontend_css_colors', $colors); if ($old_colors != $colors) { woocommerce_compile_less_styles(); } } } }
/** * Update plugin color options. * * @return void * @since 1.0.0 */ public function update_color_options($value = false) { global $pagenow; $colors_options = array(); foreach (YITH_WCWL_Init()->colors_options as $name => $option) { foreach ($option as $id => $color) { $default_value = isset($colors_options[$name][$id]) ? $colors_options[$name][$id] : ''; if (isset($_POST['yith_wcwl_color_' . $name . '_' . $id]) && !empty($_POST['yith_wcwl_color_' . $name . '_' . $id])) { $colors_options[$name][$id] = function_exists('wc_format_hex') ? wc_format_hex($_POST['yith_wcwl_color_' . $name . '_' . $id]) : woocommerce_format_hex($_POST['yith_wcwl_color_' . $name . '_' . $id]); } else { $colors_options[$name][$id] = $default_value; } } } update_option('yith_wcwl_frontend_css_colors', maybe_serialize($colors_options)); return null; }
/** * Update plugin options. * * @return void * @since 1.0.0 */ public function update_options() { foreach ($this->options as $option) { woocommerce_update_options($option); } foreach ($this->colors_options as $name => $option) { foreach ($option as $id => $color) { if (function_exists('wc_format_hex')) { $this->colors_options[$name][$id] = isset($_POST['yith_wcwl_color_' . $name . '_' . $id]) && !empty($_POST['yith_wcwl_color_' . $name . '_' . $id]) ? wc_format_hex($_POST['yith_wcwl_color_' . $name . '_' . $id]) : ''; } else { $this->colors_options[$name][$id] = isset($_POST['yith_wcwl_color_' . $name . '_' . $id]) && !empty($_POST['yith_wcwl_color_' . $name . '_' . $id]) ? woocommerce_format_hex($_POST['yith_wcwl_color_' . $name . '_' . $id]) : ''; } } } update_option('yith_wcwl_frontend_css_colors', maybe_serialize($this->colors_options)); }
/** * Save settings */ public function save() { $settings = $this->get_settings(); WC_Admin_Settings::save_fields($settings); if (isset($_POST['woocommerce_frontend_css_primary'])) { // Save settings $primary = !empty($_POST['woocommerce_frontend_css_primary']) ? wc_format_hex($_POST['woocommerce_frontend_css_primary']) : ''; $secondary = !empty($_POST['woocommerce_frontend_css_secondary']) ? wc_format_hex($_POST['woocommerce_frontend_css_secondary']) : ''; $highlight = !empty($_POST['woocommerce_frontend_css_highlight']) ? wc_format_hex($_POST['woocommerce_frontend_css_highlight']) : ''; $content_bg = !empty($_POST['woocommerce_frontend_css_content_bg']) ? wc_format_hex($_POST['woocommerce_frontend_css_content_bg']) : ''; $subtext = !empty($_POST['woocommerce_frontend_css_subtext']) ? wc_format_hex($_POST['woocommerce_frontend_css_subtext']) : ''; $colors = array('primary' => $primary, 'secondary' => $secondary, 'highlight' => $highlight, 'content_bg' => $content_bg, 'subtext' => $subtext); $old_colors = get_option('woocommerce_frontend_css_colors'); update_option('woocommerce_frontend_css_colors', $colors); if ($old_colors != $colors) { woocommerce_compile_less_styles(); } } }
/** * Save settings */ public function save() { $settings = $this->get_settings(); $filtered_settings = $image_id_fields = array(); // filter out the image ids types, because WC barfs on itself over them foreach ($settings as $field) { if ('qsot-image-ids' == $field['type']) { $image_id_fields[] = $field; } else { $filtered_settings[] = $field; } } // only allow wc to save the 'safe' ones WC_Admin_Settings::save_fields($filtered_settings); // handle any image id fields foreach ($image_id_fields as $field) { // if the field did not have any values passed, then skip it if (!isset($_POST[$field['id']])) { continue; } $raw_values = $_POST[$field['id']]; // next sanitize the individual values for the field $values = array_filter(array_map('absint', $raw_values)); // allow modification of the data $values = apply_filters('woocommerce_admin_settings_sanitize_option', $values, $field, $raw_values); $values = apply_filters('woocommerce_admin_settings_sanitize_option_' . $field['id'], $values, $field, $raw_values); // update the value update_option($field['id'], $values); } if (isset($_POST['qsot_frontend_css_form_bg'])) { // Save settings $colors = array(); foreach (array('form_bg', 'form_border', 'form_action_bg', 'form_helper') as $k) { $colors[$k] = !empty($_POST['qsot_frontend_css_' . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $k]) : ''; } foreach (array('good_msg', 'bad_msg', 'remove') as $K) { foreach (array('_bg', '_border', '_text') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } foreach (array('past_calendar_item', 'calendar_item') as $K) { foreach (array('_bg', '_border', '_text', '_text_hover') as $k) { $colors[$K . $k] = !empty($_POST['qsot_frontend_css_' . $K . $k]) ? wc_format_hex($_POST['qsot_frontend_css_' . $K . $k]) : ''; } } // Check the colors. $valid_colors = true; foreach ($colors as $color) { if (!preg_match('/^#[a-f0-9]{6}$/i', $color)) { $valid_colors = false; WC_Admin_Settings::add_error(sprintf(__('Error saving the Frontend Styles, %s is not a valid color, please use only valid colors code.', 'opentickets-community-edition'), $color)); break; } } if ($valid_colors) { $old_colors = get_option('woocommerce_frontend_css_colors'); $options = qsot_options::instance(); $options->{'qsot-event-frontend-colors'} = $colors; if ($old_colors != $colors) { QSOT::compile_frontend_styles(); } } } }