This commit is contained in:
Hanson.xyz Dev
2026-01-04 17:50:08 -06:00
parent 7e45ce0756
commit acc8ac87a0
4131 changed files with 232562 additions and 250244 deletions
+56 -24
View File
@@ -154,7 +154,10 @@ class WP_Styles extends WP_Dependencies {
}
$obj = $this->registered[ $handle ];
if ( $obj->extra['conditional'] ?? false ) {
return false;
}
if ( null === $obj->ver ) {
$ver = '';
} else {
@@ -165,16 +168,7 @@ class WP_Styles extends WP_Dependencies {
$ver = $ver ? $ver . '&' . $this->args[ $handle ] : $this->args[ $handle ];
}
$src = $obj->src;
$ie_conditional_prefix = '';
$ie_conditional_suffix = '';
$conditional = isset( $obj->extra['conditional'] ) ? $obj->extra['conditional'] : '';
if ( $conditional ) {
$ie_conditional_prefix = "<!--[if {$conditional}]>\n";
$ie_conditional_suffix = "<![endif]-->\n";
}
$src = $obj->src;
$inline_style = $this->print_inline_style( $handle, false );
if ( $inline_style ) {
@@ -189,7 +183,7 @@ class WP_Styles extends WP_Dependencies {
}
if ( $this->do_concat ) {
if ( $this->in_default_dir( $src ) && ! $conditional && ! isset( $obj->extra['alt'] ) ) {
if ( $this->in_default_dir( $src ) && ! isset( $obj->extra['alt'] ) ) {
$this->concat .= "$handle,";
$this->concat_version .= "$handle$ver";
@@ -200,7 +194,7 @@ class WP_Styles extends WP_Dependencies {
}
if ( isset( $obj->args ) ) {
$media = esc_attr( $obj->args );
$media = $obj->args;
} else {
$media = 'all';
}
@@ -224,16 +218,16 @@ class WP_Styles extends WP_Dependencies {
}
$rel = isset( $obj->extra['alt'] ) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet';
$title = isset( $obj->extra['title'] ) ? sprintf( " title='%s'", esc_attr( $obj->extra['title'] ) ) : '';
$title = isset( $obj->extra['title'] ) ? $obj->extra['title'] : '';
$tag = sprintf(
"<link rel='%s' id='%s-css'%s href='%s'%s media='%s' />\n",
$rel,
$handle,
$title,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$href,
$this->type_attr,
$media
esc_attr( $media )
);
/**
@@ -261,11 +255,11 @@ class WP_Styles extends WP_Dependencies {
$rtl_tag = sprintf(
"<link rel='%s' id='%s-rtl-css'%s href='%s'%s media='%s' />\n",
$rel,
$handle,
$title,
esc_attr( $handle ),
$title ? sprintf( " title='%s'", esc_attr( $title ) ) : '',
$rtl_href,
$this->type_attr,
$media
esc_attr( $media )
);
/** This filter is documented in wp-includes/class-wp-styles.php */
@@ -279,17 +273,13 @@ class WP_Styles extends WP_Dependencies {
}
if ( $this->do_concat ) {
$this->print_html .= $ie_conditional_prefix;
$this->print_html .= $tag;
if ( $inline_style_tag ) {
$this->print_html .= $inline_style_tag;
}
$this->print_html .= $ie_conditional_suffix;
} else {
echo $ie_conditional_prefix;
echo $tag;
$this->print_inline_style( $handle );
echo $ie_conditional_suffix;
}
return true;
@@ -333,10 +323,30 @@ class WP_Styles extends WP_Dependencies {
public function print_inline_style( $handle, $display = true ) {
$output = $this->get_data( $handle, 'after' );
if ( empty( $output ) ) {
if ( empty( $output ) || ! is_array( $output ) ) {
return false;
}
if ( ! $this->do_concat ) {
// Obtain the original `src` for a stylesheet possibly inlined by wp_maybe_inline_styles().
$inlined_src = $this->get_data( $handle, 'inlined_src' );
// If there's only one `after` inline style, and that inline style had been inlined, then use the $inlined_src
// as the sourceURL. Otherwise, if there is more than one inline `after` style associated with the handle,
// then resort to using the handle to construct the sourceURL since there isn't a single source.
if ( count( $output ) === 1 && is_string( $inlined_src ) && strlen( $inlined_src ) > 0 ) {
$source_url = esc_url_raw( $inlined_src );
} else {
$source_url = rawurlencode( "{$handle}-inline-css" );
}
$output[] = sprintf(
'/*# sourceURL=%s */',
$source_url
);
}
$output = implode( "\n", $output );
if ( ! $display ) {
@@ -353,6 +363,28 @@ class WP_Styles extends WP_Dependencies {
return true;
}
/**
* Overrides the add_data method from WP_Dependencies, to allow unsetting dependencies for conditional styles.
*
* @since 6.9.0
*
* @param string $handle Name of the item. Should be unique.
* @param string $key The data key.
* @param mixed $value The data value.
* @return bool True on success, false on failure.
*/
public function add_data( $handle, $key, $value ) {
if ( ! isset( $this->registered[ $handle ] ) ) {
return false;
}
if ( 'conditional' === $key ) {
$this->registered[ $handle ]->deps = array();
}
return parent::add_data( $handle, $key, $value );
}
/**
* Determines style dependencies.
*