| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Hooks; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class Kses { |
| 10 |
|
| 11 |
public static function init() { |
| 12 |
$self = new self(); |
| 13 |
add_filter('safecss_filter_attr_allow_css', [ $self, 'allow_rgb' ], 10, 2); |
| 14 |
} |
| 15 |
|
| 16 |
public function allow_rgb( $allow_css, $css_test ) { |
| 17 |
$css = explode(':', $css_test); |
| 18 |
if ( 2 !== count($css) ) { |
| 19 |
return $allow_css; |
| 20 |
} |
| 21 |
$value = trim($css[1]); |
| 22 |
if ( strpos($value, 'rgb') !== false ) { |
| 23 |
if ( preg_match('/^rgba?\(\s*(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,\s*(0(\.\d+)?|1(\.0+)?))?\s*\)$/', $value) ) { |
| 24 |
return true; |
| 25 |
} else { |
| 26 |
return false; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
return $allow_css; |
| 31 |
} |
| 32 |
|
| 33 |
} |
| 34 |
|