Make WordPress Core


Ignore:
Timestamp:
12/30/2025 01:01:11 PM (7 months ago)
Author:
jonsurrell
Message:

Use the HTML API to generate style tags.

The HTML API escapes <style> tag contents to ensure the correct HTML structure. Common HTML escaping is unsuitable for <style> tags because they contain "raw text." The additional safety allows other restrictions, such as rejecting content with <>, to be relaxed or removed because the resulting tag will be well-formed.

Developed in https://github.com/WordPress/wordpress-develop/pull/10656.

Props jonsurrell, westonruter, dmsnell, ramonopoly, soyebsalar01, drw158, sabernhardt.
See #64418.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/fonts/class-wp-font-face.php

    r61411 r61418  
    9393                }
    9494
    95                 printf( $this->get_style_element(), $css );
     95                $processor = new WP_HTML_Tag_Processor( '<style class="wp-fonts-local"></style>' );
     96                $processor->next_tag();
     97                $processor->set_modifiable_text( "\n{$css}\n" );
     98                echo "{$processor->get_updated_html()}\n";
    9699        }
    97100
     
    195198
    196199        /**
    197          * Gets the style element for wrapping the `@font-face` CSS.
    198          *
    199          * @since 6.4.0
    200          *
    201          * @return string The style element.
    202          */
    203         private function get_style_element() {
    204                 return "<style class='wp-fonts-local'>\n%s\n</style>\n";
    205         }
    206 
    207         /**
    208200         * Gets the `@font-face` CSS styles for locally-hosted font files.
    209201         *
Note: See TracChangeset for help on using the changeset viewer.