[WordPress] 外掛分享: Trigger Browsersync

前言介紹

  • 這款 WordPress 外掛「Trigger Browsersync」是 2017-04-06 上架。
  • 目前有 10 個安裝啟用數。
  • 上一次更新是 2022-06-23,距離現在已有 1045 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 3.0.1 以上版本才可以安裝。
  • 有 3 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

patabugen |

外掛標籤

dev | refresh | automation | browsersync |

內容簡介

將WordPress和Browsersync整合,當您編輯頁面時觸發重新載入等事件。

目前該插件僅觸發重新加載功能。如果您有其他功能的需求或想法,請聯繫我們。

由於您(應該)在生產網站上禁用此插件,因此WordPress統計數據將不可靠。如果您發現該插件有用,我們真的很感謝您通過快速電子郵件或消息讓我們知道!

觸發器

默認情況下,該插件會在以下操作上觸發重新載入:

save_post-編輯文章、頁面、自定義文章等
added_option-更改設置
attachment_updated-編輯媒體字段(標題等)
updated_postmeta-涵蓋許多事項,特別是重新生成媒體縮略圖。一些meta_fields被忽略(參見trigger_browsersync_irrelevant_meta_keys)
activated_plugin
deactivated_plugin
delete_widget

您可以使用過濾器自定義此及其他Browsersync設置:

add_filter('trigger_browsersync_reload_actions', function($filters) {
//刪除默認值。請記住,您採取的一個操作(例如保存頁面)可能觸發多個鉤子。
unset($filters['save_post']);
//添加自己的濾波器。鍵名允許其他過濾器刪除它(如上面的行)
$filters['wp_logout'] = 'wp_logout';
return $filters;
});

忽略Meta Key

並非所有的meta_key更新(由updated_postmeta觸發)對您站點的前端功能都有影響。您可以使用trigger_browsersync_irrelevant_meta_keys過濾器自定義要忽略的meta_key值:

add_filter('trigger_browsersync_irrelevant_meta_keys', function($filters) {
// 刪除默認值。
unset($filters['_edit_lock']);
//添加你自己的。鍵名允許其他過濾器刪除它(如上面的行)
$filters['_edit_lock'] = '_edit_lock';
return $filters;
});

使用過濾器進行配置

將使用默認的Browsersync設置(http://localhost:3000),但您可以使用過濾器進行更改。過濾器每次激活觸發器時都會使用,因此您不需要在實例化類之前設置它們。

add_filter('trigger_browsersync_protocol', function(){ return 'https'; } );
add_filter('trigger_browsersync_host', function(){ return 'dev.server'; } );
add_filter('trigger_browsersync_port', function(){ return '4321'; } );

或者,您可以指定整個URL,這樣其他URL就會被忽略,但請勿包含尾隨斜杠。

add_filter('trigger_browsersync_url', function(){ return 'http://localhost:3000'; } );

環境配置

由於您可能只想要在開發或測試站點上使用Browsersync,因此一旦您在WordPress中啟用它,插件就不會起作用。

要使其工作,您需要創建一個檔案來啟用它。詳情請參閱安裝說明。

記錄活動

Trigger Browsersync可以將事件記錄到WordPress日誌中-這對於插件的開發尤其有用,當您想添加或排除新事件以觸發操作時。

要啟用記錄,請在您的enable-trigger-browsersync.php文件中添加此過濾器(請參閱安裝);

add_filter('trigger_browsersync_log_events', '__return_true');

原文外掛簡介

Integrates WordPress with Browsersync to trigger events like reload when you edit pages.
The plugin also only triggers a reload for now. If you have requests or ideas for other functionality, get in touch.
Since you (should) disable this plugin on production sites, the WordPress stats won’t be reliable – if you find the plugin useful I’d really appreciate it if you’d let me know with a quick email or message!
Triggers
By default the plugin will trigger a reload on these actions:

save_post – Editing posts/pages/custom posts etc
added_option – Changing settings
attachment_updated – Editing media fields (caption etc)
updated_postmeta – Covers many things, particularly regenerating media thumbnails. Some meta_fields are ignored (see trigger_browsersync_irrelevant_meta_keys)
activated_plugin
deactivated_plugin
delete_widget

you can customise this as well as other Browsersync settings using filters:
add_filter('trigger_browsersync_reload_actions', function($filters) {
// Remove a default. Bear in mind that one action you take (e.g. saving a page)
// may trigger more than one hook.
unset($filters['save_post']);
// Add your own. The key name lets other filters remove it (like the line above)
$filters['wp_logout'] = 'wp_logout';
return $filters;
});

Ignoring Meta Keys
Not all meta_key updates (triggered by updated_postmeta) have any impact on the front-end functioning of your site. You can customise which meta_key values are ignored with the trigger_browsersync_irrelevant_meta_keys filter:
add_filter('trigger_browsersync_irrelevant_meta_keys', function($filters) {
// Remove a default.
unset($filters['_edit_lock']);
// Add your own. The key name lets other filters remove it (like the line above)
$filters['_edit_lock'] = '_edit_lock';
return $filters;
});

Configuration with Filters
The default Browsersync settings will be used (http://localhost:3000) but you can use filters to change them. The filters are used every time the trigger is activated so you don’t need to set them before instanciating the class.
add_filter('trigger_browsersync_protocol', function(){ return 'https'; } );
add_filter('trigger_browsersync_host', function(){ return 'dev.server'; } );
add_filter('trigger_browsersync_port', function(){ return '4321'; } );

Or you can specify the whole URL which will cause the others to be ignored, but don’t include a trailing slash.
add_filter('trigger_browsersync_url', function(){ return 'http://localhost:3000'; } );

Environmental Configuration
Since you probably only want Browsersync on your development or staging site, the plugin will do nothing once you activate it it in WordPress.
To make it work, you’ll want to create a file to activate it. See Installation for instructions.
Logging Activity
Trigger Browsersync can log events to the WordPress log – this is especially useful for development on the plugin when you want to add or exclude a new event from triggering an action.
To enable logging add this filter to your enable-trigger-browsersync.php file (see Installation);
add_filter('trigger_browsersync_log_events', '__return_true');

各版本下載點

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

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


最新版本

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

文章
Filter
Apply Filters
Mastodon