Skip to content

Commit 1a9c745

Browse files
fix: allow color values in inline styles
1 parent b44bcb6 commit 1a9c745

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

inc/validation.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,29 @@ function ppom_get_product_limits( $product_id, $variation_id ) {
348348
// ppom_pa($limits);
349349
return $limits;
350350
}
351+
352+
/**
353+
* By default, WordPress strips CSS values that contain \ ( & } = or comments, such as rgb()
354+
* and rgba(), because the core regex in safecss_filter_attr() flags them as unsafe.
355+
*
356+
* This filter overrides that behavior by checking if the CSS string contains
357+
* "rgb(" or "rgba(" and explicitly allows it. All other CSS values still pass
358+
* through the normal WordPress sanitization process.
359+
*
360+
* @since 1.0.0
361+
*
362+
* @param bool $allow_css Whether the CSS in the string is considered safe.
363+
* @param string $css_string The full CSS declaration.
364+
*
365+
* @return bool True if the CSS is safe and should be allowed, false otherwise.
366+
*/
367+
function ppom_safecss_filter_attr( $allow_css, $css_string ) {
368+
369+
// If the CSS string contains rgb() or rgba(), mark it as safe.
370+
if ( stripos( $css_string, 'rgb(' ) !== false || stripos( $css_string, 'rgba(' ) !== false ) {
371+
return true;
372+
}
373+
374+
return $allow_css;
375+
}
376+
add_filter( 'safecss_filter_attr_allow_css', 'ppom_safecss_filter_attr', 10, 2 );

0 commit comments

Comments
 (0)