kaioe
8/25/2017 - 5:24 AM

Queue JS/CSS files applying the version number based on timeFile.

Queue JS/CSS files applying the version number based on timeFile.

function auto_version($file)
{
    $file = str_replace('http://', '', $file);
 
    $file = str_replace('https://', '', $file);
 
    $file = str_replace($_SERVER['SERVER_NAME'], '', $file);
 
    $full_file = $_SERVER['DOCUMENT_ROOT'] . $file;
 
    if (strpos($file, '/') !== 0 || !file_exists($full_file))
    {
        $full_file = substr($_SERVER['SCRIPT_FILENAME'], 0, -strlen($_SERVER['SCRIPT_NAME']));
 
        $full_file .= $file;
 
        if (!file_exists($full_file))
        {
            return $file;
        }
    }
 
    $mtime = filemtime($full_file);
 
   //$new_file = preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file);
    return $mtime;
}

/* 
Example Usage
 
$js_file = plugins_url().'/ignite-tools/assets/js/itg-sliders.js';
 
wp_register_script(
$handle    = "itg-sliders-js",
       $src       = $js_file,
       $deps      = array('jquery'),
       $ver       = auto_version($js_file),
       $in_footer = TRUE
       );
*/