| 1 |
<?php |
| 2 |
/** |
| 3 |
* Compatibility shims for KSES (content filtering) for WordPress 7.1. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Adds SVG presentation attributes to the list of safe CSS properties. |
| 10 |
* |
| 11 |
* The {@see safecss_filter_attr()} function only keeps allowlisted CSS properties, so SVG |
| 12 |
* presentation attributes such as `fill` are stripped by default. This allows |
| 13 |
* the SVG-specific ones. |
| 14 |
* |
| 15 |
* @param string[] $attr Array of allowed CSS attributes. |
| 16 |
* @return string[] Modified array of allowed CSS attributes. |
| 17 |
*/ |
| 18 |
function gutenberg_add_svg_to_safe_style_css( array $attr ): array { |
| 19 |
$svg_properties = array( |
| 20 |
// Fill. |
| 21 |
'fill', |
| 22 |
'fill-opacity', |
| 23 |
'fill-rule', |
| 24 |
|
| 25 |
// Stroke. |
| 26 |
'stroke', |
| 27 |
'stroke-dasharray', |
| 28 |
'stroke-dashoffset', |
| 29 |
'stroke-linecap', |
| 30 |
'stroke-linejoin', |
| 31 |
'stroke-miterlimit', |
| 32 |
'stroke-opacity', |
| 33 |
'stroke-width', |
| 34 |
|
| 35 |
// Paint. |
| 36 |
'color-interpolation', |
| 37 |
'color-interpolation-filters', |
| 38 |
'paint-order', |
| 39 |
'stop-color', |
| 40 |
'stop-opacity', |
| 41 |
'flood-color', |
| 42 |
'flood-opacity', |
| 43 |
'lighting-color', |
| 44 |
|
| 45 |
// Markers. |
| 46 |
'marker', |
| 47 |
'marker-end', |
| 48 |
'marker-mid', |
| 49 |
'marker-start', |
| 50 |
|
| 51 |
// Clipping and masking. |
| 52 |
'clip-path', |
| 53 |
'clip-rule', |
| 54 |
'mask', |
| 55 |
'mask-type', |
| 56 |
|
| 57 |
// Geometry. |
| 58 |
'cx', |
| 59 |
'cy', |
| 60 |
'r', |
| 61 |
'rx', |
| 62 |
'ry', |
| 63 |
'x', |
| 64 |
'y', |
| 65 |
'd', |
| 66 |
|
| 67 |
// Text. |
| 68 |
'alignment-baseline', |
| 69 |
'baseline-shift', |
| 70 |
'dominant-baseline', |
| 71 |
'glyph-orientation-horizontal', |
| 72 |
'glyph-orientation-vertical', |
| 73 |
'text-anchor', |
| 74 |
'unicode-bidi', |
| 75 |
'word-spacing', |
| 76 |
|
| 77 |
// Font. |
| 78 |
'font-size-adjust', |
| 79 |
'font-stretch', |
| 80 |
|
| 81 |
// Rendering. |
| 82 |
'color-rendering', |
| 83 |
'image-rendering', |
| 84 |
'shape-rendering', |
| 85 |
'text-rendering', |
| 86 |
'vector-effect', |
| 87 |
|
| 88 |
// Transforms. |
| 89 |
'transform', |
| 90 |
'transform-origin', |
| 91 |
|
| 92 |
// Interactivity and visibility. |
| 93 |
'pointer-events', |
| 94 |
'visibility', |
| 95 |
); |
| 96 |
|
| 97 |
return array_unique( array_merge( $attr, $svg_properties ) ); |
| 98 |
} |
| 99 |
add_filter( 'safe_style_css', 'gutenberg_add_svg_to_safe_style_css' ); |
| 100 |
|