Script Loader: Fix adding default version to script/style URL when args are supplied via enqueued handle.

Also fixes phpdoc for some member variables of `WP_Scripts` and `WP_Styles`.

Developed in https://github.com/WordPress/wordpress-develop/pull/10608

Follow-up to [61358].

Props westonruter, peterwilsoncc.
See #64224, #64238.
Fixes #64372.

Built from https://develop.svn.wordpress.org/trunk@61397


git-svn-id: http://core.svn.wordpress.org/trunk@60709 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2025-12-22 00:56:42 +00:00
parent 30538e82f2
commit 46045c50d7
3 changed files with 44 additions and 15 deletions

View File

@@ -22,7 +22,8 @@ class WP_Scripts extends WP_Dependencies {
* Full URL with trailing slash.
*
* @since 2.6.0
* @var string
* @see wp_default_scripts()
* @var string|null
*/
public $base_url;
@@ -30,7 +31,8 @@ class WP_Scripts extends WP_Dependencies {
* URL of the content directory.
*
* @since 2.8.0
* @var string
* @see wp_default_scripts()
* @var string|null
*/
public $content_url;
@@ -38,7 +40,8 @@ class WP_Scripts extends WP_Dependencies {
* Default version string for scripts.
*
* @since 2.6.0
* @var string
* @see wp_default_scripts()
* @var string|null
*/
public $default_version;
@@ -118,6 +121,7 @@ class WP_Scripts extends WP_Dependencies {
* List of default directories.
*
* @since 2.8.0
* @see wp_default_scripts()
* @var string[]|null
*/
public $default_dirs;
@@ -413,9 +417,19 @@ class WP_Scripts extends WP_Dependencies {
$src = $this->base_url . $src;
}
if ( ! empty( $ver ) ) {
$src = add_query_arg( 'ver', $ver, $src );
$query_args = array();
if ( empty( $obj->ver ) && null !== $obj->ver && is_string( $this->default_version ) ) {
$query_args['ver'] = $this->default_version;
} elseif ( is_scalar( $obj->ver ) ) {
$query_args['ver'] = (string) $obj->ver;
}
if ( isset( $this->args[ $handle ] ) ) {
parse_str( $this->args[ $handle ], $parsed_args );
if ( $parsed_args ) {
$query_args = array_merge( $query_args, $parsed_args );
}
}
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
/** This filter is documented in wp-includes/class-wp-scripts.php */
$src = esc_url_raw( apply_filters( 'script_loader_src', $src, $handle ) );

View File

@@ -22,7 +22,8 @@ class WP_Styles extends WP_Dependencies {
* Full URL with trailing slash.
*
* @since 2.6.0
* @var string
* @see wp_default_styles()
* @var string|null
*/
public $base_url;
@@ -30,7 +31,8 @@ class WP_Styles extends WP_Dependencies {
* URL of the content directory.
*
* @since 2.8.0
* @var string
* @see wp_default_styles()
* @var string|null
*/
public $content_url;
@@ -38,7 +40,8 @@ class WP_Styles extends WP_Dependencies {
* Default version string for stylesheets.
*
* @since 2.6.0
* @var string
* @see wp_default_styles()
* @var string|null
*/
public $default_version;
@@ -46,6 +49,7 @@ class WP_Styles extends WP_Dependencies {
* The current text direction.
*
* @since 2.6.0
* @see wp_default_styles()
* @var string
*/
public $text_direction = 'ltr';
@@ -96,6 +100,7 @@ class WP_Styles extends WP_Dependencies {
* List of default directories.
*
* @since 2.8.0
* @see wp_default_styles()
* @var string[]|null
*/
public $default_dirs;
@@ -218,7 +223,7 @@ class WP_Styles extends WP_Dependencies {
return true;
}
$href = $this->_css_href( $src, $ver, $handle );
$href = $this->_css_href( $src, $obj->ver, $handle );
if ( ! $href ) {
return true;
}
@@ -425,9 +430,9 @@ class WP_Styles extends WP_Dependencies {
*
* @since 2.6.0
*
* @param string $src The source of the enqueued style.
* @param string $ver The version of the enqueued style.
* @param string $handle The style's registered handle.
* @param string $src The source of the enqueued style.
* @param string|false|null $ver The version of the enqueued style.
* @param string $handle The style's registered handle.
* @return string Style's fully-qualified URL.
*/
public function _css_href( $src, $ver, $handle ) {
@@ -435,9 +440,19 @@ class WP_Styles extends WP_Dependencies {
$src = $this->base_url . $src;
}
if ( ! empty( $ver ) ) {
$src = add_query_arg( 'ver', $ver, $src );
$query_args = array();
if ( empty( $ver ) && null !== $ver && is_string( $this->default_version ) ) {
$query_args['ver'] = $this->default_version;
} elseif ( is_scalar( $ver ) ) {
$query_args['ver'] = (string) $ver;
}
if ( isset( $this->args[ $handle ] ) ) {
parse_str( $this->args[ $handle ], $parsed_args );
if ( $parsed_args ) {
$query_args = array_merge( $query_args, $parsed_args );
}
}
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
/**
* Filters an enqueued style's fully-qualified URL.

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '7.0-alpha-61396';
$wp_version = '7.0-alpha-61397';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.