前言介紹
- 這款 WordPress 外掛「Simple Hook Widget」是 2011-12-08 上架。
- 目前有 10 個安裝啟用數。
- 上一次更新是 2012-03-15,距離現在已有 4798 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
- 外掛最低要求 WordPress 2.8 以上版本才可以安裝。
- 尚未有人給過這款外掛評分。
- 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。
外掛協作開發者
外掛標籤
Hook | widget | sidebar | custom hook | development |
內容簡介
此外掛允許使用者在任何側邊欄中插入一個名為自己選擇的掛鉤(hook)。
該掛鉤可以是任何東西,可以是 WordPress 核心中現有的掛鉤(hook),也可以是外掛、主題或是您臨時想出的東西。一旦掛鉤存在,您的外掛、主題或 WordPress 核心就能夠使用該掛鉤來執行某些動作。
這個掛鉤能夠與其他更複雜的外掛結合使用,讓您能夠在側邊欄中觸發掛鉤(hook),也可以作為製作與主題代碼綁定的非常簡單的小工具的一個快速替代方案。例如,假設您的網站已經存在一個程式碼區塊,您希望它也能夠放置在側邊欄中,但並不想用一個小工具(widget)來包裝它(因為它完全和主題有關),那麼您可以將這個程式碼區塊都掛鉤(hook)到自訂的掛鉤(hook)中,然後使用 Simple Hook Widget 來放置側邊欄中的自訂掛鉤(hook)。
顯然,這並不是小工具(widget)開發的最佳方法,但也許在某些情況下,開發人員需要這樣一個選項。
更新2.0:
新增篩選器,允許開發人員指定可供選擇的掛鉤。
警告:請小心使用此外掛。如果您不是開發人員,且不知道「掛鉤(hooks)」是什麼,請勿使用此外掛。此外掛將允許您輸入任何掛鉤(hook),並在側邊欄中運行它-包括核心 WordPress 中載有可能導致站點問題的動作。
開發者注意事項:
如果未篩選「simple-hook-list」,Simple Hook Widget 將不會在小工具界面中顯示下拉選單,而是提供一個空白的文本框,允許用戶輸入任何他們喜歡的掛鉤(hook)。
在此外掛中使用掛鉤(hooks):
以下是一個簡單的使用 Simple Hook Widget 中的掛鉤(hooks) 的示例。就像在 WordPress 中使用其他掛鉤(hooks) 一樣。請記住,您可以在此處做任何您想做的事情,只需確保在 add_action() 中使用的掛鉤(hook) 名稱和特定小工具中選擇的掛鉤(hook) 名稱相同即可。
您可以通過編寫一個函數(function)並將其添加為掛鉤(hook)的動作來創建任意數量的不同小工具。這裡有一個與第一個示例類似的示例,但這是用來說明這一點的。
在 Simple Hook Widget 中創建預先決定的掛鉤(hooks) 的下拉選單:
版本2.0的 Simple Hook Widget 包括「simple-hook-list」篩選器,允許開發人員指定可從小工具管理面板中選擇的一組掛鉤。
您建立的函數應返回一個關聯數組,其中索引是實際掛鉤(hook)的名稱,值是在小工具面板上表示它的文本。
範例:
```function simple_hook_example_filter($hooks){
$hooks = array (
'example-hook-name-one' => 'Awesome Widget',
'example-hook-name-two' => 'Simple Widget'
);
return $hooks;
}
add_filter('simple-hook-list', 'simple_hook_example_filter');```
原文外掛簡介
This widget allows the user to insert a hook, with a name of their choosing, in any sidebar.
The hook can be anything, an existing hook from the WordPress Core, a plugin, a theme, or something you’ve come up with on the fly. Once the hook exists, your plugins, your theme, or the WordPress Core to make something happen with that hook.
This can be used in conjunction with other more complex plugins, to allow you to trigger a hook from the sidebar (yes, that is intentionally vague). It can also serve as a quick alternative to making very simple widgets tied to code from a theme. Say you have a chunk of code which already exists on your site, you’d like to also have it placed in a sidebar, but don’t want to make a widget out of it (since its entirely theme-centric). You could simply hook this chunk of code to a custom hook and use the Simple Hook Widget to place that custom hook in the sidebar.
This is clearly not the best method of widget development, but there may be times where such on option is useful to a developer in a pinch.
Update 2.0
New filter which allows developers to specify what hooks are available to choose from.
Warning: Use this plugin with care. If you are not a developer and don’t know what ‘hooks’ are, this plugin is not for you. This plugin will allow you to enter ANY hook, and will run it in the sidebar – that includes core WordPress loaded with actions that could result in problems for your site.
Developer Notes
IMPORTANT:
If the ‘simple-hook-list’ is not filtered, the Simple Hook Widget will not show a drop down in the widget interface, but instead it will provide an empty text field allowing a user to enter ANY hook they like.
Using the hooks
Here is a simple example of how to use a hook used in the Simple Hook Widget. Its just like using any other hook in WordPress. Remember, you can do whatever you want here, you just need to make sure the hook used in the add_action() is the same as the hook name selected in a particular widget.
Example #1:
function simple_hook_super_example() {
echo "This is my super simple hook widget";
}
add_action('example-hook-name-one', 'simple_hook_super_example');
You can create any number of different widgets by simply writing a function, and adding it as an action to a hook. Here is a similar one as the first, but this is here to illustrate the point.
Example #2:
function simple_hook_awesome_example() {
//Do whatever you want your 'widget' to do, when the 'example-hook-name-two' hook is chosen.
echo "This is my awesome simple hook widget";
}
add_action(‘example-hook-name-two’, ‘simple_hook_awesome_example’);
Creating dropdown of Pre-determined hooks
Filter: ‘simple-hook-list’
Version 2.0 of the Simple Hook Widget includes the 'simple-hook-list' filter which allows developers to specify a set of hooks which can be selected from the widgets admin panel.
The function you create should return an associative array where the index is the actual hook's name, and the value is the text that will represent it in the drop down on the widgets panel.
Example:
function simple_hook_example_filter($hooks){
$hooks = array (
‘example-hook-name-one’ => ‘Awesome Widget’,
‘example-hook-name-two’ => ‘Simple Widget’
);
return $hooks;
}
add_filter(‘simple-hook-list’, ‘simple_hook_example_filter’);
IMPORTANT:
If the ‘simple-hook-list’ is not filtered, the Simple Hook Widget will not show a drop down in the widget interface, but instead it will provide an empty text field allowing a user to enter ANY hook they like.
Hook: simple-hook-default
This hook allows developers provide a default value for the Simple Hook widget. By default, the default value for the hook, is an empty string.
Example:
function simple_hook_example_default($default_hook){
return ‘example-hook-name-two’;
}
`
Note: If filtering ‘simple-hook-list’ to create a drop down, the default value must match one of the keys in the array passed to the filter – otherwise this default will do nothing.
Hook: simplehookupdate_
This widget also contains an internal hook, which will be your hook, prefixed with simplehookupdate_. So if you use this plugin to create a hook name ‘testhook’, the widget, aside from creating the ‘testhook’ in the chosen sidebar location, will also create a hook called ‘simplehookupdate_testhook’. This hook occurs within the update method of the WP_Widget class, immediately before $instance is returned.
Not sure how useful this is, but a friend suggested it, so here is it.
各版本下載點
- 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
- 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Simple Hook Widget」來進行安裝。
(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。
延伸相關外掛(你可能也想知道)
Query Monitor – The developer tools panel for WordPress 》ministrator user). This cookie can be set by defining QM_AUTH_KEY in your wp-config.php file., To learn more about how to use Query Monitor, please...。
Yoast Test Helper 》此外掛能幫您測試 Yoast SEO、Yoast SEO 外掛和整合功能,並且方便地重置不同功能。同時,讓您可以設定資料庫版本,方便測試資料庫升級過程是否順利。, 功能,...。
What The File 》What The File 是一個 WordPress 外掛,在您的工具列中增加了一個選項,顯示目前正在檢視的頁面所使用的文件和模板部分。, 您可以通過單擊文件名直接使用佈景...。
P3 (Plugin Performance Profiler) 》這個外掛程式可以創建您 WordPress 網站的外掛程式效能概況,並且藉由測量這些外掛對網站載入時間的影響。通常WordPress網站由於過多或配置不佳的外掛程式而...。
Prevent Browser Caching 》您是一位前端開發人員嗎?想要清除所有使用者的瀏覽器快取嗎?只需啟用此外掛程式並展現您的作品!, Prevent Browser Caching 外掛程式可讓您自動或手動一鍵...。
Stop Emails 》這個 WordPress 外掛可以停止發送電子郵件。它可以停止由 WordPress 核心、外掛和佈景主題所產生的所有出站信件,使用 wp_mail() 函數發送的信件也會停止發送...。
WP Secure Maintenance 》想要將您的網站鎖定進行維護或開發嗎?那麼這就是正確的外掛程式。使用 WP Secure Maintenance,您可以使用密碼鎖定整個網站。, 功能:, , 設置密碼,以保護...。
Ultrapress 》lugins you need are not compatible with each other, which is why Ultrapress was developed. It is a suite of tools designed for WordPress developers...。
Monkeyman Rewrite Analyzer 》這是一個了解你的重寫規則(“美麗連結”)的工具。如果你正在添加或修改規則,並想要了解它們的運作方式(或者為什麼它們不起作用),這個工具是必不可少的。,...。
What Template 》在管理列中加入目前頁面的範本名稱。, 由於這個外掛揭露了關於啟用佈景主題的潛在敏感訊息,因此建議僅在開發環境下啟用,並不應在生產網站上啟用。。
Display Environment Type 》WordPress 5.5 引入了一種區分環境類型(開發、備試、正式)的方式。此外掛會在管理列顯示您網站的環境類型。, 更多有關此新功能的資訊。
Developer 》一個能幫助 WordPress 開發者進行開發的外掛。, 這個外掛將幫助您優化您的開發環境,確保您已安裝所有必要的工具和外掛。, 如果您想查看代碼並做出貢獻,加入...。
Cron View 》此外掛在管理面板中添加了一個頁面,您可以在其中查看所有排隊的 Cron 事件,了解它們的到期時間、所在的排程(或是否為一次性事件)以及它們將調用的鈎子。...。
WP PHP Console 》, PHP Console 讓你可以透過 Google Chrome 擴充元件 PHP Console 和 PHP Console 伺服器程式庫 處理 PHP 錯誤和例外、輸出變數、遠端執行 PHP 程式等等多種...。
WP Example Content 》這個外掛可以輕鬆地協助你設計和開發新的及現有佈景主題,加入或移除範例文章內容。享受它的便利!, 在啟用外掛後,只需進入管理面板導覽 (通常為最後一項),...。