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(){ +
+
+
+
+
+
+