Svg.php
1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace AIOSEO\Plugin\Common\Traits\Helpers;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Contains SVG specific helper methods.
*
* @since 4.1.4
*/
trait Svg {
/**
* Sanitizes a SVG string.
*
* @since 4.1.4
*
* @param string $svgString The SVG to check.
* @return string The sanitized SVG.
*/
public function escSvg( $svgString ) {
if ( ! is_string( $svgString ) ) {
return false;
}
$ksesDefaults = wp_kses_allowed_html( 'post' );
$svgArgs = [
'svg' => [
'class' => true,
'aria-hidden' => true,
'aria-labelledby' => true,
'role' => true,
'xmlns' => true,
'width' => true,
'height' => true,
'viewbox' => true, // <= Must be lower case!
],
'g' => [ 'fill' => true ],
'title' => [ 'title' => true ],
'path' => [
'd' => true,
'fill' => true,
]
];
return wp_kses( $svgString, array_merge( $ksesDefaults, $svgArgs ) );
}
}