add_action

函式
add_action ( $hook_name, $callback, $priority = 10, $accepted_args = 1 )
引數
  • (string) $hook_name The name of the action to add the callback to.
    Required:
  • (callable) $callback The callback to be run when the action is called.
    Required:
  • (int) $priority Optional. Used to specify the order in which the functions associated with a particular action are executed. Lower numbers correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action. Default 10.
    Required:
    Default: 10
  • (int) $accepted_args Optional. The number of arguments the function accepts. Default 1.
    Required:
    Default: 1
返回值
  • (true) Always returns true.
定義位置
相關方法
did_actiondo_actionhas_actionadd_optiondoing_action
引入
1.2.0
棄用
-

add_action: 這個函式用來向WordPress新增一個新的動作鉤。它被外掛和主題開發者用來在WordPress執行流程的特定點上執行自定義程式碼。

為動作鉤子新增回撥函式。

動作是WordPress核心在執行過程中的特定點,或在特定事件發生時啟動的鉤子。外掛可以指定在這些點上執行它的一個或多個PHP函式,使用行動API。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
return add_filter( $hook_name, $callback, $priority, $accepted_args );
}
function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) { return add_filter( $hook_name, $callback, $priority, $accepted_args ); }
function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
	return add_filter( $hook_name, $callback, $priority, $accepted_args );
}

常見問題

FAQs
檢視更多 >