Skip to content

Script Loader: Use the style link tag API for the remaining Core stylesheet LINK tags - #14499

Draft
huubl wants to merge 3 commits into
WordPress:trunkfrom
huubl:huubl-style-link-call-sites
Draft

huubl wants to merge 3 commits into
WordPress:trunkfrom
huubl:huubl-style-link-call-sites

Conversation

@huubl

@huubl huubl commented Oct 19, 2026 •

Copy link
Copy Markdown

Important

This depends on #14498, which introduces wp_get_style_link_tag() and wp_print_style_link_tag(). Until that lands, the diff here also includes the API. The diff of only this change is: huubl/wordpress-develop@huubl-style-link-api...huubl-style-link-call-sites

Builds the LINK tags for the media sandbox stylesheets returned by wp_ajax_parse_embed() and wp_ajax_parse_media_shortcode(), and the stylesheet in the deprecated theme compatibility header, with the style link tag API, so that their attributes can be filtered with wp_style_attributes, for example to add a CSP nonce. Their URLs are now escaped, which they previously were not.

Tests check that the stylesheets returned by wp_ajax_parse_embed() and wp_ajax_parse_media_shortcode() receive the filtered attributes, and that a quote in their URLs cannot end the href attribute. While here, the class docblock of the wp_ajax_parse_media_shortcode() tests is corrected: its @covers annotation named a function that does not exist, and its summary described saving a draft.

Trac ticket: https://core.trac.wordpress.org/ticket/66342

Use of AI Tools

AI assistance: Yes
Tool(s): GitHub Copilot, Claude Code
Model(s): GPT-6 Luna, Claude Opus 5.5, Claude Fable 5.1
Used for: The initial implementation and tests were written with GitHub Copilot. Claude Code was used under my direction for review, the backward compatibility fixes, splitting the change, and tests, and I reviewed the result.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@huubl
huubl force-pushed the huubl-style-link-call-sites branch from cfecc68 to dcce47f Compare October 19, 2026 18:05
Introduce `wp_get_style_link_tag()` and `wp_print_style_link_tag()`,
which build a `<link rel="stylesheet">` tag with `WP_HTML_Tag_Processor`,
and the `wp_style_attributes` filter, so that attributes such as a CSP
`nonce`, `integrity` or `crossorigin` can be added to stylesheet links
without editing HTML strings. This complements `wp_get_script_tag()` and
the `wp_script_attributes` filter, and `wp_get_inline_style_tag()` for
inline STYLE tags.

`WP_Styles::do_item()`, including right-to-left and alternate
stylesheets, the concatenated stylesheet printed by `_print_styles()`,
`wp_admin_css()` and `locale_stylesheet()` now print their LINK tags
with the API.

Backward compatibility:

- The `style_loader_tag` and `wp_admin_css` filters are kept, and the
  markup they are passed is unchanged: the values Core supplies are
  still escaped with `esc_attr()` or `esc_url()`, single-quoted and in
  the same order, since callbacks have long edited that markup as a
  string. Attributes added by the `wp_style_attributes` filter are
  printed after them.
- `style_loader_tag` is still passed the escaped URL from before the
  `wp_style_attributes` filter, and each URL is still escaped, and
  passed to the `clean_url` filter, once.
- In the markup passed to `style_loader_tag` and `wp_admin_css`, a
  quote returned by a filtered escaping function, such as a
  `clean_url` callback, is encoded, so it can no longer end an
  attribute value early. Like `wp_get_script_tag()`,
  `wp_get_style_link_tag()` prints the `href` as the Tag Processor
  escapes it.
- A supplied `id` cannot be changed or removed by the filter, since
  code locates LINK tags by it, such as the color scheme picker on the
  user profile screen with `colors-css`. A `_doing_it_wrong()` notice
  naming the function that printed the tag is issued if the filter
  tries.
- `WP_Styles::do_item()` no longer calls `WP_Styles::_css_href()`, so
  overriding that method in a subclass no longer changes the printed
  URL.
- The URL printed by `locale_stylesheet()` is now escaped.

Attributes are printed in the order they are given. An attribute that
the Tag Processor rejects, such as a URL with a disallowed protocol, is
left out rather than printed empty.

See #66342, #51325.
@huubl
huubl force-pushed the huubl-style-link-call-sites branch from dcce47f to 2c66ef7 Compare October 19, 2026 18:35
huubl added 2 commits October 20, 2026 18:15
Keep the new stylesheet link tag API, filter and backward compatibility tests, while retaining the Core removal of script and style concatenation (r64585). Drop the two tests for concatenated stylesheet output, which no longer exists.
…esheet LINK tags.

Build the LINK tags for the media sandbox stylesheets returned by
`wp_ajax_parse_embed()` and `wp_ajax_parse_media_shortcode()`, and the
stylesheet in the deprecated theme compatibility header, with the style
link tag API, so that their attributes can be filtered with
`wp_style_attributes`, for example to add a CSP `nonce`. Their URLs are
now escaped, which they previously were not.

Also correct the class docblock of the `wp_ajax_parse_media_shortcode()`
tests, whose `@covers` annotation named a function that does not exist
and whose summary described saving a draft.

Follow-up to the style link tag API. See #66342, #51325.
@huubl
huubl force-pushed the huubl-style-link-call-sites branch from 2c66ef7 to 534ab16 Compare October 20, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant