
內容簡介
這個外掛會在管理列新增一個選單,以快速辨識網站不同的環境(例如正式版和開發版),並能輕鬆地在其他環境切換到相同的網址。支援多站架設,包括子網域和子目錄架構。
設定
外掛有一個方便的設定頁面,但也可以透過篩選器鉤子在程式碼上進行設定。
透過WordPress管理介面設定環境
前往WordPress管理介面中的「設定>設定環境」,以檢視和編輯設定。
使用WordPress篩選器鉤子設定環境
鉤綁至drgnff_wp_stage_switcher__environments,並傳回具有環境的陣列。以下是篩選器函數的範例:
add_filter( 'drgnff_wp_stage_switcher__environments', function ($envs) {
return [
[
'url' => 'https://example.com', // 主頁 網址
'title' => '正式版', // 名稱
'color' => '#ffffff', // 十六進位顏色 (可選)
'background_color' => '#ff0000', // 十六進位背景色 (可選)
],
[
'url' => 'https://example.com',
'title' => '開發版',
'color' => '#ffffff',
'background_color' => '#228b22',
],
];
});
控制切換器的可見度
預設情況下,切換器選單會顯示給所有已登入的使用者。通過鉤綁至drgnff_wp_stage_switcher__should_display_switcher,並傳回布林值,您可以控制是否顯示切換器。
覆寫預設環境
如果目前的網站不在環境列表中,預設環境會用於當前網站。 通過鉤綁至drgnff_wp_stage_switcher__default_environment,您可以控制預設環境的標題和顏色。
設定備註
篩選器優先於在設定頁面上進行的手動設定。如果使用篩選器,則相關部分的設定頁面會呈現為唯讀模式。
對於多站安裝,請使用主站的網址。
本外掛邏輯的啟動,是在插件載入時的plugins_loaded鉤子以11的優先權進行。因此,影響外掛的鉤綁器必須在之前加入。
外掛標籤
開發者團隊
原文外掛簡介
Adds a menu to the admin bar to quickly identify different environments for a site (e.g. production and development) and easily switch to the same URL on other environments. Multi-site compatible for both sub-domain and sub-directory installations.
Configuration
The plugin has a convenient settings page but can also be configured programatically via a filter hook.
Setting environments via the WordPress admin interface
Navigate to “Settings > Set the Stage” in the WordPress admin to review and edit the configuration.
Setting environments via a WordPress filter hook
Hook to drgnff_wp_stage_switcher__environments and return an array with environments. Here’s an example filter function:
add_filter( 'drgnff_wp_stage_switcher__environments', function ($envs) {
return [
[
'url' => 'https://example.com', // home url
'title' => 'LIVE', // display name
'color' => '#ffffff', // hex color (optional)
'background_color' => '#ff0000', // hex color (optional)
],
[
'url' => 'https://example.com',
'title' => 'DEVELOPMENT',
'color' => '#ffffff',
'background_color' => '#228b22',
],
];
});
Controlling visibility of the switcher
By default the switcher menu is displayed to all logged in users. By hooking to drgnff_wp_stage_switcher__should_display_switcher and returning a boolean you can control whether the switcher should be displayed.
Overriding the default environment
The default environment is used for the current site if it’s not in the list of environments. By hooking to drgnff_wp_stage_switcher__default_environment you can control the title and colors for the default environment.
A few notes on configuration
Filters have a precedence over manual configuration made in the settings page. If filters are used then relevant sections on the settings page are rendered as read-only.
For multi-site installations use the URLs of the main site.
The plugin initiates its logic on the plugins_loaded hook with priority 11. Thus filter hooks that affect the plugin must be added before that.
