custom-css.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Custom CSS
  4. *
  5. * @package WordPress
  6. * @subpackage Twenty_Twenty_One
  7. * @since Twenty Twenty-One 1.0
  8. */
  9. /**
  10. * Generate CSS.
  11. *
  12. * @since Twenty Twenty-One 1.0
  13. *
  14. * @param string $selector The CSS selector.
  15. * @param string $style The CSS style.
  16. * @param string $value The CSS value.
  17. * @param string $prefix The CSS prefix.
  18. * @param string $suffix The CSS suffix.
  19. * @param bool $display Print the styles.
  20. * @return string
  21. */
  22. function twenty_twenty_one_generate_css( $selector, $style, $value, $prefix = '', $suffix = '', $display = true ) {
  23. // Bail early if there is no $selector elements or properties and $value.
  24. if ( ! $value || ! $selector ) {
  25. return '';
  26. }
  27. $css = sprintf( '%s { %s: %s; }', $selector, $style, $prefix . $value . $suffix );
  28. if ( $display ) {
  29. /*
  30. * Note to reviewers: $css contains auto-generated CSS.
  31. * It is included inside <style> tags and can only be interpreted as CSS on the browser.
  32. * Using wp_strip_all_tags() here is sufficient escaping to avoid
  33. * malicious attempts to close </style> and open a <script>.
  34. */
  35. echo wp_strip_all_tags( $css ); // phpcs:ignore WordPress.Security.EscapeOutput
  36. }
  37. return $css;
  38. }