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