外掛說明
WordPress 可以透過 WXR 匯出全部內容,並使用 WordPress Importer (WordPress 內容匯入程式) 匯入內容。這個流程可以匯出/匯入全部文章、分類法詞彙、選單、留言及使用者,但無法對網站的選項進行操作。這個外掛除了網站的一般設定外,還可以匯出/匯入的選項包含小工具組態、外掛設定、佈景主題設定等選項。手動移轉網站會非常耗時,WP Options Importer 可以提供協助並節省使用者大量的時間。
WP Options Importer 可以讓使用者將網站的全部選項匯出為 JSON 檔案,然後可以選擇性的將這些選項匯入至其他 WordPress 網站。匯入流程非常透明,並且會顯示哪些資料可以匯入,這個外掛也提供覆寫現有選項或略過已經存在的選項的功能。
螢幕擷圖
安裝方式
- 外掛壓縮檔解壓縮後,將包含全部檔案的外掛資料夾上傳至
/wp-content/plugins/
目錄。 - 在 WordPress 管理後台的 [外掛] 選單中啟用外掛。
- 前往 [工具]→[匯出程式],選取 [選項] 後便能匯出選項,或是前往 [工具]→[匯入程式],選取 [選項] 後便能匯入選項。
常見問題集
-
為網站匯入 [預設選項] 後,某些外掛的設定無法移轉,應該如何處理?
-
[預設選項] 是核心程式選項,或這個外掛認為可以安全匯入的選項。使用者可以選取 [指定選項],便能依據需求手動匯入需要匯入的選項。
-
我不能這麼做,但是你可以自己完成。這個外掛為開發者提供
options_import_allowlist
篩選器,讓開發者可以將選項加入這個外掛的預設選項清單中。以下為範例程式碼:function my_awesome_plugin_options( $options ) { $options[] = 'my_awesome_plugin'; return $options; } add_filter( 'options_import_allowlist', 'my_awesome_plugin_options' );
同理可證,如果不想讓使用者匯入某個選項,開發者可以使用
options_import_denylist
篩選器將選項加入封鎖清單中。以下為範例程式碼:function my_awesome_plugin_denylist_options( $options ) { $options[] = 'my_awesome_plugin_edit_lock'; return $options; } add_filter( 'options_import_denylist', 'my_awesome_plugin_denylist_options' );
-
我營運一個 WordPress 多站網路,有些選項「永遠」不該由子網站的網站管理員匯出或匯入,該如何達到這個目的?
-
無論是匯出或匯入,多站網路管理員都有兩個限制做法。
匯入
首先,多站網路管理員可以使用
options_import_denylist
篩選器將任何選項納入陣列中 (預設陣列值為空)。如果多站網路的使用者可以存取佈景主題或外掛的程式碼,因為他們可以使用相同的篩選器覆寫多站網路管理員的封鎖清單,因此無法保證百分之百安全。在這類狀況中,可以使用緊急開關停用匯入選項。要使用這項功能,請定義WP_OPTION_IMPORT_DENYLIST_REGEX
常數 (多站網路管理員可能會想使用於強制使用外掛),並為其設定規則運算式,而符合該運算式的項目均會略過。以下為範例程式碼:define( 'WP_OPTION_IMPORT_DENYLIST_REGEX', '/^(home|siteurl)$/' );
匯出
與匯入幾乎相同,對應的篩選器為
options_export_denylist
,而其常數為WP_OPTION_EXPORT_DENYLIST_REGEX
。
使用者評論
參與者及開發者
變更記錄
7
- SECURITY: Add proper escaping to all echo functions
- SECURITY: Add nonce checks
- SECURITY: Sanitize option name values during import
- ENHANCEMENT: Use wp_remote_get instead of file_get_contents
- INFO: Deprecate the use of blacklist and whitlelist in favor of denylist and allowlist
- INFO: Move class into new file
- INFO: Enable phpcs against the WordPress standard
6
- Remove multisite site-specific exclusions
5
- Added WP_OPTION_EXPORT_BLACKLIST_REGEX
- Breaking: Changed the
options_export_exclude
filter tooptions_export_blacklist
to be consistent with imports.
4
- After file upload, store data in transient and immediately delete the file so it doesn’t linger on the server.
3
- Added blacklists
- Fixing bug where plugin wouldn’t show in multisite when WP Importer wasn’t active.
- Misc bug fixes
2
- Spit & polish
- Improved error handling
- Added file cleanup on completion
- Misc bug fixes
1
- Brand new!