WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#30032 closed enhancement (fixed)

Add ID attribute to style element from wp_add_inline_style()

Reported by: westonruter Owned by: SergeyBiryukov
Milestone: 4.1 Priority: normal
Severity: normal Version:
Component: Script Loader Keywords: has-patch
Focuses: Cc:

Description

In order to support partial preview refreshes (#27355), it is important for all partials being updated to have an element with a distinct CSS selector for targeting. In the case of Twenty Fifteen, styles output via wp_add_inline_style() may be dynamically refreshed by JS and so the style elements output by this function should have distinct IDs. Once this is in place, then the Twenty Fifteen theme can make use of it in #29988.

Attachments (3)

30032.diff (1.0 KB) - added by westonruter 6 years ago.
https://github.com/xwpco/wordpress-develop/pull/34
30032.1.diff (682 bytes) - added by georgestephanis 6 years ago.
30032.fix-unit-tests.diff (1.5 KB) - added by georgestephanis 6 years ago.

Download all attachments as: .zip

Change History (13)

#1 @westonruter
6 years ago

  • Keywords has-patch added
  • Summary changed from Add ID to style element output by wp_add_inline_style to Add ID attribute to style element from wp_add_inline_style()

In 30032.diff, add id="wp-inline-style-$handle" to style elements added via wp_add_inline_style()

#2 @SergeyBiryukov
6 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 29956:

Add ID attribute to style element from wp_add_inline_style().

props westonruter.
fixes #30032.

This ticket was mentioned in IRC in #wordpress-dev by georgestephanis. View the logs.


6 years ago

#4 follow-up: @obenland
6 years ago

What if there is more than one inline style added to one handle?

#5 in reply to: ↑ 4 @westonruter
6 years ago

Replying to obenland:

What if there is more than one inline style added to one handle?

The after data for the style dependency is actually an array and print_inline_style() concatenates the array into a single string: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class.wp-styles.php#L144

So adding multiple inline styles won't be a problem.

#6 @SergeyBiryukov
6 years ago

In 29958:

wp_add_inline_style():

  • Change the wp-inline-style-$handle class added in [29956] to $handle-inline-css for consistency with existing patterns.
  • Add the ID attribute when concatenation is enabled as well.

props georgestephanis.
see #30032.

#7 @boonebgorges
6 years ago

[29958] broke a couple unit tests - phpunit --filter _inline_styles. The expected strings need to be updated.

#9 @georgestephanis
6 years ago

fixes broken unit tests.

#10 @SergeyBiryukov
6 years ago

In 29967:

Update expected results in wp_add_inline_style() unit tests after [29958].

props georgestephanis.
see #30032.

Note: See TracTickets for help on using tickets.