|
@@ -242,14 +242,14 @@ class Studiou_WC_Product_Cat_Manage {
|
|
|
|
|
|
|
|
wp_enqueue_style(
|
|
wp_enqueue_style(
|
|
|
'studiou-wcpcm-admin',
|
|
'studiou-wcpcm-admin',
|
|
|
- STUDIOU_WCPCM_PLUGIN_URL . 'assets/css/admin.css',
|
|
|
|
|
|
|
+ $this->get_cache_busted_asset_url('assets/css/admin', 'css'),
|
|
|
array(),
|
|
array(),
|
|
|
STUDIOU_WCPCM_VERSION
|
|
STUDIOU_WCPCM_VERSION
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script(
|
|
wp_enqueue_script(
|
|
|
'studiou-wcpcm-admin',
|
|
'studiou-wcpcm-admin',
|
|
|
- STUDIOU_WCPCM_PLUGIN_URL . 'assets/js/admin.js',
|
|
|
|
|
|
|
+ $this->get_cache_busted_asset_url('assets/js/admin', 'js'),
|
|
|
array('jquery'),
|
|
array('jquery'),
|
|
|
STUDIOU_WCPCM_VERSION,
|
|
STUDIOU_WCPCM_VERSION,
|
|
|
true
|
|
true
|
|
@@ -301,7 +301,55 @@ class Studiou_WC_Product_Cat_Manage {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Build a cache-busting URL for a plugin asset.
|
|
|
|
|
+ *
|
|
|
|
|
+ * studiou.cz (and similar host optimisers) strip the `?ver=` query string
|
|
|
|
|
+ * from static assets, so a version bump alone does not bust the browser
|
|
|
|
|
+ * cache. To work around that, this serves the asset under a filename that
|
|
|
|
|
+ * embeds the plugin version, e.g. assets/js/admin-1.6.0.js. The versioned
|
|
|
|
|
+ * copy is generated automatically from the source file and refreshed
|
|
|
|
|
+ * whenever the source changes, so no manual file renaming is needed.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Falls back to the plain source URL if the copy cannot be written.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param string $rel_no_ext Asset path relative to the plugin dir, without
|
|
|
|
|
+ * extension, e.g. 'assets/js/admin'.
|
|
|
|
|
+ * @param string $ext File extension without the dot, e.g. 'js'.
|
|
|
|
|
+ * @return string Absolute URL to the asset.
|
|
|
|
|
+ */
|
|
|
|
|
+ private function get_cache_busted_asset_url($rel_no_ext, $ext) {
|
|
|
|
|
+ $source_rel = $rel_no_ext . '.' . $ext;
|
|
|
|
|
+ $source_abs = STUDIOU_WCPCM_PLUGIN_DIR . $source_rel;
|
|
|
|
|
+
|
|
|
|
|
+ // Source missing - nothing we can do, return the plain URL.
|
|
|
|
|
+ if (!file_exists($source_abs)) {
|
|
|
|
|
+ return STUDIOU_WCPCM_PLUGIN_URL . $source_rel;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $versioned_rel = $rel_no_ext . '-' . STUDIOU_WCPCM_VERSION . '.' . $ext;
|
|
|
|
|
+ $versioned_abs = STUDIOU_WCPCM_PLUGIN_DIR . $versioned_rel;
|
|
|
|
|
+
|
|
|
|
|
+ // Regenerate the versioned copy if it is missing or out of date.
|
|
|
|
|
+ if (!file_exists($versioned_abs) || filemtime($source_abs) > filemtime($versioned_abs)) {
|
|
|
|
|
+ // Remove stale versioned copies of this asset.
|
|
|
|
|
+ $old_files = glob(STUDIOU_WCPCM_PLUGIN_DIR . $rel_no_ext . '-*.' . $ext);
|
|
|
|
|
+ if (is_array($old_files)) {
|
|
|
|
|
+ foreach ($old_files as $old_file) {
|
|
|
|
|
+ @unlink($old_file);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Copy failed (e.g. read-only filesystem) - fall back to plain URL.
|
|
|
|
|
+ if (!@copy($source_abs, $versioned_abs)) {
|
|
|
|
|
+ return STUDIOU_WCPCM_PLUGIN_URL . $source_rel;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return STUDIOU_WCPCM_PLUGIN_URL . $versioned_rel;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Render import page
|
|
* Render import page
|
|
|
*/
|
|
*/
|