外掛說明
注意事項:如果網站執行 WordPress 6.5 或更新版本,由於相關功能已內建至 WordPress 核心程式中,因此不需要安裝這個外掛。如果網站需要使用新的
.l10n.php格式產生語言套件,請改用 Performant Translations 外掛。
這個 WordPress 外掛能將 .mo 檔案快取為 PHP 陣列,並以 include 運算式處理過的陣列取代 .mo 檔案。在 PHP 環境中,載入及執行另一個 PHP 檔案理論上會最為快速。
外掛運作方式
如果網站上有會載入 textdomain 的外掛或佈景主題,例如使用 load_textdomain( 'textdomain', $path_to_mo_file ),這個外掛便會產生以下效果:
- 在
WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'目錄中查詢 .mo 檔案的 PHP 版本。 - 如果 PHP 版本資訊存在,便以 include 運算式處理 .mo 檔案。
- 如果 PHP 版本資訊不存在,載入 .mo 檔案並將檔案儲存為
wp-content/cache/a-faster-load-textdomain/目錄中的 PHP 陣列。
包含本地化介面字串的 PHP 陣列可以透過 PHP OPcache 進行快取。如果網站伺服器上的 PHP OPcache 已啟用,包含本地化介面字串的 PHP 陣列便會快取在伺服器記憶體中,不需再對 PHP 檔案進行剖析。
篩選器
a_faster_load_textdomain_cache_path
變更快取路徑前,請先了解預設路徑為 WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'。
add_filter( 'a_faster_load_textdomain_cache_path', function( $path ) {
return WP_CONTENT_DIR . '/cache/my-cache';
} );
GitHub
這個外掛在 GitHub 存放庫提供原始程式碼。
安裝方式
手動安裝 (建議):
– 下載外掛檔案並解壓縮後,將 a-faster-load-textdomain.php 及 class-afld-cachehandler.php 上傳至 wp-content/mu-plugins 目錄。
自動安裝:
– 搜尋「A faster load_textdomain」並使用 WordPress 外掛安裝程式安裝。
– (多站網路) 在 WordPress 管理後台的 [外掛] 選單中啟用外掛。
也可以使用 composer 命令安裝外掛:
composer require soderlind/a-faster-load-textdomain
使用者評論
這個外掛目前沒有任何使用者評論。
參與者及開發者
變更記錄
2.3.2
- Housekeeping.
2.3.1
- Catch errors in the cache handler. If the cache file is corrupt, update the file and return the .mo file.
2.3.0
- If running WordPress 6.5, give a notice that the plugin is not needed.
2.2.4
- Fail gracefully if cache directory can’t be created.
2.2.3
- Housekeeping.
2.2.2
- Add uninstall handler. Will remove the cache directory when the plugin is uninstalled.
2.2.1
- Fix bug in cache handler.
2.2.0
- Refactor cache handler.
2.1.5
- Bump version to force deploy to WordPress.org
2.1.4
- Deploy with GitHub Actions to WordPress.org
2.1.3
- Remove
mkdir()
2.1.2
- Fail gracefully if
$cache_pathcan’t be created.
2.1.1
- Add
aflt_load_textdomainfilter.
2.1.0
- Rename namespace to
Soderlind\Plugin\A_Faster_Load_Textdomain - Rename cache directory to
WP_CONTENT_DIR . '/cache/a-faster-load-textdomain'
2.0.1
- Rename file to
a-faster-load-textdomain.phpto follow WordPress plugin standards.
2.0.0
- Refactor code, instead of using a transient, save .mo file as an PHP array, and include the array instead of the .mo file.
1.0.3
- Housekeeping.
1.0.2
- DRY (Don’t Repeat Yourself) code. Add namespace.
1.0.1
- Add multisite support
1.0.0
- Initial release