wordpress中add_filter函数中的参数有什么用处

时间:2016-06-03 07:31:53

标签: wordpress

实际上我对下面提到的这个功能有点困惑。

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );

10,2在这个功能中的作用是什么。

2 个答案:

答案 0 :(得分:1)

(您的" 10")$ priority:(int)(可选)用于指定执行与特定操作关联的功能的顺序。较低的数字与先前的执行相对应,具有相同优先级的函数按照它们添加到操作的顺序执行。

Default value: 10

(你的" 2")$ accepted_args(int)(可选)函数接受的参数个数。

Default value: 1

Wordpress doc

答案 1 :(得分:0)

WordPress提供过滤器挂钩,允许插件在运行时修改各种类型的内部数据。 的语法

add_filter ( $tag, $function_to_add, $priority , $accepted_args);

<强> $代码

(string) (Required) The name of the filter to hook the $function_to_add callback to.

<强> $ function_to_add

(callable) (Required) The callback to be run when the filter is applied.

<强> $优先

(int) (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 value: 10

<强> $ accepted_args

(int) (Optional) The number of arguments the function accepts.

Default value: 1