Skip to content
Open
24 changes: 19 additions & 5 deletions src/wp-includes/class-wp-scripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@ 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;

/**
* URL of the content directory.
*
* @since 2.8.0
* @var string
* @see wp_default_scripts()
* @var string|null
*/
public $content_url;

/**
* Default version string for scripts.
*
* @since 2.6.0
* @var string
* @see wp_default_scripts()
* @var string|null
*/
public $default_version;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -413,9 +417,19 @@ public function do_item( $handle, $group = false ) {
$src = $this->base_url . $src;
}

if ( ! empty( $ver ) ) {
$src = add_query_arg( 'ver', $ver, $src );
$query_args = array();
if ( false === $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 ) );
Expand Down
33 changes: 24 additions & 9 deletions src/wp-includes/class-wp-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,34 @@ 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;

/**
* URL of the content directory.
*
* @since 2.8.0
* @var string
* @see wp_default_styles()
* @var string|null
*/
public $content_url;

/**
* Default version string for stylesheets.
*
* @since 2.6.0
* @var string
* @see wp_default_styles()
* @var string|null
*/
public $default_version;

/**
* The current text direction.
*
* @since 2.6.0
* @see wp_default_styles()
* @var string
*/
public $text_direction = 'ltr';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -212,7 +217,7 @@ public function do_item( $handle, $group = false ) {
return true;
}

$href = $this->_css_href( $src, $ver, $handle );
$href = $this->_css_href( $src, $obj->ver, $handle );
if ( ! $href ) {
return true;
}
Expand Down Expand Up @@ -419,19 +424,29 @@ public function all_deps( $handles, $recursion = false, $group = false ) {
*
* @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 ) {
if ( ! is_bool( $src ) && ! preg_match( '|^(https?:)?//|', $src ) && ! ( $this->content_url && str_starts_with( $src, $this->content_url ) ) ) {
$src = $this->base_url . $src;
}

if ( ! empty( $ver ) ) {
$src = add_query_arg( 'ver', $ver, $src );
$query_args = array();
if ( false === $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.
Expand Down
Loading
Loading