/** * Create general CSS style * * @since 1.0.0 * @access public * @param string $property name of the css property * @param string $value value of the css property * @param string $idtag setting id used in wp admin (may be used in live preview js) * used for fetching background and typography settings * @param bool|string $important * @param bool $typography_reset Used for 'typography' property * @return mixed empty if sanitization failed, else the sanitized property array */ function css_rule_sanitized_array($property, $value = '', $idtag = '', $important = false, $typography_reset = false) { if (empty($property)) { return ''; } if ($property == 'background' || $property == 'font' || $property == 'typography') { if (empty($value) && empty($idtag)) { return ''; } } else { if (empty($value)) { return ''; } } /** Load Sanitization functions if not loaded already (for frontend) **/ if (!function_exists('hoot_sanitize_enum')) { require_once trailingslashit(HOOT_INCLUDES) . 'sanitization.php'; } /** Sanitize CSS values **/ switch ($property) { case 'color': case 'background-color': case 'border-color': case 'border-right-color': case 'border-bottom-color': case 'border-top-color': case 'border-left-color': if ('none' == $value || 'transparent' == $value) { $value = 'transparent'; } else { // sanitize color. hoot_sanitize_hex() will return null if $value is not a formatted hex color $value = hoot_sanitize_hex($value); } break; case 'background': if (!empty($value)) { if ('none' == $value || 'transparent' == $value) { $value = 'none'; } else { // sanitize for background color. hoot_sanitize_hex() will return null if $value is not a formatted hex color $value = hoot_sanitize_hex($value); } } elseif (!empty($idtag)) { // use the background function for multiple background properties return $this->background($idtag, $important); } break; case 'background-image': $value = 'url("' . esc_url($value) . '")'; break; case 'background-repeat': $recognized = hoot_enum_background_repeat(); $value = array_key_exists($value, $recognized) ? $value : ''; break; case 'background-position': $recognized = hoot_enum_background_position(); $value = array_key_exists($value, $recognized) ? $value : ''; break; case 'background-attachment': $recognized = hoot_enum_background_attachment(); $value = array_key_exists($value, $recognized) ? $value : ''; break; case 'box-shadow': case '-moz-box-shadow': case '-webkit-box-shadow': $value = esc_attr($value); case 'typography': case 'font': if (!empty($value)) { $property = 'font-family'; $recognized = hoot_enum_font_faces(); $value = stripslashes($value); $value = array_key_exists($value, $recognized) ? $value : ''; } elseif (!empty($idtag)) { // use the typography function for multiple font properties return $this->typography($idtag, $important, $typography_reset); } break; case 'font-family': // Recognized font-families in hoot/options/includes/fonts{-google}.php $recognized = hoot_enum_font_faces(); $value = stripslashes($value); $value = array_key_exists($value, $recognized) ? $value : ''; break; case 'font-style': $recognized = array('inherit', 'initial', 'italic', 'normal', 'oblique'); $value = in_array($value, $recognized) ? $value : ''; break; case 'font-weight': $value_check = intval($value); if (!empty($value_check)) { // for numerical weights like 300, 600 etc. $value = $value_check; } else { // for strings like 'bold', 'light', 'lighter' etc. $recognized = array('bold', 'bolder', 'inherit', 'initial', 'lighter', 'normal'); $value = in_array($value, $recognized) ? $value : ''; } break; case 'text-decoration': $recognized = array('blink', 'inherit', 'initial', 'line-through', 'overline', 'underline'); $value = in_array($value, $recognized) ? $value : ''; break; case 'text-transform': $recognized = array('capitalize', 'inherit', 'initial', 'lowercase', 'none', 'uppercase'); $value = in_array($value, $recognized) ? $value : ''; break; case 'font-size': case 'padding': case 'padding-right': case 'padding-bottom': case 'padding-left': case 'padding-top': case 'margin': case 'margin-right': case 'margin-bottom': case 'margin-left': case 'margin-top': case 'height': case 'max-height': case 'min-height': case 'width': case 'max-width': case 'min-width': $value_check = preg_replace('/px|em|rem/', '', $value); $value_check = intval($value_check); $value = !empty($value_check) || '0' === $value_check || 0 === $value_check ? $value : ''; break; case 'opacity': $value_check = intval($value); $value = !empty($value_check) || '0' === $value_check || 0 === $value_check ? $value : ''; break; } // Allow custom sanitization by child themes $value = apply_filters('hoot_style_builder_css_rule_sanitized_array', $value, $property); /** Return **/ if (empty($value)) { // if $value is empty => failed sanitization checks return ''; } else { return array($property => array('value' => $value, 'important' => $important, 'idtag' => $idtag)); } }
function hoot_sanitize_background_position($value) { $recognized = hoot_enum_background_position(); if (array_key_exists($value, $recognized)) { return $value; } return apply_filters('hoot_sanitize_default_background_position', current($recognized)); }
/** * Modify the settings array and prepare betterbackground settings for Customizer Library Interface functions * * @since 2.0.0 * @param array $value * @param string $key * @param array $setting * @param int $count * @return void */ function hoot_customizer_prepare_betterbackground_settings($value, $key, $setting, $count) { if ($setting['type'] == 'betterbackground') { $setting = wp_parse_args($setting, array('label' => '', 'section' => '', 'priority' => '', 'choices' => hoot_enum_background_pattern(), 'default' => array(), 'description' => '', 'options' => array('image', 'color', 'repeat', 'position', 'attachment', 'pattern'))); $setting['default'] = wp_parse_args($setting['default'], array('type' => 'predefined', 'color' => '', 'image' => '', 'repeat' => 'repeat', 'position' => 'top center', 'attachment' => 'scroll', 'pattern' => '0')); if (is_array($setting['options']) && !empty($setting['options'])) { $color = in_array('color', $setting['options']); $image = in_array('image', $setting['options']); $repeat = in_array('repeat', $setting['options']); $position = in_array('position', $setting['options']); $attachment = in_array('attachment', $setting['options']); $pattern = in_array('pattern', $setting['options']) && !empty($setting['choices']); if ($color || $image || $pattern) { // Betterbackground Start $value["betterbackground-{$count}"] = array('label' => $setting['label'], 'section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'description' => $setting['description'], 'background' => 'start'); // Background Color :: (priority & section same as betterbackground) if ($color) { $value["{$key}-color"] = array('section' => $setting['section'], 'type' => 'color', 'priority' => $setting['priority'], 'default' => $setting['default']['color']); } // Background Type Button if ($image && $pattern) { $value["{$key}-type"] = array('section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'default' => $setting['default']['type'], 'background' => 'button'); } // Background Image :: (priority & section same as betterbackground) if ($image) { $value["{$key}-image"] = array('section' => $setting['section'], 'type' => 'image', 'priority' => $setting['priority'], 'default' => $setting['default']['image']); if ($repeat) { $value["{$key}-repeat"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_repeat(), 'default' => $setting['default']['repeat']); } if ($position) { $value["{$key}-position"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_position(), 'default' => $setting['default']['position']); } if ($attachment) { $value["{$key}-attachment"] = array('section' => $setting['section'], 'type' => 'select', 'priority' => $setting['priority'], 'choices' => hoot_enum_background_attachment(), 'default' => $setting['default']['attachment']); } } // Background Patterns :: (priority & section same as betterbackground) if ($pattern) { // Group Start $value["group-{$count}-p"] = array('section' => $setting['section'], 'type' => 'group', 'priority' => $setting['priority'], 'button' => '<span class="hoot-betterbackground-button-pattern"></span>' . __('Select Pattern', 'responsive-brix'), 'group' => 'start'); // Pattern Images $value["{$key}-pattern"] = array('section' => $setting['section'], 'type' => 'radioimage', 'priority' => $setting['priority'], 'choices' => $setting['choices'], 'default' => $setting['default']['pattern']); // Group End $value["group-{$count}-p-end"] = array('section' => $setting['section'], 'type' => 'group', 'priority' => $setting['priority'], 'group' => 'end'); } // Betterbackground End $value["betterbackground-{$count}-end"] = array('section' => $setting['section'], 'type' => 'betterbackground', 'priority' => $setting['priority'], 'background' => 'end'); } } } return $value; }