Aucune description

FormHtmlSanitizer.php 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace MailPoet\Form;
  3. if (!defined('ABSPATH')) exit;
  4. use MailPoet\WP\Functions as WPFunctions;
  5. class FormHtmlSanitizer {
  6. /** @var WPFunctions */
  7. private $wp;
  8. /**
  9. * @var array
  10. * Configuration of allowed tags for form blocks that may contain some html.
  11. * Covers all tags available in the form editor's Rich Text component
  12. * This doesn't cover CustomHTML block.
  13. */
  14. private $allowedHtml = [
  15. 'a' => [
  16. 'href' => true,
  17. 'title' => true,
  18. 'data-id' => true,
  19. 'data-type' => true,
  20. 'target' => true,
  21. 'rel' => true,
  22. ],
  23. 'br' => [],
  24. 'code' => [],
  25. 'em' => [],
  26. 'img' => [
  27. 'class' => true,
  28. 'style' => true,
  29. 'src' => true,
  30. 'alt' => true,
  31. ],
  32. 'kbd' => [],
  33. 'span' => [
  34. 'style' => true,
  35. 'data-font' => true,
  36. 'class' => true,
  37. ],
  38. 'strong' => [],
  39. 'sub' => [],
  40. 'sup' => [],
  41. 's' => [],
  42. ];
  43. public function __construct(
  44. WPFunctions $wp
  45. ) {
  46. $this->wp = $wp;
  47. }
  48. public function sanitize(string $html): string {
  49. return $this->wp->wpKses($html, $this->allowedHtml);
  50. }
  51. }