add_action & Hooks For Actions
- Posted by Beata on 三月 20th, 2006 filed in wordpress
所謂外掛外掛,WP的外掛何其之多,能讓一堆使用者為它開發出五花八門的外掛,完善的Plugin API 可說是功不可沒。
其中最具重要性的就屬 add_action 了。
add_action 函式可以讓你將自定義的函式「掛」在想要作用的區域,至於掛在哪兒?
WP 早就為我們準備好了各項「掛勾」以便讓我們掛上去這些自定義的函式。
下面的這些資料就是翻譯自官方幫助文件的「掛勾」清單。偷笑了一下
新增與移除
增加函式到目標對象 (把衣服掛上去)
add_action ("hook_name", "function_name", [ini priority], [ini accepted_args] );
從目標對象移除函式 (把衣服拿下來)
remove_action("hook_name", "function_name");
hook_name 自訂函式所要加入的掛勾名稱 再偷笑了一下
function_name 自訂函式名稱 (衣服)
priority 設定自訂函式的優先順序,預設為10級,亦即最後
accepted_args 自訂函式的引數個數
另外,也可以物件方式在add_action加入物件之method
class sample_class {
function sample_method($argument) {
..........................................
}
}
add_action(’hook’, array(’sample_class’, ’sample_method’));
或者
$the_class = new sample_class();
add_action(’hook’, array(&$the_class, ’sample_method’));
掛勾名列表….恩..知道我要說什麼吧!
格式:
掛勾 / 接收引數
掛勾所在的檔案
掛勾貼的位置 (作用區域)
admin_footer / 無
wp-admin\bookmarklet.php
後台管理頁面最下方</body>之前
admin_head / 無
wp-admin\admin-header.php
後台管理頁面最上方<head>之內
admin_menu / 無
wp-admin\menu.php
除了九大分類以外的管理選單
comment_closed / comment’s post ID
wp-comments-post.php
當迴響關閉時
comment_form / comment’s post ID
在迴響留言表單即將結束之前加上 html tag
comment_id_not_found / comment’s post ID
wp-content\themes\classic\comments-popup.php
當迴響表單沒有相對應的文章時
comment_post / comment’s post ID
wp-includes\comment-functions.php
當迴響已經由wp-comments.php發出時
delete_comment / comment’s post ID
wp-admin\post.php
當刪除一篇迴響時
delete_post / post ID
wp-includes\functions-post.php
當刪除一篇文章時
edit_comment / comment’s post ID
wp-includes\comment-functions.php
編輯迴響時
edit_form_advanced / 無
wp-admin\edit-form-advanced.php
後台文章進階編輯表單,位於 textarea 之後 div 之內
edit_page_form / 無
wp-admin\edit-page-form.php
後台網頁編輯表單,整個form區域之內
edit_post / post ID
wp-includes\functions-post.php
文章編輯時
generate_rewrite_rules / 無
wp-includes\classes.php
rewrite_rules 重新設定時
init / 無
WP載入完成,但未有任何header送出時,常用於擷取 $_GET、$_POST
pingback_post / comment’s post ID
wp-settings.php
當經由 X M L R P C 發送迴響時
private_to_published / post ID
wp-includes\functions-post.php
當文章狀態由「私人」改為「公開」時
publish_phone / post ID
wp-mail.php
當經由 wp-mail.php 發佈文章時
publish_post / post ID
wp-includes\functions-post.php
當文章已儲存且狀態為「公開」時
save_post / post ID
wp-includes\functions-post.php
當文章已存進資料庫時
shutdown / 無
wp-settings.php
當網頁輸出完成時
simple_edit_form / 無
wp-admin\edit-form.php
同 edit_form_advanced,不過是加在小的編輯表單中
switch_theme / 目前所使用的佈景名稱
wp-admin\admin-functions.php
當Blog佈景更改時
template_redirect / 無
wp-includes\template-loader.php
在佈景載入之前執行
trackback_post / comment ID
wp-trackback.php
當迴響是經由 trackback.php 所發送時
wp_footer / 無
wp-includes\functions.php
在</body>標籤之前執行
wp_head / 無
wp-includes\functions.php
在<head>標籤之內執行
wp_meta / 無
wp-includes\template-functions-general.php
依照預設的佈景主題而言,就是sidebar.php之 meta() 所產生的區塊
wp_set_comment_status / comment ID
wp-includes\comment-functions.php
當文章的迴響狀態改變時(但我還不太瞭解運作方式…)
十一月 13th, 2006 at 12:52 下午
Leggo ed imparo sul vostro luogo. grazie!
十二月 6th, 2006 at 2:14 下午
ymjncicuig…
agcgyyjsr fwpommechd ygzqmmbctk sslpkevowa …
七月 5th, 2007 at 6:34 上午
[...] 懶懶喵之add_action & Hooks For Actions [...]