Нет описания

svg-icons.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * @since Twenty Twenty 1.0
  15. *
  16. * @param string $svg_name The name of the icon.
  17. * @param string $group The group the icon belongs to.
  18. * @param string $color Color code.
  19. */
  20. function twentytwenty_the_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
  21. echo twentytwenty_get_theme_svg( $svg_name, $group, $color ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in twentytwenty_get_theme_svg().
  22. }
  23. }
  24. if ( ! function_exists( 'twentytwenty_get_theme_svg' ) ) {
  25. /**
  26. * Get information about the SVG icon.
  27. *
  28. * @since Twenty Twenty 1.0
  29. *
  30. * @param string $svg_name The name of the icon.
  31. * @param string $group The group the icon belongs to.
  32. * @param string $color Color code.
  33. */
  34. function twentytwenty_get_theme_svg( $svg_name, $group = 'ui', $color = '' ) {
  35. // Make sure that only our allowed tags and attributes are included.
  36. $svg = wp_kses(
  37. TwentyTwenty_SVG_Icons::get_svg( $svg_name, $group, $color ),
  38. array(
  39. 'svg' => array(
  40. 'class' => true,
  41. 'xmlns' => true,
  42. 'width' => true,
  43. 'height' => true,
  44. 'viewbox' => true,
  45. 'aria-hidden' => true,
  46. 'role' => true,
  47. 'focusable' => true,
  48. ),
  49. 'path' => array(
  50. 'fill' => true,
  51. 'fill-rule' => true,
  52. 'd' => true,
  53. 'transform' => true,
  54. ),
  55. 'polygon' => array(
  56. 'fill' => true,
  57. 'fill-rule' => true,
  58. 'points' => true,
  59. 'transform' => true,
  60. 'focusable' => true,
  61. ),
  62. )
  63. );
  64. if ( ! $svg ) {
  65. return false;
  66. }
  67. return $svg;
  68. }
  69. }