Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/wp-admin/includes/ajax-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3894,7 +3894,12 @@ function wp_ajax_parse_embed() {
$mce_styles = wpview_media_sandbox_styles();

foreach ( $mce_styles as $style ) {
$styles .= sprintf( '<link rel="stylesheet" href="%s" />', $style );
$styles .= wp_get_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => $style,
)
);
}

$html = do_shortcode( $parsed );
Expand Down Expand Up @@ -4001,7 +4006,12 @@ function wp_ajax_parse_media_shortcode() {
$styles = wpview_media_sandbox_styles();

foreach ( $styles as $style ) {
$head .= '<link rel="stylesheet" href="' . $style . '">';
$head .= wp_get_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => $style,
)
);
}

if ( ! empty( $wp_scripts ) ) {
Expand Down
16 changes: 15 additions & 1 deletion src/wp-content/themes/twentyeleven/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,21 @@
?>
</title>
<link rel="profile" href="https://gmpg.org/xfn/11" />
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20260819" />
<?php
if ( function_exists( 'wp_print_stylesheet_link_tag' ) ) {
wp_print_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'media' => 'all',
'href' => get_stylesheet_uri() . '?ver=20260819',
)
);
} else {
?>
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20260819" />
<?php
}
?>
<link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
<?php
/*
Expand Down
16 changes: 15 additions & 1 deletion src/wp-content/themes/twentyten/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,21 @@
?>
</title>
<link rel="profile" href="https://gmpg.org/xfn/11" />
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20260819" />
<?php
if ( function_exists( 'wp_print_stylesheet_link_tag' ) ) {
wp_print_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'media' => 'all',
'href' => get_stylesheet_uri() . '?ver=20260819',
)
);
} else {
?>
<link rel="stylesheet" media="all" href="<?php echo esc_url( get_stylesheet_uri() ); ?>?ver=20260819" />
<?php
}
?>
<link rel="pingback" href="<?php echo esc_url( get_bloginfo( 'pingback_url' ) ); ?>">
<?php
/*
Expand Down
40 changes: 24 additions & 16 deletions src/wp-includes/class-wp-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,27 @@ public function do_item( $handle, $group = false ) {
return true;
}

$href = $this->_css_href( $src, $obj->ver, $handle );
$raw_href = $this->get_src( $handle );
$href = esc_url( $raw_href );
if ( ! $href ) {
return true;
}

$rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = $obj->extra['title'] ?? '';

$tag = sprintf(
"<link rel='%s' id='%s-css'%s href='%s' media='%s' />\n",
$rel,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$href,
esc_attr( $media )
$attributes = array(
'rel' => $rel,
'id' => "{$handle}-css",
);
if ( $title ) {
$attributes['title'] = $title;
}
$attributes['href'] = $raw_href;
$attributes['media'] = $media;

// Preserve the single-quoted format expected by style_loader_tag callbacks.
$tag = str_replace( '"', "'", wp_get_stylesheet_link_tag( $attributes ) );

/**
* Filters the HTML link tag of an enqueued style.
Expand All @@ -227,15 +232,18 @@ public function do_item( $handle, $group = false ) {
$rtl_src = $this->get_rtl_src( $handle );

if ( null !== $rtl_src ) {
$rtl_href = esc_url( $rtl_src );
$rtl_tag = sprintf(
"<link rel='%s' id='%s-rtl-css'%s href='%s' media='%s' />\n",
$rel,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$rtl_href,
esc_attr( $media )
$rtl_href = esc_url( $rtl_src );
$rtl_attributes = array(
'rel' => $rel,
'id' => "{$handle}-rtl-css",
);
if ( $title ) {
$rtl_attributes['title'] = $title;
}
$rtl_attributes['href'] = $rtl_src;
$rtl_attributes['media'] = $media;

$rtl_tag = str_replace( '"', "'", wp_get_stylesheet_link_tag( $rtl_attributes ) );

/** This filter is documented in wp-includes/class-wp-styles.php */
$rtl_tag = apply_filters( 'style_loader_tag', $rtl_tag, $handle, $rtl_href, $media );
Expand Down
25 changes: 19 additions & 6 deletions src/wp-includes/general-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5400,9 +5400,16 @@ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
return;
}

$stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' />\n",
esc_url( wp_admin_css_uri( $file ) )
// Preserve the historical markup format passed to the wp_admin_css filter.
$stylesheet_link = str_replace(
'"',
"'",
wp_get_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => wp_admin_css_uri( $file ),
)
)
);

