add_filter() 可以掛載一個函式到指定的過濾器上。
用法
|
1 |
add_filter($tag,$function_to_add,$priority,$accepted_args); |
引數
$tag
(字串)(必須) 所掛載的過濾器名字 (和目標 apply_filters() 函式的 $tag 屬性一樣) 。
預設值:None
$function_to_add
(回撥)(必須) 要掛載的回撥函式,參考 PHP 回撥函式型別檔案。
預設值:None
$priority
(整數)(可選) 執行順序,越小函式越先被執行。
預設值:10
$accepted_args
(整數)(可選) 回撥函式接收的引數數量,設定多個可以接收更多 apply_filters() 函式傳進來的引數。
預設值:1
返回值
(布林) 總是 True
例子
|
functiontest_func($text,$var1,$var2){ return$text.$var1.$var2; } add_filter('test','test_func',10,3); echoapply_filters('test','引數 2','引數 3','引數 4'); |
列印:
引數 2 引數 3 引數 4
更多參考:https://www.weixiaoduo.com/apply_filters/
其它
該函式位於:wp-includes/plugin.php
相關的函式:https://www.weixiaoduo.com/tag/hook