Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,206 changes: 1,184 additions & 22 deletions globals/sanitize-functions.php

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion header-footer-grid/Core/Builder/Abstract_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,25 @@ protected function get_row_featured_image( $image_url, $use_featured, $meta ) {
return apply_filters( 'nv_builder_row_image_url', $image, $use_featured, $meta );
}

/**
* Print a row color variable after validating the stored value.
*
* @param string $css_prop CSS variable.
* @param mixed $value Stored color.
*
* @return string
*/
public function row_color_rule( $css_prop, $value ) {
if ( ! is_string( $value ) ) {
return '';
}

// The printed style is stripped of HTML as a whole; strip it here first so only CSS is checked.
$value = neve_sanitize_row_text_color( wp_strip_all_tags( $value ) );

return '' !== $value ? sprintf( ' %s: %s;', $css_prop, $value ) : '';
Comment thread
pirate-bot marked this conversation as resolved.
Resolved
}

/**
* Method to generate css array for each row.
*
Expand Down Expand Up @@ -1033,12 +1052,14 @@ private function add_row_style( $row_index, $css_array = array() ) {
$rules['--rowbcolor'] = [
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_' . self::BORDER_COLOR,
Dynamic_Selector::META_DEFAULT => 'var(--nv-light-bg)',
Dynamic_Selector::META_FILTER => [ $this, 'row_color_rule' ],
];
}

$rules['--color'] = [
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_' . self::TEXT_COLOR,
Dynamic_Selector::META_DEFAULT => $default_colors['text'],
Dynamic_Selector::META_FILTER => [ $this, 'row_color_rule' ],
];

// Exclude the following rules for the header when the global header background is active.
Expand All @@ -1061,6 +1082,7 @@ private function add_row_style( $row_index, $css_array = array() ) {
'--bgcolor' => [
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_background.colorValue',
Dynamic_Selector::META_DEFAULT => $default_color,
Dynamic_Selector::META_FILTER => [ $this, 'row_color_rule' ],
],
]
);
Expand All @@ -1071,7 +1093,8 @@ private function add_row_style( $row_index, $css_array = array() ) {
$rules,
[
'--overlaycolor' => [
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_background.overlayColorValue',
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_background.overlayColorValue',
Dynamic_Selector::META_FILTER => [ $this, 'row_color_rule' ],
],
'--bgimage' => [
Dynamic_Selector::META_KEY => $this->control_id . '_' . $row_index . '_background',
Expand Down Expand Up @@ -2118,6 +2141,7 @@ private function add_sidebar_styles( $css_array ) {
Dynamic_Selector::META_DEFAULT => $default_sidebar_width,
Dynamic_Selector::META_SUFFIX => 'responsive_suffix',
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_FILTER => 'neve_sanitize_responsive_range_css_rule',
],
],
];
Expand All @@ -2131,6 +2155,7 @@ private function add_sidebar_styles( $css_array ) {
Dynamic_Selector::META_DEFAULT => $default_sidebar_width,
Dynamic_Selector::META_SUFFIX => 'responsive_suffix',
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_FILTER => 'neve_sanitize_responsive_range_css_rule',
],
],
];
Expand All @@ -2144,6 +2169,7 @@ private function add_sidebar_styles( $css_array ) {
Dynamic_Selector::META_DEFAULT => $default_sidebar_width,
Dynamic_Selector::META_SUFFIX => 'responsive_suffix',
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_FILTER => 'neve_sanitize_responsive_range_css_rule',
],
],
];
Expand Down
5 changes: 4 additions & 1 deletion header-footer-grid/Core/Components/Abstract_Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,13 +669,15 @@ public function add_style( array $css_array = array() ) {
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::PADDING_ID ),
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
'directional-prop' => Config::CSS_PROP_PADDING,
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
],
'--margin' => [
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::MARGIN_ID,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::MARGIN_ID ),
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
'directional-prop' => Config::CSS_PROP_MARGIN,
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
],
];

Expand Down Expand Up @@ -729,6 +731,7 @@ public function add_style( array $css_array = array() ) {
'--inheritedff' => [
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::FONT_FAMILY_ID,
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FONT_FAMILY_ID ),
Dynamic_Selector::META_FILTER => 'neve_sanitize_font_family_css_rule',
],
'--inheritedfw' => [
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::TYPEFACE_ID . '.fontWeight',
Expand Down Expand Up @@ -829,7 +832,7 @@ private function add_typography_controls() {
'transport' => 'postMessage',
'priority' => $priority + 1,
'type' => '\Neve\Customizer\Controls\React\Font_Family',
'sanitize_callback' => 'sanitize_text_field',
'sanitize_callback' => 'neve_sanitize_font_family',
'live_refresh_selector' => $this->default_typography_selector,
'live_refresh_css_prop' => array(
'cssVar' => [
Expand Down
24 changes: 12 additions & 12 deletions header-footer-grid/Core/Components/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,29 +230,35 @@ public function add_style( array $css_array = array() ) {
'--primarybtnbg' => [
Dynamic_Selector::META_KEY => $id . '.background',
Dynamic_Selector::META_DEFAULT => 'var(--nv-primary-accent)',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtncolor' => [
Dynamic_Selector::META_KEY => $id . '.text',
Dynamic_Selector::META_DEFAULT => '#fff',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtnhoverbg' => [
Dynamic_Selector::META_KEY => $id . '.backgroundHover',
Dynamic_Selector::META_DEFAULT => 'var(--nv-primary-accent)',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtnhovercolor' => [
Dynamic_Selector::META_KEY => $id . '.textHover',
Dynamic_Selector::META_DEFAULT => '#fff',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtnborderradius' => [
Dynamic_Selector::META_KEY => $id . '.borderRadius',
'directional-prop' => Config::CSS_PROP_BORDER_RADIUS,
Dynamic_Selector::META_KEY => $id . '.borderRadius',
Dynamic_Selector::META_FILTER => 'neve_sanitize_button_dimension_css_rule',
'directional-prop' => Config::CSS_PROP_BORDER_RADIUS,
],
];

if ( isset( $value['type'] ) && $value['type'] === 'outline' ) {
$rules['--primarybtnborderwidth'] = [
Dynamic_Selector::META_KEY => $id . '.borderWidth',
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
Dynamic_Selector::META_KEY => $id . '.borderWidth',
Dynamic_Selector::META_FILTER => 'neve_sanitize_button_dimension_css_rule',
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
];
}

Expand All @@ -264,11 +270,8 @@ public function add_style( array $css_array = array() ) {
if ( ! isset( $button_values['useShadow'] ) || empty( $button_values['useShadow'] ) ) {
return sprintf( '%s:%s;', $css_prop, 'none' );
}
$blur = intval( $button_values['shadowProperties']['blur'] );
$width = intval( $button_values['shadowProperties']['width'] );
$height = intval( $button_values['shadowProperties']['height'] );

return sprintf( '%s:%s;', $css_prop, sprintf( '%spx %spx %spx %s;', $width, $height, $blur, $value ) );
return neve_sanitize_button_shadow_css_rule( $css_prop, $value, $button_values['shadowProperties'] ?? array() );
},
];
$rules['--primarybtnhovershadow'] = [
Expand All @@ -278,11 +281,8 @@ public function add_style( array $css_array = array() ) {
if ( ! isset( $button_values['useShadowHover'] ) || empty( $button_values['useShadowHover'] ) ) {
return sprintf( '%s:%s;', $css_prop, 'none' );
}
$blur = intval( $button_values['shadowPropertiesHover']['blur'] );
$width = intval( $button_values['shadowPropertiesHover']['width'] );
$height = intval( $button_values['shadowPropertiesHover']['height'] );

return sprintf( '%s:%s;', $css_prop, sprintf( '%spx %spx %spx %s;', $width, $height, $blur, $value ) );
return neve_sanitize_button_shadow_css_rule( $css_prop, $value, $button_values['shadowPropertiesHover'] ?? array() );
},
];

Expand Down
21 changes: 15 additions & 6 deletions header-footer-grid/Core/Components/MenuIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,15 +680,23 @@ public function add_style( array $css_array = array() ) {
$id = $this->get_id() . '_' . self::BUTTON_APPEARANCE;

$rules = [
'--bgcolor' => $id . '.background',
'--color' => $id . '.text',
'--bgcolor' => [
Dynamic_Selector::META_KEY => $id . '.background',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--color' => [
Dynamic_Selector::META_KEY => $id . '.text',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--borderradius' => [
Dynamic_Selector::META_KEY => $id . '.borderRadius',
'directional-prop' => Config::CSS_PROP_BORDER_RADIUS,
Dynamic_Selector::META_KEY => $id . '.borderRadius',
Dynamic_Selector::META_FILTER => 'neve_sanitize_button_dimension_css_rule',
'directional-prop' => Config::CSS_PROP_BORDER_RADIUS,
],
'--borderwidth' => [
Dynamic_Selector::META_KEY => $id . '.borderWidth',
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
Dynamic_Selector::META_KEY => $id . '.borderWidth',
Dynamic_Selector::META_FILTER => 'neve_sanitize_button_dimension_css_rule',
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
],
];

Expand All @@ -713,6 +721,7 @@ public function add_style( array $css_array = array() ) {
Dynamic_Selector::META_DEFAULT => $this->default_label_margin_value,
Dynamic_Selector::META_SUFFIX => 'responsive_unit',
'directional-prop' => Config::CSS_PROP_MARGIN,
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
],
],
];
Expand Down
2 changes: 2 additions & 0 deletions header-footer-grid/Core/Components/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,15 @@ public function add_style( array $css_array = array() ) {
Dynamic_Selector::META_SUFFIX => 'px',
],
'--formfieldborderwidth' => [
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::FIELD_BORDER_WIDTH,
Dynamic_Selector::META_SUFFIX => 'px',
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FIELD_BORDER_WIDTH ),
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
],
'--formfieldborderradius' => [
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::FIELD_BORDER_RADIUS,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FIELD_BORDER_RADIUS ),
Expand Down
2 changes: 2 additions & 0 deletions header-footer-grid/Core/Components/SearchResponsive.php
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,14 @@ public function add_style( array $css_array = array() ) {
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FIELD_FONT_SIZE ),
],
'--formfieldborderwidth' => [
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::FIELD_BORDER_WIDTH,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FIELD_BORDER_WIDTH ),
'directional-prop' => Config::CSS_PROP_BORDER_WIDTH,
],
'--formfieldborderradius' => [
Dynamic_Selector::META_FILTER => 'neve_sanitize_directional_css_rule',
Dynamic_Selector::META_KEY => $this->get_id() . '_' . self::FIELD_BORDER_RADIUS,
Dynamic_Selector::META_IS_RESPONSIVE => true,
Dynamic_Selector::META_DEFAULT => SettingsManager::get_instance()->get_default( $this->get_id() . '_' . self::FIELD_BORDER_RADIUS ),
Expand Down
20 changes: 16 additions & 4 deletions header-footer-grid/Core/Components/Utility/SearchIconButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,22 @@ public function get_style( array $css_array = array() ) {
$button_style_id = $this->component_id . '_' . self::BUTTON_STYLE;

$rules = [
'--primarybtnbg' => $button_style_id . '.background',
'--primarybtnhoverbg' => $button_style_id . '.background',
'--primarybtncolor' => $button_style_id . '.text',
'--primarybtnhovercolor' => $button_style_id . '.text',
'--primarybtnbg' => [
Dynamic_Selector::META_KEY => $button_style_id . '.background',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtnhoverbg' => [
Dynamic_Selector::META_KEY => $button_style_id . '.background',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtncolor' => [
Dynamic_Selector::META_KEY => $button_style_id . '.text',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
'--primarybtnhovercolor' => [
Dynamic_Selector::META_KEY => $button_style_id . '.text',
Dynamic_Selector::META_FILTER => 'neve_sanitize_color_css_rule',
],
];

$css_array[] = [
Expand Down
26 changes: 23 additions & 3 deletions header-footer-grid/Traits/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,31 @@ public function sanitize_responsive_int_json( $input ) {
* @return array
*/
public function sanitize_spacing_array( $input ) {
if ( is_array( $input ) ) {
return $input;
if ( ! is_array( $input ) ) {
return array();
}

foreach ( array( 'top', 'right', 'bottom', 'left' ) as $direction ) {
if ( isset( $input[ $direction ] ) && ! is_numeric( $input[ $direction ] ) ) {
unset( $input[ $direction ] );
}
}

foreach ( array( 'mobile', 'tablet', 'desktop' ) as $device ) {
if ( isset( $input[ $device ] ) ) {
$input[ $device ] = $this->sanitize_spacing_array( $input[ $device ] );
}
$unit_key = $device . '-unit';
if ( isset( $input[ $unit_key ] ) ) {
$input[ $unit_key ] = neve_sanitize_css_unit( $input[ $unit_key ] );
}
}

if ( isset( $input['unit'] ) ) {
$input['unit'] = neve_sanitize_css_unit( $input['unit'] );
}

return array();
return $input;
}

/**
Expand Down
Loading
Loading