From b1d84e3bbd5654342b0c6b4c9683d016070f1bde Mon Sep 17 00:00:00 2001 From: nanhaoluo <3075912108@qq.com> Date: Thu, 15 Jan 2026 22:43:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E7=BC=93=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在设置页杂项部分添加强制刷新缓存按钮 - 启用后所有资源文件(CSS/JS)将附加时间戳参数 - 1小时后自动关闭,避免服务器压力 - 解决手机端浏览器缓存导致样式或功能无法更新的问题 - 支持实时倒计时显示剩余时间 --- footer.php | 3 +- functions.php | 87 +++++++++++++++++++++ header.php | 13 ++-- settings.php | 207 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 304 insertions(+), 6 deletions(-) diff --git a/footer.php b/footer.php index 0f14f3e..975cddb 100644 --- a/footer.php +++ b/footer.php @@ -30,7 +30,8 @@ - + + diff --git a/functions.php b/functions.php index 3251715..b93e9cb 100644 --- a/functions.php +++ b/functions.php @@ -35,6 +35,93 @@ $GLOBALS['theme_version'] = $argon_version; // 强制使用本地资源,避免 CDN 加载问题 $GLOBALS['assets_path'] = get_bloginfo('template_url'); +// ==================== 强制刷新缓存功能 ==================== + +/** + * 检查强制刷新缓存是否启用 + * 启用后 1 小时自动关闭 + */ +function argon_is_force_refresh_enabled() { + $enabled_time = get_option('argon_force_refresh_enabled_time', 0); + if ($enabled_time == 0) { + return false; + } + // 检查是否超过 1 小时 + if (time() - $enabled_time > 3600) { + // 自动关闭 + update_option('argon_force_refresh_enabled_time', 0); + return false; + } + return true; +} + +/** + * 获取资源版本号 + * 如果启用了强制刷新,返回当前时间戳 + */ +function argon_get_assets_version() { + if (argon_is_force_refresh_enabled()) { + return $GLOBALS['theme_version'] . '.' . time(); + } + return $GLOBALS['theme_version']; +} + +/** + * 启用强制刷新缓存 + */ +function argon_enable_force_refresh() { + check_ajax_referer('argon_force_refresh', 'nonce'); + + if (!current_user_can('manage_options')) { + wp_send_json_error(__('权限不足', 'argon')); + } + + update_option('argon_force_refresh_enabled_time', time()); + wp_send_json_success(array( + 'message' => __('强制刷新已启用,将在 1 小时后自动关闭', 'argon'), + 'expires_at' => time() + 3600 + )); +} +add_action('wp_ajax_argon_enable_force_refresh', 'argon_enable_force_refresh'); + +/** + * 关闭强制刷新缓存 + */ +function argon_disable_force_refresh() { + check_ajax_referer('argon_force_refresh', 'nonce'); + + if (!current_user_can('manage_options')) { + wp_send_json_error(__('权限不足', 'argon')); + } + + update_option('argon_force_refresh_enabled_time', 0); + wp_send_json_success(array( + 'message' => __('强制刷新已关闭', 'argon') + )); +} +add_action('wp_ajax_argon_disable_force_refresh', 'argon_disable_force_refresh'); + +/** + * 获取强制刷新状态 + */ +function argon_get_force_refresh_status() { + check_ajax_referer('argon_force_refresh', 'nonce'); + + $enabled_time = get_option('argon_force_refresh_enabled_time', 0); + $is_enabled = argon_is_force_refresh_enabled(); + $remaining = 0; + + if ($is_enabled && $enabled_time > 0) { + $remaining = max(0, 3600 - (time() - $enabled_time)); + } + + wp_send_json_success(array( + 'enabled' => $is_enabled, + 'remaining' => $remaining + )); +} +add_action('wp_ajax_argon_get_force_refresh_status', 'argon_get_force_refresh_status'); + //翻译 Hook function argon_locate_filter($locate){ if (substr($locate, 0, 2) == 'zh'){ diff --git a/header.php b/header.php index 597ec3a..46f488e 100644 --- a/header.php +++ b/header.php @@ -265,12 +265,15 @@ @@ -323,7 +326,7 @@ - + diff --git a/settings.php b/settings.php index 0660ab1..7d1505e 100644 --- a/settings.php +++ b/settings.php @@ -4731,6 +4731,213 @@ window.pjaxLoaded = function(){ + + + + + + + 0) { + $remaining = max(0, 3600 - (time() - $enabled_time)); + } + ?> + +
+ +
+ + + + + + + + ' . floor($remaining / 60) . ':' . str_pad($remaining % 60, 2, '0', STR_PAD_LEFT) . ''); ?> + + + + + + + + + +
+ + + +
+ +

+ +
+ + + +

+ + + + + + +