Skip to content

Commit

Permalink
Editor: Replace id attribute with class in `WP_Font_Face::get_sty…
Browse files Browse the repository at this point in the history
…le_element()`.

`wp_print_font_faces()` prints an HTML tag that can be used more than once, so the document could end up having multiple tags with the same `id` attribute.

The `id` global attribute defines an identifier (ID) which must be unique in the whole document.

Reference: [https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id MDN Web Docs: id].

Follow-up to [56500].

Props mmaattiiaass, peterwilsoncc.
Fixes #62246.

git-svn-id: https://develop.svn.wordpress.org/trunk@59259 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Oct 20, 2024
1 parent de51a44 commit 281a68f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/wp-includes/fonts/class-wp-font-face.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ private function validate_font_face_declarations( array $font_face ) {
private function get_style_element() {
$attributes = $this->generate_style_element_attributes();

return "<style id='wp-fonts-local'{$attributes}>\n%s\n</style>\n";
return "<style class='wp-fonts-local'{$attributes}>\n%s\n</style>\n";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_should_not_generate_and_print_when_no_fonts() {
*/
public function test_should_generate_and_print_given_fonts( array $fonts, $expected ) {
$font_face = new WP_Font_Face();
$style_element = "<style id='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
$style_element = "<style class='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
$expected_output = sprintf( $style_element, $expected );

$this->expectOutputString( $expected_output );
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function test_should_escape_tags() {
);

$expected_output = <<<CSS
<style id='wp-fonts-local' type='text/css'>
<style class='wp-fonts-local' type='text/css'>
@font-face{font-family:"Source Serif Pro";font-style:normal;font-weight:200 900;font-display:fallback;src:url('http://example.com/assets/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2') format('woff2');font-stretch:;}
</style>
Expand All @@ -76,7 +76,7 @@ public function test_should_print_fonts_in_merged_data() {
}

private function get_expected_styles_output( $styles ) {
$style_element = "<style id='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
$style_element = "<style class='wp-fonts-local' type='text/css'>\n%s\n</style>\n";
return sprintf( $style_element, $styles );
}
}

0 comments on commit 281a68f

Please sign in to comment.