Skip to content

Commit c6284a0

Browse files
authored
Update class-wp-styles.php
### Summary Adds support for loading `ltr.css` in RTL-based multilingual WordPress sites, mirroring the existing `rtl.css` behavior. ### Details - Introduces `wp_style_add_data( $handle, 'ltr', 'replace' )` and `'suffix'` modes - Uses `extra['ltr']` and `_css_href()` for consistent file resolution - Applies `style_loader_tag` filter for extensibility - Ensures compatibility with single-file enqueue behavior in WordPress Core ### Trac Ticket See: https://core.trac.wordpress.org/ticket/64193
1 parent 9f3e07c commit c6284a0

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/wp-includes/class-wp-styles.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,34 @@ public function do_item( $handle, $group = false ) {
271271
$tag .= $rtl_tag;
272272
}
273273
}
274+
275+
if ( 'rtl' !== $this->text_direction && isset( $obj->extra['ltr'] ) && $obj->extra['ltr'] ) {
276+
if ( is_bool( $obj->extra['ltr'] ) || 'replace' === $obj->extra['ltr'] ) {
277+
$suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : '';
278+
$ltr_href = str_replace( "{$suffix}.css", "-ltr{$suffix}.css", $this->_css_href( $src, $ver, "$handle-ltr" ) );
279+
} else {
280+
$ltr_href = $this->_css_href( $obj->extra['ltr'], $ver, "$handle-ltr" );
281+
}
282+
283+
$ltr_tag = sprintf(
284+
"<link rel='%s' id='%s-ltr-css'%s href='%s'%s media='%s' />\n",
285+
$rel,
286+
esc_attr( $handle ),
287+
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
288+
$ltr_href,
289+
$this->type_attr,
290+
esc_attr( $media )
291+
);
292+
293+
/** This filter is documented in wp-includes/class-wp-styles.php */
294+
$ltr_tag = apply_filters( 'style_loader_tag', $ltr_tag, $handle, $ltr_href, $media );
295+
296+
if ( 'replace' === $obj->extra['ltr'] ) {
297+
$tag = $ltr_tag;
298+
} else {
299+
$tag .= $ltr_tag;
300+
}
301+
}
274302

275303
if ( $this->do_concat ) {
276304
$this->print_html .= $tag;

0 commit comments

Comments
 (0)