Kses.php
39 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Sanitize; |
| 4 | |
| 5 | class Kses |
| 6 | { |
| 7 | |
| 8 | public function sanitize(string $string): string |
| 9 | { |
| 10 | return wp_kses($string, $this->get_allowed_html(), $this->get_allowed_protocols()); |
| 11 | } |
| 12 | |
| 13 | private function get_allowed_html(): array |
| 14 | { |
| 15 | $html = wp_kses_allowed_html('post'); |
| 16 | |
| 17 | $html['a']['download'] = true; |
| 18 | $html['iframe'] = [ |
| 19 | 'src' => true, |
| 20 | 'height' => true, |
| 21 | 'width' => true, |
| 22 | 'frameborder' => true, |
| 23 | 'allowfullscreen' => true, |
| 24 | ]; |
| 25 | |
| 26 | return $html; |
| 27 | } |
| 28 | |
| 29 | protected function get_allowed_protocols(): array |
| 30 | { |
| 31 | return array_merge( |
| 32 | wp_allowed_protocols(), |
| 33 | [ |
| 34 | 'data', |
| 35 | ] |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | } |