Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
use full link for WordPress resources (#7211)
Browse files Browse the repository at this point in the history
Co-authored-by: Niels Lange <[email protected]>
  • Loading branch information
senadir and nielslange authored Sep 23, 2022
1 parent ad83e75 commit 9f9682f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private function get_script_dependency_src_array( array $dependencies ) {
$dependencies,
function( $src, $handle ) use ( $wp_scripts ) {
if ( isset( $wp_scripts->registered[ $handle ] ) ) {
$src[] = add_query_arg( 'ver', $wp_scripts->registered[ $handle ]->ver, $wp_scripts->registered[ $handle ]->src );
$src[] = add_query_arg( 'ver', $wp_scripts->registered[ $handle ]->ver, $this->get_absolute_url( $wp_scripts->registered[ $handle ]->src ) );
$src = array_merge( $src, $this->get_script_dependency_src_array( $wp_scripts->registered[ $handle ]->deps ) );
}
return $src;
Expand All @@ -172,6 +172,20 @@ function( $src, $handle ) use ( $wp_scripts ) {
);
}

/**
* Returns an absolute url to relative links for WordPress core scripts.
*
* @param string $src Original src that can be relative.
* @return string Correct full path string.
*/
private function get_absolute_url( $src ) {
$wp_scripts = wp_scripts();
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $wp_scripts->content_url && 0 === strpos( $src, $wp_scripts->content_url ) ) ) {
$src = $wp_scripts->base_url . $src;
}
return $src;
}

/**
* Add body classes to the frontend and within admin.
*
Expand Down

0 comments on commit 9f9682f

Please sign in to comment.