Skip to content

Commit 62d59c2

Browse files
committed
Update wp_custom_css_cb to rely on HTML API for safe SCRIPT tag printing.
1 parent db273b7 commit 62d59c2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/wp-includes/theme.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,17 +1967,18 @@ function _custom_background_cb() {
19671967
*/
19681968
function wp_custom_css_cb() {
19691969
$styles = wp_get_custom_css();
1970-
if ( $styles || is_customize_preview() ) :
1971-
$type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
1972-
?>
1973-
<style<?php echo $type_attr; ?> id="wp-custom-css">
1974-
<?php
1975-
// Note that esc_html() cannot be used because `div &gt; span` is not interpreted properly.
1976-
echo strip_tags( $styles );
1977-
?>
1978-
</style>
1979-
<?php
1980-
endif;
1970+
if ( ! $styles || ! is_customize_preview() ) {
1971+
return;
1972+
}
1973+
1974+
$processor = new WP_HTML_Tag_Processor( '<style></style>' );
1975+
$processor->next_tag();
1976+
if ( ! current_theme_supports( 'html5', 'style' ) ) {
1977+
$processor->set_attribute( 'type', 'text/css' );
1978+
}
1979+
$processor->set_attribute( 'id', 'wp-custom-css' );
1980+
$processor->set_modifiable_text( $styles );
1981+
echo $processor->get_updated_html();
19811982
}
19821983

19831984
/**

0 commit comments

Comments
 (0)