Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

share|improve this answer
    
Yes, you're right. The above code is implemented in a function which is runned within the next actions: save_post, switch_theme, register_activation_hook. If the site administrator would upload a new versioned stylesheet for example, he will need to deactivate and activate again the plugin. I would not use a cronjob and don't see another dynamicaly way to control this versioning issue. BTW, your code works like a charm integrated into my example. Thanks a lot! :) –  Grávuj Miklós Henrich Apr 18 '13 at 16:09
    
Oh, i did a mistake. After each every file is added the ?ver=3.5.1 Hehe. Which is wrong. I think that is the wp version instead of the required versions. –  Grávuj Miklós Henrich Apr 18 '13 at 16:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.