/**
Expand All @@ -5419,9 +5426,15 @@ function wp_admin_css( $file = 'wp-admin', $force_echo = false ) {
echo apply_filters( 'wp_admin_css', $stylesheet_link, $file );

if ( function_exists( 'is_rtl' ) && is_rtl() ) {
$rtl_stylesheet_link = sprintf(
"<link rel='stylesheet' href='%s' />\n",
esc_url( wp_admin_css_uri( "$file-rtl" ) )
$rtl_stylesheet_link = str_replace(
'"',
"'",
wp_get_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => wp_admin_css_uri( "$file-rtl" ),
)
)
);

/** This filter is documented in wp-includes/general-template.php */
Expand Down
78 changes: 77 additions & 1 deletion src/wp-includes/script-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,18 @@ function _print_styles() {
}

$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "' media='all' />\n";
// Preserve the concatenated link's historical single-quoted markup.
echo str_replace(
'"',
"'",
wp_get_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => $href,
'media' => 'all',
)
)
);

if ( ! empty( $wp_styles->print_code ) ) {
$processor = new WP_HTML_Tag_Processor( '<style></style>' );
Expand Down Expand Up @@ -3672,6 +3683,71 @@ function wp_print_inline_script_tag( $data, $attributes = array() ) {
echo wp_get_inline_script_tag( $data, $attributes );
}

/**
* Formats `<link rel="stylesheet">` tags.
*
* It is possible to inject attributes in the stylesheet link tag via the {@see 'wp_style_attributes'} filter.
*
* @since 7.3.0
*
* @param array<string, string|bool|null> $attributes Key-value pairs representing `<link>` tag attributes. Values of
* `true` or `null` add a bare attribute, `false` omits it, and
* strings (including empty strings) are serialized as values.
* @return string String containing a `<link>` tag.
*
* @phpstan-return non-falsy-string
*/
function wp_get_stylesheet_link_tag( $attributes ) {
/**
* Filters attributes to be added to a stylesheet link tag.
*
* @since 7.3.0
*
* @param array<string, string|bool|null> $attributes Key-value pairs representing `<link>` tag attributes.
* Values of `true` or `null` add a bare attribute; `false`
* omits the attribute.
*/
$attributes = apply_filters( 'wp_style_attributes', $attributes );

$processor = new WP_HTML_Tag_Processor( '<link />' );
$processor->next_tag();
$seen_attributes = array();
foreach ( $attributes as $name => $value ) {
/*
* Lexical variations of an attribute name may represent the same attribute in HTML.
* Calling code should rewrite an attribute's value rather than sending a duplicate.
*/
$normalized_name = strtolower( $name );
if ( isset( $seen_attributes[ $normalized_name ] ) ) {
continue;
}
$seen_attributes[ $normalized_name ] = true;

if ( null !== $processor->get_attribute( $name ) ) {
continue;
}

$processor->set_attribute( $name, $value ?? true );
}

return "{$processor->get_updated_html()}\n";
}

/**
* Prints a formatted stylesheet link tag.
*
* It is possible to inject attributes in the stylesheet link tag via the {@see 'wp_style_attributes'} filter.
*
* @since 7.3.0
*
* @param array<string, string|bool|null> $attributes Key-value pairs representing `<link>` tag attributes. Values of
* `true` or `null` add a bare attribute, `false` omits it, and
* strings (including empty strings) are serialized as values.
*/
function wp_print_stylesheet_link_tag( $attributes ) {
echo wp_get_stylesheet_link_tag( $attributes );
}

/**
* Allows small styles to be inlined.
*
Expand Down
10 changes: 9 additions & 1 deletion src/wp-includes/theme-compat/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@

<title><?php echo wp_get_document_title(); ?></title>

<link rel="stylesheet" href="<?php bloginfo( 'stylesheet_url' ); ?>" media="screen" />
<?php
wp_print_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => get_bloginfo( 'stylesheet_url', 'display' ),
'media' => 'screen',
)
);
?>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php if ( file_exists( get_stylesheet_directory() . '/images/kubrickbgwide.jpg' ) ) { ?>
Expand Down
9 changes: 6 additions & 3 deletions src/wp-includes/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,12 @@ function locale_stylesheet() {
return;
}

printf(
'<link rel="stylesheet" href="%s" media="screen" />',
$stylesheet
wp_print_stylesheet_link_tag(
array(
'rel' => 'stylesheet',
'href' => $stylesheet,
'media' => 'screen',
)
);
}

Expand Down
Loading
Loading