function alum_sanitize_hex($input) { return maybe_hash_hex_color($input); }
/** * Save the data for the gallery section. * * @since 1.0.0. * * @param array $data The data from the $_POST array for the section. * @return array The cleaned data. */ public function save_gallery($data) { $clean_data = array(); if (isset($data['columns'])) { if (in_array($data['columns'], range(1, 4))) { $clean_data['columns'] = $data['columns']; } } if (isset($data['caption-color'])) { if (in_array($data['caption-color'], array('light', 'dark'))) { $clean_data['caption-color'] = $data['caption-color']; } } if (isset($data['captions'])) { if (in_array($data['captions'], array('none', 'overlay', 'reveal'))) { $clean_data['captions'] = $data['captions']; } } if (isset($data['aspect'])) { if (in_array($data['aspect'], array('none', 'landscape', 'portrait', 'square'))) { $clean_data['aspect'] = $data['aspect']; } } if (isset($data['background-image']['image-id'])) { $clean_data['background-image'] = ttfmake_sanitize_image_id($data['background-image']['image-id']); } if (isset($data['title'])) { $clean_data['title'] = $clean_data['label'] = apply_filters('title_save_pre', $data['title']); } if (isset($data['darken'])) { $clean_data['darken'] = 1; } else { $clean_data['darken'] = 0; } if (isset($data['background-color'])) { $clean_data['background-color'] = maybe_hash_hex_color($data['background-color']); } if (isset($data['background-style'])) { if (in_array($data['background-style'], array('tile', 'cover'))) { $clean_data['background-style'] = $data['background-style']; } } if (isset($data['gallery-item-order'])) { $clean_data['gallery-item-order'] = array_map(array('TTFMAKE_Builder_Save', 'clean_section_id'), explode(',', $data['gallery-item-order'])); } if (isset($data['gallery-items']) && is_array($data['gallery-items'])) { foreach ($data['gallery-items'] as $id => $item) { if (isset($item['title'])) { $clean_data['gallery-items'][$id]['title'] = apply_filters('title_save_pre', $item['title']); } if (isset($item['link'])) { $clean_data['gallery-items'][$id]['link'] = esc_url_raw($item['link']); } if (isset($item['description'])) { $clean_data['gallery-items'][$id]['description'] = sanitize_post_field('post_content', $item['description'], get_post() ? get_the_ID() : 0, 'db'); } if (isset($item['image-id'])) { $clean_data['gallery-items'][$id]['image-id'] = ttfmake_sanitize_image_id($item['image-id']); } } } return $clean_data; }
/** * Clean the data being passed when saving the Banner layout. * * @param array $data Array of data inputs being passed. * * @return array Clean data. */ public function save_banner($data) { $clean_data = array(); $clean_data['title'] = $clean_data['label'] = isset($data['title']) ? apply_filters('title_save_pre', $data['title']) : ''; $clean_data['hide-arrows'] = isset($data['hide-arrows']) && 1 === (int) $data['hide-arrows'] ? 1 : 0; $clean_data['hide-dots'] = isset($data['hide-dots']) && 1 === (int) $data['hide-dots'] ? 1 : 0; $clean_data['autoplay'] = isset($data['autoplay']) && 1 === (int) $data['autoplay'] ? 1 : 0; if (isset($data['transition']) && in_array($data['transition'], array('fade', 'scrollHorz', 'none'))) { $clean_data['transition'] = $data['transition']; } if (isset($data['delay'])) { $clean_data['delay'] = absint($data['delay']); } if (isset($data['height'])) { $clean_data['height'] = absint($data['height']); } if (isset($data['responsive']) && in_array($data['responsive'], array('aspect', 'balanced'))) { $clean_data['responsive'] = $data['responsive']; } if (isset($data['banner-slide-order'])) { $clean_data['banner-slide-order'] = array_map(array('TTFMAKE_Builder_Save', 'clean_section_id'), explode(',', $data['banner-slide-order'])); } if (isset($data['banner-slides']) && is_array($data['banner-slides'])) { foreach ($data['banner-slides'] as $id => $slide) { if (isset($slide['content'])) { $clean_data['banner-slides'][$id]['content'] = sanitize_post_field('post_content', $slide['content'], get_post() ? get_the_ID() : 0, 'db'); } if (isset($slide['background-color'])) { $clean_data['banner-slides'][$id]['background-color'] = maybe_hash_hex_color($slide['background-color']); } $clean_data['banner-slides'][$id]['darken'] = isset($slide['darken']) && 1 === (int) $slide['darken'] ? 1 : 0; if (isset($slide['image-id'])) { $clean_data['banner-slides'][$id]['image-id'] = ttfmake_sanitize_image_id($slide['image-id']); } $clean_data['banner-slides'][$id]['alignment'] = isset($slide['alignment']) && in_array($slide['alignment'], array('none', 'left', 'right')) ? $slide['alignment'] : 'none'; if (isset($slide['state'])) { $clean_data['banner-slides'][$id]['state'] = in_array($slide['state'], array('open', 'closed')) ? $slide['state'] : 'open'; } if (isset($slide['spine_slide_url'])) { $clean_data['banner-slides'][$id]['slide-url'] = esc_url_raw($slide['spine_slide_url']); } } } if (isset($data['section-classes'])) { $clean_data['section-classes'] = $this->clean_classes($data['section-classes']); } if (isset($data['section-wrapper'])) { $clean_data['section-wrapper'] = $this->clean_classes($data['section-wrapper']); } if (isset($data['column-classes'])) { $clean_data['column-classes'] = $this->clean_classes($data['column-classes']); } if (isset($data['label'])) { $clean_data['label'] = sanitize_text_field($data['label']); } if (isset($data['background-img'])) { $clean_data['background-img'] = esc_url_raw($data['background-img']); } if (isset($data['background-mobile-img'])) { $clean_data['background-mobile-img'] = esc_url_raw($data['background-mobile-img']); } $clean_data = apply_filters('spine_builder_save_banner', $clean_data, $data); return $clean_data; }
/** * Get the CSS for a slide. * * @since 1.0.0. * * @param array $slide The slide data. * @param array $ttfmake_section_data The section data. * @return string The CSS. */ function ttfmake_builder_banner_slide_style($slide, $ttfmake_section_data) { $slide_style = ''; // Background color if (isset($slide['background-color']) && '' !== $slide['background-color']) { $slide_style .= 'background-color:' . maybe_hash_hex_color($slide['background-color']) . ';'; } // Background image if (isset($slide['image-id']) && 0 !== ttfmake_sanitize_image_id($slide['image-id'])) { $image_src = ttfmake_get_image_src($slide['image-id'], 'full'); if (isset($image_src[0])) { $slide_style .= 'background-image: url(\'' . addcslashes(esc_url_raw($image_src[0]), '"') . '\');'; } } /** * Allow developers to change the CSS for a Banner section. * * @since 1.2.3. * * @param string $slide_style The CSS for the banner. * @param array $slide The slide data. * @param array $ttfmake_section_data The section data. */ return apply_filters('make_builder_banner_slide_style', esc_attr($slide_style), $slide, $ttfmake_section_data); }
function eryn_sanitize_color($input) { return maybe_hash_hex_color($input); }
<label for="<?php echo $section_name; ?> [background-color]"><?php _e('Background color', 'make'); ?> </label> </h4> <input id="<?php echo $section_name; ?> [background-color]" type="text" name="<?php echo $section_name; ?> [background-color]" class="ttfmake-banner-slide-background-color" value="<?php echo maybe_hash_hex_color($background_color); ?> "/> </div> <div class="ttfmake-banner-slide-alignment-wrapper"> <h4> <label for="<?php echo $section_name; ?> [alignment]"><?php _e('Content position', 'make'); ?> </label> </h4> <select id="<?php
function premier_sanitize_color($input) { return maybe_hash_hex_color($input); }
/** * Build the CSS rules for the color scheme. * * @since 1.5.0. * * @return void */ function ttfmake_css_color() { /** * Global */ // Primary color $color_primary = maybe_hash_hex_color(get_theme_mod('color-primary', ttfmake_get_default('color-primary'))); if ($color_primary !== ttfmake_get_default('color-primary')) { ttfmake_get_css()->add(array('selectors' => array('.color-primary-text', 'a', '.entry-author-byline a.vcard', '.entry-footer a:hover', '.comment-form .required', 'ul.ttfmake-list-dot li:before', 'ol.ttfmake-list-dot li:before', '.entry-comment-count a:hover', '.comment-count-icon a:hover'), 'declarations' => array('color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.color-primary-background', '.ttfmake-button.color-primary-background'), 'declarations' => array('background-color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.color-primary-border'), 'declarations' => array('border-color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation ul.menu ul a:hover', '.site-navigation ul.menu ul a:focus', '.site-navigation .menu ul ul a:hover', '.site-navigation .menu ul ul a:focus'), 'declarations' => array('background-color' => $color_primary), 'media' => 'screen and (min-width: 800px)')); } // Secondary color $color_secondary = maybe_hash_hex_color(get_theme_mod('color-secondary', ttfmake_get_default('color-secondary'))); if ($color_secondary !== ttfmake_get_default('color-secondary')) { ttfmake_get_css()->add(array('selectors' => array('.color-secondary-text', '.builder-section-banner .cycle-pager', '.ttfmake-shortcode-slider .cycle-pager', '.builder-section-banner .cycle-prev:before', '.builder-section-banner .cycle-next:before', '.ttfmake-shortcode-slider .cycle-prev:before', '.ttfmake-shortcode-slider .cycle-next:before', '.ttfmake-shortcode-slider .cycle-caption'), 'declarations' => array('color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.color-secondary-background', 'blockquote.ttfmake-testimonial', 'tt', 'kbd', 'pre', 'code', 'samp', 'var', 'textarea', 'input[type="date"]', 'input[type="datetime"]', 'input[type="datetime-local"]', 'input[type="email"]', 'input[type="month"]', 'input[type="number"]', 'input[type="password"]', 'input[type="search"]', 'input[type="tel"]', 'input[type="text"]', 'input[type="time"]', 'input[type="url"]', 'input[type="week"]', '.ttfmake-button.color-secondary-background', 'button.color-secondary-background', 'input[type="button"].color-secondary-background', 'input[type="reset"].color-secondary-background', 'input[type="submit"].color-secondary-background', '.sticky-post-label', '.widget_tag_cloud a'), 'declarations' => array('background-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu', '.site-navigation .menu .children'), 'declarations' => array('background-color' => $color_secondary), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.color-secondary-border', 'table', 'table th', 'table td', '.header-layout-3 .site-navigation .menu'), 'declarations' => array('border-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('hr', 'hr.ttfmake-line-dashed', 'hr.ttfmake-line-double', 'blockquote.ttfmake-testimonial:after'), 'declarations' => array('border-top-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.comment-body', '.post', '.widget li'), 'declarations' => array('border-bottom-color' => $color_secondary))); } // Text color $color_text = maybe_hash_hex_color(get_theme_mod('color-text', ttfmake_get_default('color-text'))); if ($color_text !== ttfmake_get_default('color-text')) { ttfmake_get_css()->add(array('selectors' => array('.color-text', 'body', '.entry-date a', 'button', 'input', 'select', 'textarea', '[class*="navigation"] .nav-previous a', '[class*="navigation"] .nav-previous span', '[class*="navigation"] .nav-next a', '[class*="navigation"] .nav-next span'), 'declarations' => array('color' => $color_text))); // These placeholder selectors have to be isolated in individual rules. // See http://css-tricks.com/snippets/css/style-placeholder-text/#comment-96771 ttfmake_get_css()->add(array('selectors' => array('::-webkit-input-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array(':-moz-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array('::-moz-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array(':-ms-input-placeholder'), 'declarations' => array('color' => $color_text))); } // Detail color $color_detail = maybe_hash_hex_color(get_theme_mod('color-detail', ttfmake_get_default('color-detail'))); if ($color_detail !== ttfmake_get_default('color-detail')) { ttfmake_get_css()->add(array('selectors' => array('.color-detail-text', '.builder-section-banner .cycle-pager .cycle-pager-active', '.ttfmake-shortcode-slider .cycle-pager .cycle-pager-active', '.entry-footer a', '.entry-footer .fa', '.post-categories li:after', '.post-tags li:after', '.comment-count-icon:before', '.entry-comment-count a', '.comment-count-icon a'), 'declarations' => array('color' => $color_detail))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .page_item_has_children a:after', '.site-navigation .menu-item-has-children a:after'), 'declarations' => array('color' => $color_detail), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu a', '.site-navigation .menu .children a'), 'declarations' => array('border-bottom-color' => $color_detail), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.color-detail-background'), 'declarations' => array('background-color' => $color_detail))); ttfmake_get_css()->add(array('selectors' => array('.color-detail-border'), 'declarations' => array('border-color' => $color_detail))); } // Link Hover/Focus Color $color_primary_link = maybe_hash_hex_color(get_theme_mod('color-primary-link', ttfmake_get_default('color-primary-link'))); if ($color_primary_link && $color_primary_link !== ttfmake_get_default('color-primary-link')) { ttfmake_get_css()->add(array('selectors' => array('a:hover', 'a:focus', '.entry-author-byline a.vcard:hover', '.entry-author-byline a.vcard:focus'), 'declarations' => array('color' => $color_primary_link))); } // Main background color $main_background_color = maybe_hash_hex_color(get_theme_mod('main-background-color', ttfmake_get_default('main-background-color'))); $main_background_color_opacity = ttfmake_sanitize_float(get_theme_mod('main-background-color-opacity', ttfmake_get_default('main-background-color-opacity'))); if ($main_background_color !== ttfmake_get_default('main-background-color') || $main_background_color_opacity !== (double) ttfmake_get_default('main-background-color-opacity')) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($main_background_color) . ', ' . $main_background_color_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-content', 'body.mce-content-body'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'))); } /** * Header */ // Header text color $header_text_color = maybe_hash_hex_color(get_theme_mod('header-text-color', ttfmake_get_default('header-text-color'))); if ($header_text_color !== ttfmake_get_default('header-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-header', '.site-title', '.site-title a', '.site-navigation .menu li a'), 'declarations' => array('color' => $header_text_color))); } // Header background color $header_background_color = maybe_hash_hex_color(get_theme_mod('header-background-color', ttfmake_get_default('header-background-color'))); $header_background_color_opacity = ttfmake_sanitize_float(get_theme_mod('header-background-color-opacity', ttfmake_get_default('header-background-color-opacity'))); if ($header_background_color !== ttfmake_get_default('header-background-color') || $header_background_color_opacity !== (double) ttfmake_get_default('header-background-color-opacity')) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($header_background_color) . ', ' . $header_background_color_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-header-main'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'))); } /** * Site Title & Tagline */ // Site title $color_site_title = maybe_hash_hex_color(get_theme_mod('color-site-title', ttfmake_get_default('color-site-title'))); if ($color_site_title && ($color_site_title !== ttfmake_get_default('color-site-title') || $header_text_color !== $color_site_title)) { ttfmake_get_css()->add(array('selectors' => array('.site-header .site-title', '.site-header .site-title a'), 'declarations' => array('color' => $color_site_title))); } // Tagline $color_tagline = maybe_hash_hex_color(get_theme_mod('color-site-tagline', ttfmake_get_default('color-site-tagline'))); if ($color_tagline && ($color_tagline !== ttfmake_get_default('color-site-tagline') || $header_text_color !== $color_tagline)) { ttfmake_get_css()->add(array('selectors' => array('.site-header .site-description'), 'declarations' => array('color' => $color_tagline))); } /** * Main Menu */ // Menu Item Text $color_nav_text = maybe_hash_hex_color(get_theme_mod('color-nav-text', ttfmake_get_default('color-nav-text'))); if ($color_nav_text && $color_nav_text !== ttfmake_get_default('color-nav-text')) { ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu li a'), 'declarations' => array('color' => $color_nav_text))); } // Menu Item Text hover $color_nav_text_hover = maybe_hash_hex_color(get_theme_mod('color-nav-text-hover', ttfmake_get_default('color-nav-text-hover'))); if ($color_nav_text_hover && $color_nav_text_hover !== ttfmake_get_default('color-nav-text-hover')) { ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu li a:hover', '.site-navigation .menu li a:focus'), 'declarations' => array('color' => $color_nav_text_hover))); } // Sub-Menu Item Text $color_subnav_text = maybe_hash_hex_color(get_theme_mod('color-subnav-text', ttfmake_get_default('color-subnav-text'))); if ($color_subnav_text && $color_subnav_text !== ttfmake_get_default('color-subnav-text')) { ttfmake_get_css()->add(array('selectors' => array('.site-navigation ul.menu ul a', '.site-navigation ul.menu ul a', '.site-navigation .menu ul ul a', '.site-navigation .menu ul ul a'), 'declarations' => array('color' => $color_subnav_text), 'media' => 'screen and (min-width: 800px)')); } // Sub-Menu Item Text hover $color_subnav_text_hover = maybe_hash_hex_color(get_theme_mod('color-subnav-text-hover', ttfmake_get_default('color-subnav-text-hover'))); if ($color_subnav_text_hover && $color_subnav_text_hover !== ttfmake_get_default('color-subnav-text-hover')) { ttfmake_get_css()->add(array('selectors' => array('.site-navigation ul.menu ul a:hover', '.site-navigation ul.menu ul a:focus', '.site-navigation .menu ul ul a:hover', '.site-navigation .menu ul ul a:focus'), 'declarations' => array('color' => $color_subnav_text_hover), 'media' => 'screen and (min-width: 800px)')); } // Sub-Menu Item Detail $color_subnav_detail = maybe_hash_hex_color(get_theme_mod('color-subnav-detail', ttfmake_get_default('color-subnav-detail'))); if ($color_subnav_detail && $color_subnav_detail !== ttfmake_get_default('color-subnav-detail')) { ttfmake_get_css()->add(array('selectors' => array('.site-navigation .page_item_has_children a:after', '.site-navigation .menu-item-has-children a:after'), 'declarations' => array('color' => $color_subnav_detail), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu a', '.site-navigation .menu .children a'), 'declarations' => array('border-bottom-color' => $color_subnav_detail), 'media' => 'screen and (min-width: 800px)')); } // Sub-Menu Item Background $color_subnav_background = maybe_hash_hex_color(get_theme_mod('color-subnav-background', ttfmake_get_default('color-subnav-background'))); $color_subnav_background_opacity = ttfmake_sanitize_float(get_theme_mod('color-subnav-background-opacity', ttfmake_get_default('color-subnav-background-opacity'))); if ($color_subnav_background && ($color_subnav_background !== ttfmake_get_default('color-subnav-background') || $color_subnav_background_opacity !== ttfmake_get_default('color-subnav-background-opacity'))) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($color_subnav_background) . ', ' . $color_subnav_background_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu', '.site-navigation .menu .children'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'), 'media' => 'screen and (min-width: 800px)')); } // Sub-Menu Item Background hover $color_subnav_background_hover = maybe_hash_hex_color(get_theme_mod('color-subnav-background-hover', ttfmake_get_default('color-subnav-background-hover'))); $color_subnav_background_hover_opacity = ttfmake_sanitize_float(get_theme_mod('color-subnav-background-hover-opacity', ttfmake_get_default('color-subnav-background-hover-opacity'))); if ($color_subnav_background_hover && ($color_subnav_background_hover !== ttfmake_get_default('color-subnav-background-hover') || $color_subnav_background_hover_opacity !== ttfmake_get_default('color-subnav-background-hover-opacity'))) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($color_subnav_background_hover) . ', ' . $color_subnav_background_hover_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-navigation ul.menu ul a:hover', '.site-navigation ul.menu ul a:focus', '.site-navigation .menu ul ul a:hover', '.site-navigation .menu ul ul a:focus'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'), 'media' => 'screen and (min-width: 800px)')); } // Current Item Background $color_nav_current_item_background = maybe_hash_hex_color(get_theme_mod('color-nav-current-item-background', ttfmake_get_default('color-nav-current-item-background'))); $color_nav_current_item_background_opacity = ttfmake_sanitize_float(get_theme_mod('color-nav-current-item-background-opacity', ttfmake_get_default('color-nav-current-item-background-opacity'))); if ($color_nav_current_item_background && ($color_nav_current_item_background !== ttfmake_get_default('color-nav-current-item-background') || $color_nav_current_item_background_opacity !== ttfmake_get_default('color-nav-current-item-background-opacity'))) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($color_nav_current_item_background) . ', ' . $color_nav_current_item_background_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu li.current_page_item', '.site-navigation .menu .children li.current_page_item', '.site-navigation .menu li.current_page_ancestor', '.site-navigation .menu li.current-menu-item', '.site-navigation .menu .sub-menu li.current-menu-item', '.site-navigation .menu li.current-menu-ancestor'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'), 'media' => 'screen and (min-width: 800px)')); } /** * Header Bar */ // Header Bar text color $header_bar_text_color = maybe_hash_hex_color(get_theme_mod('header-bar-text-color', ttfmake_get_default('header-bar-text-color'))); if ($header_bar_text_color !== ttfmake_get_default('header-bar-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar', '.header-bar a', '.header-bar .menu li a'), 'declarations' => array('color' => $header_bar_text_color))); } // Header Bar link color $header_bar_link_color = maybe_hash_hex_color(get_theme_mod('header-bar-link-color', ttfmake_get_default('header-bar-link-color'))); if ($header_bar_link_color && $header_bar_link_color !== ttfmake_get_default('header-bar-link-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar a', '.header-bar .menu li a', '.header-bar .social-links a'), 'declarations' => array('color' => $header_bar_link_color))); } // Header Bar link hover color $header_bar_link_hover_color = maybe_hash_hex_color(get_theme_mod('header-bar-link-hover-color', ttfmake_get_default('header-bar-link-hover-color'))); if ($header_bar_link_hover_color && $header_bar_link_hover_color !== ttfmake_get_default('header-bar-link-hover-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar a:hover', '.header-bar a:focus', '.header-bar .menu li a:hover', '.header-bar .menu li a:focus'), 'declarations' => array('color' => $header_bar_link_hover_color))); } // Header Bar border color $header_bar_border_color = maybe_hash_hex_color(get_theme_mod('header-bar-border-color', ttfmake_get_default('header-bar-border-color'))); if ($header_bar_border_color !== ttfmake_get_default('header-bar-border-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar', '.header-bar .search-form input', '.header-social-links li:first-of-type', '.header-social-links li a'), 'declarations' => array('border-color' => $header_bar_border_color))); } // Header Bar background color $header_bar_background_color = maybe_hash_hex_color(get_theme_mod('header-bar-background-color', ttfmake_get_default('header-bar-background-color'))); $header_bar_background_color_opacity = ttfmake_sanitize_float(get_theme_mod('header-bar-background-color-opacity', ttfmake_get_default('header-bar-background-color-opacity'))); if ($header_bar_background_color !== ttfmake_get_default('header-bar-background-color') || $header_bar_background_color_opacity !== (double) ttfmake_get_default('header-bar-background-color-opacity')) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($header_bar_background_color) . ', ' . $header_bar_background_color_opacity; ttfmake_get_css()->add(array('selectors' => array('.header-bar'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'))); } /** * Sidebars */ // Sidebar widget title $color_widget_title = maybe_hash_hex_color(get_theme_mod('color-widget-title-text', ttfmake_get_default('color-widget-title-text'))); if ($color_widget_title && $color_widget_title !== ttfmake_get_default('color-widget-title-text')) { ttfmake_get_css()->add(array('selectors' => array('.sidebar .widget-title', '.sidebar .widgettitle', '.sidebar .widget-title a', '.sidebar .widgettitle a'), 'declarations' => array('color' => $color_widget_title))); } // Sidebar widget body $color_widget_body = maybe_hash_hex_color(get_theme_mod('color-widget-text', ttfmake_get_default('color-widget-text'))); if ($color_widget_body && $color_widget_body !== ttfmake_get_default('color-widget-text')) { ttfmake_get_css()->add(array('selectors' => array('.sidebar .widget'), 'declarations' => array('color' => $color_widget_body))); } // Sidebar link $color_widget_link = maybe_hash_hex_color(get_theme_mod('color-widget-link', ttfmake_get_default('color-widget-link'))); if ($color_widget_link && $color_widget_link !== ttfmake_get_default('color-widget-link')) { ttfmake_get_css()->add(array('selectors' => array('.sidebar a'), 'declarations' => array('color' => $color_widget_link))); } // Sidebar link hover $color_widget_link_hover = maybe_hash_hex_color(get_theme_mod('color-widget-link-hover', ttfmake_get_default('color-widget-link-hover'))); if ($color_widget_link_hover && $color_widget_link_hover !== ttfmake_get_default('color-widget-link-hover')) { ttfmake_get_css()->add(array('selectors' => array('.sidebar a:hover', '.sidebar a:focus'), 'declarations' => array('color' => $color_widget_link_hover))); } // Sidebar widget border $color_widget_border = maybe_hash_hex_color(get_theme_mod('color-widget-border', ttfmake_get_default('color-widget-border'))); if ($color_widget_border && $color_widget_border !== ttfmake_get_default('color-widget-border')) { ttfmake_get_css()->add(array('selectors' => array('.sidebar table', '.sidebar table th', '.sidebar table td', '.sidebar .widget li'), 'declarations' => array('border-color' => $color_widget_border))); } /** * Footer section */ // Footer text color $footer_text_color = maybe_hash_hex_color(get_theme_mod('footer-text-color', ttfmake_get_default('footer-text-color'))); if ($footer_text_color !== ttfmake_get_default('footer-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer', '.site-footer .social-links a'), 'declarations' => array('color' => $footer_text_color))); } // Footer link color $footer_link_color = maybe_hash_hex_color(get_theme_mod('footer-link-color', ttfmake_get_default('footer-link-color'))); if ($footer_link_color !== ttfmake_get_default('footer-link-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer a'), 'declarations' => array('color' => $footer_link_color))); } // Footer link hover color $footer_link_hover_color = maybe_hash_hex_color(get_theme_mod('footer-link-hover-color', ttfmake_get_default('footer-link-hover-color'))); if ($footer_link_hover_color !== ttfmake_get_default('footer-link-hover-color') || $footer_link_color !== ttfmake_get_default('footer-link-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer a:hover', '.site-footer a:focus'), 'declarations' => array('color' => $footer_link_hover_color))); } // Footer border color $footer_border_color = maybe_hash_hex_color(get_theme_mod('footer-border-color', ttfmake_get_default('footer-border-color'))); if ($footer_border_color !== ttfmake_get_default('footer-border-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer *:not(select)'), 'declarations' => array('border-color' => $footer_border_color . ' !important'))); } // Footer background color $footer_background_color = maybe_hash_hex_color(get_theme_mod('footer-background-color', ttfmake_get_default('footer-background-color'))); $footer_background_color_opacity = ttfmake_sanitize_float(get_theme_mod('footer-background-color-opacity', ttfmake_get_default('footer-background-color-opacity'))); if ($footer_background_color !== ttfmake_get_default('footer-background-color') || $footer_background_color_opacity !== (double) ttfmake_get_default('footer-background-color-opacity')) { // Convert to RGBa $color_value = ttfmake_hex_to_rgb($footer_background_color) . ', ' . $footer_background_color_opacity; ttfmake_get_css()->add(array('selectors' => array('.site-footer'), 'declarations' => array('background-color' => 'rgba(' . $color_value . ')'))); } }
/** * Process user options to generate CSS needed to implement the choices. * * This function reads in the options from theme mods and determines whether a CSS rule is needed to implement an * option. CSS is only written for choices that are non-default in order to avoid adding unnecessary CSS. All options * are also filterable allowing for more precise control via a child theme or plugin. * * Note that all CSS for options is present in this function except for the CSS for fonts and the logo, which require * a lot more code to implement. * * @since 1.0.0. * * @return void */ function ttfmake_css_add_rules() { /** * Background section */ $site_background_image = get_theme_mod('background_image', ttfmake_get_default('background_image')); if (!empty($site_background_image)) { // Note that most site background options are handled by internal WordPress functions $site_background_size = ttfmake_sanitize_choice(get_theme_mod('background_size', ttfmake_get_default('background_size')), 'background-size'); ttfmake_get_css()->add(array('selectors' => array('body'), 'declarations' => array('background-size' => $site_background_size))); } /** * Colors section */ // Get and escape options $color_primary = maybe_hash_hex_color(get_theme_mod('color-primary', ttfmake_get_default('color-primary'))); $color_secondary = maybe_hash_hex_color(get_theme_mod('color-secondary', ttfmake_get_default('color-secondary'))); $color_text = maybe_hash_hex_color(get_theme_mod('color-text', ttfmake_get_default('color-text'))); $color_detail = maybe_hash_hex_color(get_theme_mod('color-detail', ttfmake_get_default('color-detail'))); // Primary color if ($color_primary !== ttfmake_get_default('color-primary')) { ttfmake_get_css()->add(array('selectors' => array('.color-primary-text', 'a', '.entry-author-byline a.vcard', '.entry-footer a:hover', '.comment-form .required', 'ul.ttfmake-list-dot li:before', 'ol.ttfmake-list-dot li:before', '.entry-comment-count a:hover', '.comment-count-icon a:hover'), 'declarations' => array('color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.color-primary-background', '.ttfmake-button.color-primary-background'), 'declarations' => array('background-color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.color-primary-border'), 'declarations' => array('border-color' => $color_primary))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation ul.menu ul a:hover', '.site-navigation ul.menu ul a:focus', '.site-navigation .menu ul ul a:hover', '.site-navigation .menu ul ul a:focus'), 'declarations' => array('background-color' => $color_primary), 'media' => 'screen and (min-width: 800px)')); } // Secondary color if ($color_secondary !== ttfmake_get_default('color-secondary')) { ttfmake_get_css()->add(array('selectors' => array('.color-secondary-text', '.builder-section-banner .cycle-pager', '.ttfmake-shortcode-slider .cycle-pager', '.builder-section-banner .cycle-prev:before', '.builder-section-banner .cycle-next:before', '.ttfmake-shortcode-slider .cycle-prev:before', '.ttfmake-shortcode-slider .cycle-next:before', '.ttfmake-shortcode-slider .cycle-caption'), 'declarations' => array('color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.color-secondary-background', 'blockquote.ttfmake-testimonial', 'tt', 'kbd', 'pre', 'code', 'samp', 'var', 'textarea', 'input[type="date"]', 'input[type="datetime"]', 'input[type="datetime-local"]', 'input[type="email"]', 'input[type="month"]', 'input[type="number"]', 'input[type="password"]', 'input[type="search"]', 'input[type="tel"]', 'input[type="text"]', 'input[type="time"]', 'input[type="url"]', 'input[type="week"]', '.ttfmake-button.color-secondary-background', 'button.color-secondary-background', 'input[type="button"].color-secondary-background', 'input[type="reset"].color-secondary-background', 'input[type="submit"].color-secondary-background', '.sticky-post-label', '.widget_tag_cloud a'), 'declarations' => array('background-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu', '.site-navigation .menu .children'), 'declarations' => array('background-color' => $color_secondary), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.color-secondary-border', 'table', 'table th', 'table td', '.header-layout-3 .site-navigation .menu'), 'declarations' => array('border-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('hr', 'hr.ttfmake-line-dashed', 'hr.ttfmake-line-double', 'blockquote.ttfmake-testimonial:after'), 'declarations' => array('border-top-color' => $color_secondary))); ttfmake_get_css()->add(array('selectors' => array('.comment-body', '.post', '.widget li'), 'declarations' => array('border-bottom-color' => $color_secondary))); } // Text color if ($color_text !== ttfmake_get_default('color-text')) { ttfmake_get_css()->add(array('selectors' => array('.color-text', 'body', '.entry-date a', 'body', 'button', 'input', 'select', 'textarea', '[class*="navigation"] .nav-previous a', '[class*="navigation"] .nav-previous span', '[class*="navigation"] .nav-next a', '[class*="navigation"] .nav-next span'), 'declarations' => array('color' => $color_text))); // These placeholder selectors have to be isolated in individual rules. // See http://css-tricks.com/snippets/css/style-placeholder-text/#comment-96771 ttfmake_get_css()->add(array('selectors' => array('::-webkit-input-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array(':-moz-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array('::-moz-placeholder'), 'declarations' => array('color' => $color_text))); ttfmake_get_css()->add(array('selectors' => array(':-ms-input-placeholder'), 'declarations' => array('color' => $color_text))); } // Detail color if ($color_detail !== ttfmake_get_default('color-detail')) { ttfmake_get_css()->add(array('selectors' => array('.color-detail-text', '.builder-section-banner .cycle-pager .cycle-pager-active', '.ttfmake-shortcode-slider .cycle-pager .cycle-pager-active', '.post-categories li:after', '.post-tags li:after', '.comment-count-icon:before', '.entry-comment-count a', '.comment-count-icon a'), 'declarations' => array('color' => $color_detail))); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu-item-has-children a:after'), 'declarations' => array('color' => $color_detail), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu a', '.site-navigation .menu .sub-menu a'), 'declarations' => array('border-bottom-color' => $color_detail), 'media' => 'screen and (min-width: 800px)')); ttfmake_get_css()->add(array('selectors' => array('.color-detail-background'), 'declarations' => array('background-color' => $color_detail))); ttfmake_get_css()->add(array('selectors' => array('.color-detail-border'), 'declarations' => array('border-color' => $color_detail))); } /** * Header section */ // Get and escape options $header_text_color = maybe_hash_hex_color(get_theme_mod('header-text-color', ttfmake_get_default('header-text-color'))); $header_background_color = maybe_hash_hex_color(get_theme_mod('header-background-color', ttfmake_get_default('header-background-color'))); $header_background_image = get_theme_mod('header-background-image', ttfmake_get_default('header-background-image')); $header_bar_text_color = maybe_hash_hex_color(get_theme_mod('header-bar-text-color', ttfmake_get_default('header-bar-text-color'))); $header_bar_border_color = maybe_hash_hex_color(get_theme_mod('header-bar-border-color', ttfmake_get_default('header-bar-border-color'))); $header_bar_background_color = maybe_hash_hex_color(get_theme_mod('header-bar-background-color', ttfmake_get_default('header-bar-background-color'))); // Header text color if ($header_text_color !== ttfmake_get_default('header-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-header', '.site-header a', '.site-navigation .menu li a'), 'declarations' => array('color' => $header_text_color))); } // Header background color if ($header_background_color !== ttfmake_get_default('header-background-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-header-main'), 'declarations' => array('background-color' => $header_background_color))); } // Header background image if (!empty($header_background_image)) { // Escape the background image URL properly $header_background_image = addcslashes(esc_url_raw($header_background_image), '"'); // Get and escape related options $header_background_size = ttfmake_sanitize_choice(get_theme_mod('header-background-size', ttfmake_get_default('header-background-size')), 'header-background-size'); $header_background_repeat = ttfmake_sanitize_choice(get_theme_mod('header-background-repeat', ttfmake_get_default('header-background-repeat')), 'header-background-repeat'); $header_background_position = ttfmake_sanitize_choice(get_theme_mod('header-background-position', ttfmake_get_default('header-background-position')), 'header-background-position'); // All variables are escaped at this point ttfmake_get_css()->add(array('selectors' => array('.site-header-main'), 'declarations' => array('background-image' => 'url("' . $header_background_image . '")', 'background-size' => $header_background_size, 'background-repeat' => $header_background_repeat, 'background-position' => $header_background_position . ' center'))); } // Header Bar text color if ($header_bar_text_color !== ttfmake_get_default('header-bar-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar'), 'declarations' => array('color' => $header_bar_text_color))); } // Header Bar border color if ($header_bar_border_color !== ttfmake_get_default('header-bar-border-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar', '.header-bar .search-form input', '.header-social-links li:first-of-type', '.header-social-links li a'), 'declarations' => array('border-color' => $header_bar_border_color))); } // Header Bar background color if ($header_bar_background_color !== ttfmake_get_default('header-bar-background-color')) { ttfmake_get_css()->add(array('selectors' => array('.header-bar'), 'declarations' => array('background-color' => $header_bar_background_color))); } /** * Site Title & Tagline section */ $color_site_title = maybe_hash_hex_color(get_theme_mod('color-site-title', ttfmake_get_default('color-site-title'))); if ($color_site_title !== ttfmake_get_default('color-site-title') || $header_text_color !== $color_site_title) { ttfmake_get_css()->add(array('selectors' => array('.site-header .site-title', '.site-header .site-title a'), 'declarations' => array('color' => $color_site_title))); } /** * Main section */ // Get and escape options $main_background_color = maybe_hash_hex_color(get_theme_mod('main-background-color', ttfmake_get_default('main-background-color'))); $main_background_image = get_theme_mod('main-background-image', ttfmake_get_default('main-background-image')); $main_content_link_underline = absint(get_theme_mod('main-content-link-underline', ttfmake_get_default('main-content-link-underline'))); // Main background color if ($main_background_color !== ttfmake_get_default('main-background-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-content', 'body.mce-content-body'), 'declarations' => array('background-color' => $main_background_color))); } // Main background image if (!empty($main_background_image)) { // Escape the background image URL properly $main_background_image = addcslashes(esc_url_raw($main_background_image), '"'); // Get and escape related options $main_background_size = ttfmake_sanitize_choice(get_theme_mod('main-background-size', ttfmake_get_default('main-background-size')), 'main-background-size'); $main_background_repeat = ttfmake_sanitize_choice(get_theme_mod('main-background-repeat', ttfmake_get_default('main-background-repeat')), 'main-background-repeat'); $main_background_position = ttfmake_sanitize_choice(get_theme_mod('main-background-position', ttfmake_get_default('main-background-position')), 'main-background-position'); // All variables are escaped at this point ttfmake_get_css()->add(array('selectors' => array('.site-content'), 'declarations' => array('background-image' => 'url("' . $main_background_image . '")', 'background-size' => $main_background_size, 'background-repeat' => $main_background_repeat, 'background-position' => $main_background_position . ' top'))); } // Main Content Link Underline if (1 === $main_content_link_underline) { ttfmake_get_css()->add(array('selectors' => array('.entry-content a'), 'declarations' => array('text-decoration' => 'underline'))); } /** * Footer section */ // Get and escape options $footer_text_color = maybe_hash_hex_color(get_theme_mod('footer-text-color', ttfmake_get_default('footer-text-color'))); $footer_border_color = maybe_hash_hex_color(get_theme_mod('footer-border-color', ttfmake_get_default('footer-border-color'))); $footer_background_color = maybe_hash_hex_color(get_theme_mod('footer-background-color', ttfmake_get_default('footer-background-color'))); $footer_background_image = get_theme_mod('footer-background-image', ttfmake_get_default('footer-background-image')); // Footer text color if ($footer_text_color !== ttfmake_get_default('footer-text-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer'), 'declarations' => array('color' => $footer_text_color))); } // Footer border color if ($footer_border_color !== ttfmake_get_default('footer-border-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer *:not(select)'), 'declarations' => array('border-color' => $footer_border_color . ' !important'))); } // Footer background color if ($footer_background_color !== ttfmake_get_default('footer-background-color')) { ttfmake_get_css()->add(array('selectors' => array('.site-footer'), 'declarations' => array('background-color' => $footer_background_color))); } // Footer background image if (!empty($footer_background_image)) { // Escape the background image URL properly $footer_background_image = addcslashes(esc_url_raw($footer_background_image), '"'); // Get and escape related options $footer_background_size = ttfmake_sanitize_choice(get_theme_mod('footer-background-size', ttfmake_get_default('footer-background-size')), 'footer-background-size'); $footer_background_repeat = ttfmake_sanitize_choice(get_theme_mod('footer-background-repeat', ttfmake_get_default('footer-background-repeat')), 'footer-background-repeat'); $footer_background_position = ttfmake_sanitize_choice(get_theme_mod('footer-background-position', ttfmake_get_default('footer-background-position')), 'footer-background-position'); // All variables are escaped at this point ttfmake_get_css()->add(array('selectors' => array('.site-footer'), 'declarations' => array('background-image' => 'url("' . $footer_background_image . '")', 'background-size' => $footer_background_size, 'background-repeat' => $footer_background_repeat, 'background-position' => $footer_background_position . ' center'))); } /** * Featured image alignment */ $templates = array('blog', 'archive', 'search', 'post', 'page'); foreach ($templates as $template_name) { $key = 'layout-' . $template_name . '-featured-images-alignment'; $default = ttfmake_get_default($key); $alignment = ttfmake_sanitize_choice(get_theme_mod($key, $default), $key); if ($alignment !== $default) { ttfmake_get_css()->add(array('selectors' => array('.' . $template_name . ' .entry-header .entry-thumbnail'), 'declarations' => array('text-align' => $alignment))); } } }
/** * Starts with a HEX color and calculates all other properties. * * @return void */ private function from_hex() { if (!function_exists('sanitize_hex_color')) { require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; } // Is this perhaps a word-color? $word_colors = $this->get_word_colors(); if (array_key_exists($this->color, $word_colors)) { $this->color = '#' . $word_colors[$this->color]; } // Sanitize color $this->hex = sanitize_hex_color(maybe_hash_hex_color($this->color)); $hex = ltrim($this->hex, '#'); // Make sure we have 6 digits for the below calculations if (3 == strlen($hex)) { $hex = ltrim($this->hex, '#'); $hex = substr($hex, 0, 1) . substr($hex, 0, 1) . substr($hex, 1, 1) . substr($hex, 1, 1) . substr($hex, 2, 1) . substr($hex, 2, 1); } // Set red, green, blue $this->red = hexdec(substr($hex, 0, 2)); $this->green = hexdec(substr($hex, 2, 2)); $this->blue = hexdec(substr($hex, 4, 2)); $this->alpha = 1; // set other color properties $this->set_brightness(); $this->set_hsl(); $this->set_luminance(); }
function discovery_sanitize_color($input) { return maybe_hash_hex_color($input); }
/** * Sanitize Color * * If hex code empty or invalid, use default value when empty value is not permitted. * Add # to front of hex code if missing. * * @since 1.1.4 * @param string $setting The setting being sanitized, as provided in defaults array * @param string $input The user-entered value * @return string Sanitized value */ function ctfw_customize_sanitize_color($setting, $input) { // Default values $defaults = ctfw_customize_defaults(); // Return null if hex code invalid $output = sanitize_hex_color($input); // If invalid or empty and empty value not permitted, use default if (empty($output) && !empty($defaults[$setting]['no_empty'])) { $output = $defaults[$setting]['value']; } // Add # if missing $output = maybe_hash_hex_color($output); // Return sanitized, filterable return apply_filters('ctfw_customize_sanitize_color', $output, $setting, $input); }
function indiepro_sanitize_color($input) { return maybe_hash_hex_color($input); }