diff --git a/src/wp-includes/class-wp-styles.php b/src/wp-includes/class-wp-styles.php
index a5d071da54886..72af6c29b0171 100644
--- a/src/wp-includes/class-wp-styles.php
+++ b/src/wp-includes/class-wp-styles.php
@@ -158,11 +158,11 @@ public function do_item( $handle, $group = false ) {
$inline_style = $this->print_inline_style( $handle, false );
if ( $inline_style ) {
- $inline_style_tag = sprintf(
- "\n",
- esc_attr( $handle ),
- $inline_style
- );
+ $processor = new WP_HTML_Tag_Processor( '' );
+ $processor->next_tag();
+ $processor->set_attribute( 'id', "{$handle}-inline-css" );
+ $processor->set_modifiable_text( "\n{$inline_style}\n" );
+ $inline_style_tag = "{$processor->get_updated_html()}\n";
} else {
$inline_style_tag = '';
}
@@ -336,11 +336,11 @@ public function print_inline_style( $handle, $display = true ) {
return $output;
}
- printf(
- "\n",
- esc_attr( $handle ),
- $output
- );
+ $processor = new WP_HTML_Tag_Processor( '' );
+ $processor->next_tag();
+ $processor->set_attribute( 'id', "{$handle}-inline-css" );
+ $processor->set_modifiable_text( "\n{$output}\n" );
+ echo "{$processor->get_updated_html()}\n";
return true;
}
diff --git a/src/wp-includes/fonts/class-wp-font-face.php b/src/wp-includes/fonts/class-wp-font-face.php
index 96d51b19ff401..193a5d0951ddb 100644
--- a/src/wp-includes/fonts/class-wp-font-face.php
+++ b/src/wp-includes/fonts/class-wp-font-face.php
@@ -92,7 +92,10 @@ public function generate_and_print( array $fonts ) {
return;
}
- printf( $this->get_style_element(), $css );
+ $processor = new WP_HTML_Tag_Processor( '' );
+ $processor->next_tag();
+ $processor->set_modifiable_text( "\n{$css}\n" );
+ echo "{$processor->get_updated_html()}\n";
}
/**
@@ -193,17 +196,6 @@ private function validate_font_face_declarations( array $font_face ) {
return $font_face;
}
- /**
- * Gets the style element for wrapping the `@font-face` CSS.
- *
- * @since 6.4.0
- *
- * @return string The style element.
- */
- private function get_style_element() {
- return "\n";
- }
-
/**
* Gets the `@font-face` CSS styles for locally-hosted font files.
*
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index a60fce6262744..fb9cebbf4b551 100644
--- a/src/wp-includes/script-loader.php
+++ b/src/wp-includes/script-loader.php
@@ -2413,10 +2413,12 @@ function _print_styles() {
echo "\n";
if ( ! empty( $wp_styles->print_code ) ) {
- echo "\n";
+ $processor = new WP_HTML_Tag_Processor( '' );
+ $processor->next_tag();
+ $style_tag_contents = "\n{$wp_styles->print_code}\n"
+ . sprintf( "/*# sourceURL=%s */\n", rawurlencode( $concat_source_url ) );
+ $processor->set_modifiable_text( $style_tag_contents );
+ echo "{$processor->get_updated_html()}\n";
}
}
@@ -3146,7 +3148,10 @@ function wp_enqueue_block_support_styles( $style, $priority = 10 ) {
add_action(
$action_hook_name,
static function () use ( $style ) {
- echo "\n";
+ $processor = new WP_HTML_Tag_Processor( '' );
+ $processor->next_tag();
+ $processor->set_modifiable_text( $style );
+ echo "{$processor->get_updated_html()}\n";
},
$priority
);
diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php
index 89d56d4e44bce..0ff915cbe4263 100644
--- a/src/wp-includes/theme.php
+++ b/src/wp-includes/theme.php
@@ -1950,11 +1950,13 @@ function _custom_background_cb() {
$style .= $image . $position . $size . $repeat . $attachment;
}
- ?>
-
- " );
+ $processor->next_tag();
+
+ $style_tag_content = 'body.custom-background { ' . trim( $style ) . ' }';
+ $processor->set_modifiable_text( "\n{$style_tag_content}\n" );
+ echo "{$processor->get_updated_html()}\n";
}
/**
@@ -1964,17 +1966,18 @@ function _custom_background_cb() {
*/
function wp_custom_css_cb() {
$styles = wp_get_custom_css();
- if ( $styles || is_customize_preview() ) :
- $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
- ?>
-
- ' );
+ $processor->next_tag();
+ if ( ! current_theme_supports( 'html5', 'style' ) ) {
+ $processor->set_attribute( 'type', 'text/css' );
+ }
+ $processor->set_attribute( 'id', 'wp-custom-css' );
+ $processor->set_modifiable_text( "\n{$styles}\n" );
+ echo "{$processor->get_updated_html()}\n";
}
/**