| @@ -97,8 +97,11 @@ | ||
| 97 | 97 | * @param string $url |
| 98 | 98 | * @return string |
| 99 | 99 | */ |
| 100 | 100 | public static function get_file_path($url) { |
| 101 | + $url_without_query = strtok($url, '?'); | |
| 102 | + $url = false === $url_without_query ? $url : $url_without_query; | |
| 103 | + | |
| 101 | 104 | if (is_multisite()) { |
| 102 | 105 | if (function_exists('get_main_site_id')) { |
| 103 | 106 | $site_id = get_main_site_id(); |
| 104 | 107 | } else { |
| @@ -463,9 +466,44 @@ | ||
| 463 | 466 | * |
| 464 | 467 | * @return string |
| 465 | 468 | */ |
| 466 | 469 | public static function get_url_without_cache_purge_params() { |
| 467 | - return remove_query_arg(array('_wpo_purge', 'wpo_minify_cache_purged', '_wpo_purge_minify_cache', 'wpo_all_pages_cache_purged', 'wpo_single_page_cache_purged')); | |
| 470 | + return remove_query_arg(self::get_cache_purge_params()); | |
| 471 | + } | |
| 472 | + | |
| 473 | + /** | |
| 474 | + * Outputs JavaScript to remove cache purge parameters from the URL. | |
| 475 | + * | |
| 476 | + * @return void | |
| 477 | + */ | |
| 478 | + public static function script_to_remove_cache_purge_params_from_url() { | |
| 479 | + printf('<script>document.addEventListener("DOMContentLoaded", function() { var params = %s; var url = new URL(window.location.href); for (var param of params) { url.searchParams.delete(param); } history.replaceState({}, "", url); });</script>', json_encode(self::get_cache_purge_params())); | |
| 480 | + } | |
| 481 | + | |
| 482 | + /** | |
| 483 | + * Returns the list of parameter names used for cache purge actions | |
| 484 | + * | |
| 485 | + * @return array | |
| 486 | + */ | |
| 487 | + private static function get_cache_purge_params() { | |
| 488 | + $original_purge_params = array('_wpo_purge', 'wpo_minify_cache_purged', '_wpo_purge_minify_cache', 'wpo_all_pages_cache_purged', 'wpo_single_page_cache_purged'); | |
| 489 | + $purge_params = apply_filters('wpo_get_cache_purge_params', $original_purge_params); | |
| 490 | + | |
| 491 | + if (!is_array($purge_params)) $purge_params = $original_purge_params; | |
| 492 | + | |
| 493 | + return $purge_params; | |
| 494 | + } | |
| 495 | + | |
| 496 | + /** | |
| 497 | + * Returns a human-readable time difference or "Never" if no timestamp exists. | |
| 498 | + * | |
| 499 | + * @param int|null $timestamp Unix timestamp, or null/0 for "Never". | |
| 500 | + * @return string Human-readable time string. | |
| 501 | + */ | |
| 502 | + public static function human_time_diff_or_never(?int $timestamp = null): string { | |
| 503 | + if (!$timestamp) return __('Never', 'wp-optimize'); | |
| 504 | + /* translators: %s = human-readable time difference */ | |
| 505 | + return sprintf(__('%s ago', 'wp-optimize'), human_time_diff($timestamp, time())); | |
| 468 | 506 | } |
| 469 | 507 | } |
| 470 | 508 | |
| 471 | 509 | endif; |