[WordPress] 外掛分享: Transient Cleaner

前言介紹

  • 這款 WordPress 外掛「Transient Cleaner」是 2012-11-27 上架。
  • 目前有 1000 個安裝啟用數。
  • 上一次更新是 2025-04-12,距離現在已有 22 天。
  • 外掛最低要求 WordPress 4.4 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 7.4 以上。
  • 有 23 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

dartiss |

外掛標籤

cache | clean | options | database | transient |

內容簡介

從你的 WordPress options 資料庫表格中清理已過期的 transients。這個外掛是原創且最好用的!

“Transients (翻譯中:暫存資料) 是 WordPress 中儲存快取資料的一個簡單且標準化的方式,它會以自定名稱和時間框架來暫時儲存在 WordPress 資料庫中,之後會到期並被刪除。”

不幸地,若你沒有嘗試訪問這個 transient,它就只有在那時才會被刪除。即使它已經過期了,WordPress 也不會自動去移除它。這是一個已知的問題,但根據 FAQ 所說的原因,這個問題沒有被充分解決。

為什麼這是個問題呢?因為許多外掛都會用 transients 來“快取”資料(我的外掛也包含在內)。因此,這意味著過期的資料可能會殘留下來並積累,進而導致資料庫的表格過於臃腫。

與此同時,這個外掛就是你一直以來渴望的英雄。只需啟用這個外掛,然後享受一個更加整潔且較小的 options 表格。它還增加了額外建議,當一次資料庫升級後,所有的 transients 會被清除。

我要感謝 WordPress 開發人員 Andrew Nacin 對此早期的討論。同時,我還要感謝Everybody Staze 的一篇有用文章,該文確保了所提出的解決方案是有意義的,以及W-Shadow.com的清理程式碼。

圖示是由非常有才華的Janki Rathod設計的 ♥️

👉 請造訪Github 頁面以了解最新的代碼開發、計畫中的增強功能及已知問題 👈

設定畫面

在 管理 -> 工具 -> Transients 中,有個選項頁面可以讓你調整何時清理,包括執行一次即時清理和設定自動排程的時間。

你還可以要求對 options 資料庫表格進行最佳化,以提升系統效能!

運行 Lite 模式

有一種“Lite”模式可供選擇。啟用這個模式後,選項畫面就不會再出現,且會使用預設設定。好處是,Admin 區塊可以提供更好的效能,尤其是在多站點環境下更顯著,因為沒有人能夠“亂搞”設定。

要啟用此功能,請使用以下指令碼...

define( 'TC_LITE', true );

這個要加入到你的 wp-config.php 檔案中。

使用個別鉤子

如果你是那種喜歡為 WordPress 編寫程式的人(真的嗎?),那麼我已經加入了一些鉤子,讓你可以呼叫我們相當精簡的清理功能...

housekeep_transients - 它會清除掉所有過期的 transients
clear_all_transients - 它會移除所有的transients,包括未過期的

原文外掛簡介

Clean expired transients from your options table. The original and best!
Transient housekeeping was added to the core of WordPress after version 5.8. However, I have decided to open up this plugin to all versions to allow for manual transient cleaning. Longer term I am working on a new version of the plugin, designed specifically for all WordPress releases.

Tested up to PHP 8.2
Fully complies with WordPress coding standards
Compliant with the stronger WordPress VIP coding standards, as well as compatibility with their platform
Community plugin – visit the [Github page](https://github.com/dartiss/[repo link] “Github”) to get involved with the latest code development, request enhancements and report issues

“Transients are a simple and standardized way of storing cached data in the WordPress database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted.”
Unfortunately, expired transients only get deleted when you attempt to access them. If you don’t access the transient then, even though it’s expired, WordPress will not remove it. This is a known “issue” but due to reasons, which are explained in the FAQ, this has not been adequately resolved.
Why is this a problem? Transients are often used by plugins to “cache” data (my own plugins included). Because of this it means that expired data can be left and build up, resulting in a bloated database table.
Meantime, this plugin is the hero that you’ve been waiting for. Simply activate the plugin, sit back and enjoy a much cleaner, smaller options table. It also adds the additional recommendation that after a database upgrade all transients will be cleared down.
The Settings Screen
Within Administration -> Tools -> Transients an options screen exists allowing you to tweak when you’d like cleaning to happen, including the ability to perform an ad-hoc run, and when you’d like the to be automatically scheduled.
You can even request an optimization of the options table to give your system a real “pep”!
Running in Lite mode
A “lite” mode is available. By activating this the options screen will no longer appear and default settings will be used. The advantage? Improved performance to Admin and, especially if you’re running multi-site, no chance of anybody “tinkering” with the settings.
To activate, use the following…
define( 'TC_LITE', true );

This should be added to your wp-config.php file.
Using hooks
If you’re the type of odd person who likes to code for WordPress (really?) then I’ve added a couple of hooks so you can call our rather neat cleaning functions…

housekeep_transients – this will clear down any expired transients
clear_all_transients – this will remove any and all transients, expired or otherwise

Acknowledgements
I’d like to thank WordPress Developer Andrew Nacin for his early discussion on this. Also, I’d like to acknowledge the useful article at Everybody Staze for ensuring the proposed solution made sense, and W-Shadow.com for the cleaning code.
Iconography is courtesy of the very talented Janki Rathod.

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Transient Cleaner」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


1.0 | 1.1 | 1.6 | 1.7 | 1.2.4 | 1.3.1 | 1.4.2 | 1.5.7 | 1.5.8 | 1.6.1 | 1.6.2 | trunk |

延伸相關外掛(你可能也想知道)

文章
Filter
Apply Filters
Mastodon