svg-icons.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Twenty Twenty SVG Icon helper functions
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Twenty
  7. * @since Twenty Twenty 1.0
  8. */
  9. if ( ! function_exists( 'twentytwenty_the_theme_svg' ) ) {
  10. /**
  11. * Output and Get Theme SVG.
  12. * Output and get the SVG markup for an icon in the TwentyTwenty_SVG_Icons class.
  13. *
  14. * @param string $svg_name The name of the icon.
  15. * @param string $group The group the icon belongs to.
  16. * @param string $color Color code.
  17. */
  18. function twentytwenty_the_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
  19. echo twentytwenty_get_theme_svg( $svg_name, $group, $color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in twentytwenty_get_theme_svg().
  20. }
  21. }
  22. if ( ! function_exists( 'twentytwenty_get_theme_svg' ) ) {
  23. /**
  24. * Get information about the SVG icon.
  25. *
  26. * @param string $svg_name The name of the icon.
  27. * @param string $group The group the icon belongs to.
  28. * @param string $color Color code.
  29. */
  30. function twentytwenty_get_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
  31. // Make sure that only our allowed tags and attributes are included.
  32. $svg = wp_kses(
  33. TwentyTwenty_SVG_Icons::get_svg( $svg_name, $group, $color ),
  34. array(
  35. 'svg' => array(
  36. 'class' => true,
  37. 'xmlns' => true,
  38. 'width' => true,
  39. 'height' => true,
  40. 'viewbox' => true,
  41. 'aria-hidden' => true,
  42. 'role' => true,
  43. 'focusable' => true,
  44. ),
  45. 'path' => array(
  46. 'fill' => true,
  47. 'fill-rule' => true,
  48. 'd' => true,
  49. 'transform' => true,
  50. ),
  51. 'polygon' => array(
  52. 'fill' => true,
  53. 'fill-rule' => true,
  54. 'points' => true,
  55. 'transform' => true,
  56. 'focusable' => true,
  57. ),
  58. )
  59. );
  60. if ( ! $svg ) {
  61. return false;
  62. }
  63. return $svg;
  64. }
  65. }