Earlier I've learned how to remove file versions from wordpress style and script file source links inside the wp_head
function. From here: How to remove file versions from the file source links in wp_head?
I had a good reason needing that action. Why? While writing a cache manifest file, inside that file I managed to write also absolute source links, but without ?ver=
parameter. wp_head
has generated the used theme with ?ver=
parameter the syle and script file inclusions. So there was smooth differences between the cache data and theme data. I don't know if that was the reason not getting the styles while being offline my test site.
Question:
Now what I'd like to know, is the way how can I add ?ver=
parameter to the cache manifest file entries. I'm writing this way the cache file's lines:
$hashes = "";
$network = array("\n\nNETWORK:");
$cache = array("\n\nCACHE:");
$path = get_stylesheet_directory()."/";
$dir = new RecursiveDirectoryIterator( $path );
foreach(new RecursiveIteratorIterator($dir) as $file) {
if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") {
if(preg_match('/.php$/', $file)) {
if (isAllowedExtension($file))
array_push($network,"\n" . str_replace($path, './', $file));
} else {
if (isAllowedExtension($file))
array_push($cache,"\n" . str_replace($path, './', $file));
}
$hashes .= md5_file($file);
}
}
Hence this aren't absolute url's, I'm just curious how could be possible adding the ?ver=
parameter to this file url's? :)
===
Update:
if( !strpos( $file, '?ver=' ) ) {
$file = add_query_arg( 'ver', $file );
return $file;
}
This is only a try... Not complete code. First I think we should check if the file has any version, then add the version parameter after the source url.
Earlier I've learned how to remove file versions from wordpress style and script file source links inside the wp_head
function. From here: How to remove file versions from the file source links in wp_head?
I had a good reason needing that action. Why? While writing a cache manifest file, inside that file I managed to write also absolute source links, but without ?ver=
parameter. wp_head
has generated the used theme with ?ver=
parameter the syle and script file inclusions. So there was smooth differences between the cache data and theme data. I don't know if that was the reason not getting the styles while being offline my test site.
Question:
Now what I'd like to know, is the way how can I add ?ver=
parameter to the cache manifest file entries. I'm writing this way the cache file's lines:
$hashes = "";
$network = array("\n\nNETWORK:");
$cache = array("\n\nCACHE:");
$path = get_stylesheet_directory()."/";
$dir = new RecursiveDirectoryIterator( $path );
foreach(new RecursiveIteratorIterator($dir) as $file) {
if ($file->IsFile() && $file != "./manifest.php" && substr($file->getFilename(), 0, 1) != ".") {
if(preg_match('/.php$/', $file)) {
if (isAllowedExtension($file))
array_push($network,"\n" . str_replace($path, './', $file));
} else {
if (isAllowedExtension($file))
array_push($cache,"\n" . str_replace($path, './', $file));
}
$hashes .= md5_file($file);
}
}
Hence this aren't absolute url's, I'm just curious how could be possible adding the ?ver=
parameter to this file url's? :)
===
Update:
if( !strpos( $file, '?ver=' ) ) {
$file = add_query_arg( 'ver', $file );
return $file;
}
This is only a try... Not complete code. First I think we should check if the file has any version, then add the version parameter after the source url.
You could use add_query_arg()
:
$url = add_query_arg( 'ver', $GLOBALS['wp_version'], $url );
But I see one problem: How can you be sure the resource is actually used? And how do you know the author has not passed a custom version?
So you can do that only in a very controlled environment: when you know everything about the code.