問題描述
很多鈎子:
add_action('thesis_hook_after_comment', 'pj_time');
add_action('thesis_hook_after_comments', 'pj_time');
add_action('thesis_hook_after_comment_box', 'pj_time');
add_action('thesis_hook_after_comment_meta', 'pj_time');
add_action('thesis_hook_after_content', 'pj_time');
add_action('thesis_hook_after_content_area', 'pj_time');
add_action('thesis_hook_after_content_box', 'pj_time');
add_action('thesis_hook_after_footer', 'pj_time');
add_action('thesis_hook_after_header', 'pj_time');
add_action('thesis_hook_after_headline', 'pj_time');
// etc.
function pj_time()如何知道哪個鈎叫?是否有全局變量或告訴我哪個鈎子的東西? So pj_time() 可以輸出如下:「鈎子 (這裏的名字) 岩石」 。
我不知道掛鈎的命令,他們只是按字母順序在這裏。否則,我可以使用一個計數器來計算到目前為止我們已經做了多少鈎子,並以這種方式確定了鈎子的名稱。
所以我想知道是否可以獲取掛鈎的名稱。謝謝。
最佳解決方案
function pj_time () {
echo current_filter();
}
比我想的更容易;-)
http://codex.wordpress.org/Function_Reference/current_filter
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。