WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#36839 closed defect (bug) (fixed)

Locale stylesheet loaded early for embeds

Reported by: greenshady Owned by: peterwilsoncc
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.4
Component: Embeds Keywords: needs-testing good-first-bug has-patch commit
Focuses: Cc:
PR Number:

Description

Typically, locale stylesheets get loaded after other styles have been output when hooked to wp_head. However, with embeds on the embed_head hook, the locale stylesheet is output earlier. This can cause locale stylesheets to get overwritten with CSS applied later.

Here's a comparison of the priorities between the wp_head and embed_head hooks:

add_action( 'wp_head', 'wp_print_styles', 8 );
add_action( 'wp_head', 'locale_stylesheet' );

add_action( 'embed_head', 'wp_print_styles', 20 );
add_action( 'embed_head', 'locale_stylesheet' );

The locale_stylesheet action should get a later priority on embed_head for consistency.

This has been in core since 4.4, but it's probably been overlooked because most theme authors were not dealing with it. Now that themes can have custom embed templates, this could be a problem. I know it is for some of my themes that have locale-specific stylesheets.

Attachments (1)

36839.diff (870 bytes) - added by swissspidy 3 years ago.

Download all attachments as: .zip

Change History (9)

#1 @swissspidy
3 years ago

  • Keywords needs-patch needs-testing added
  • Milestone changed from Awaiting Review to 4.6

Hey Justin, thanks for opening this ticket.

Definitely looks a bit off. Will have a closer look at this tomorrow as there's a contributor day going on here.

#2 @peterwilsoncc
3 years ago

  • Keywords good-first-bug added

#3 @sjmur
3 years ago

Would like to take a stab at this if someone would like to mentor a little.

Cheers,

#4 @swissspidy
3 years ago

@sjmur That'd be great! You can ping me on Slack if you have any questions.

Basically, when you're running WordPress in another locale (e.g. de_DE) and a theme has a locale stylesheet (de_DE.css) or an rtl.css stylesheet, WordPress will enqueue this file.

As you can see from the add_action() snippets above, the regular stylesheets get printed earlier (priority 8) than the locale stylesheet (default priority of 10). However, when embedding a post, regular stylesheets get printed after the locale CSS.

This of course is inconsistent and can lead to all sorts of bugs, like not being able to override some theme styles in the locale CSS.

We should change add_action( 'embed_head', 'locale_stylesheet' ); to something like add_action( 'embed_head', 'locale_stylesheet', 30 ); and test if it works correctly.

#5 @sjmur
3 years ago

@swissspidy Cheers! I'll take a look at this over the next few days and will shout if need be.

@swissspidy
3 years ago

#6 @swissspidy
3 years ago

  • Keywords has-patch added; needs-patch removed

#7 @swissspidy
3 years ago

  • Keywords commit added

Further testing has shown no issues.

#8 @peterwilsoncc
3 years ago

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

In 38010:

Embeds: Include locale stylesheets after default styles.

Fire locale_stylesheet action after the wp_print_styles action in the embeds header to match the order in wp_head.

Props swissspidy.
Fixes #36839.

Note: See TracTickets for help on using tickets.