Skip to content

Commit

Permalink
Fix generateFileVersion not working on alt setups like Bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
atanas-dev committed Apr 19, 2020
1 parent 7b7d005 commit 5dabf7e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Assets/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace WPEmergeTheme\Assets;

use WPEmerge\Helpers\MixedType;

class Assets {
/**
* Manifest.
Expand Down Expand Up @@ -51,21 +53,21 @@ protected function isExternalUrl( $url, $home_url ) {
*/
protected function generateFileVersion( $src ) {
// Normalize both URLs in order to avoid problems with http, https
// and protocol-less cases
// and protocol-less cases.
$src = $this->removeProtocol( $src );
$home_url = $this->removeProtocol( site_url( '/' ) );
$home_url = $this->removeProtocol( WP_CONTENT_URL );
$version = false;

if ( ! $this->isExternalUrl( $src, $home_url ) ) {
// Generate the absolute path to the file
$file_path = str_replace(
// Generate the absolute path to the file.
$file_path = MixedType::normalizePath( str_replace(
[$home_url, '/'],
[ABSPATH, DIRECTORY_SEPARATOR],
[WP_CONTENT_DIR, DIRECTORY_SEPARATOR],
$src
);
) );

if ( file_exists( $file_path ) ) {
// Use the last modified time of the file as a version
// Use the last modified time of the file as a version.
$version = filemtime( $file_path );
}
}
Expand Down

0 comments on commit 5dabf7e

Please sign in to comment.