WordPress: Function Reference/add filter:修订间差异

来自站长百科
跳转至: 导航、​ 搜索
(新页面: == Description == Hooks a function to a specific filter action. Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending...)
 
无编辑摘要
第1行: 第1行:
== Description ==
== Description ==
== 描述==
Hooks a function to a specific filter action.
Hooks a function to a specific filter action.
将一个函数hook到一个特别的filter action。


Filters are the hooks that WordPress launches to modify text of various types  before adding it to the database or sending it to the browser screen. Plugins  can specify that one or more of its PHP functions is executed to  modify specific types of text at these times, using the Filter API.  See the [[WordPress:Plugin API]] for a list of filter hooks.
Filters are the hooks that WordPress launches to modify text of various types  before adding it to the database or sending it to the browser screen. Plugins  can specify that one or more of its PHP functions is executed to  modify specific types of text at these times, using the Filter API.  See the [[WordPress:Plugin API]] for a list of filter hooks.


Filters是WordPress发行的hooks,用来更改不同类型的文本,再将这些文本添加到数据库或者发送到浏览器屏面。这是,插件可以指定一个或者更多的PHP函数使用Filter API,更改特别类型的文本。请看看[[WordPress:Plugin API|插件API]]上关于filter hooks的一个列表。
== Usage ==
== Usage ==
== 用法 ==
%%% <?php add_filter($tag,  $function_to_add,  $priority = 10,  $accepted_args = 1); ?> %%%
%%% <?php add_filter($tag,  $function_to_add,  $priority = 10,  $accepted_args = 1); ?> %%%
%%% <?php add_filter($tag,  $function_to_add,  $priority = 10,  $accepted_args = 1); ?> %%%


== Parameters ==
== Parameters ==
== 参数 ==
{{Parameter|$tag|string|The name of the filter to hook the <tt>$function_to_add</tt> to.}}
{{Parameter|$tag|string|The name of the filter to hook the <tt>$function_to_add</tt> to.}}
{{Parameter|$tag|string|The name of the filter to hook the <tt>$function_to_add</tt> to.}}
{{Parameter|$function_to_add|callback|The name of the function to be called when the filter is [[WordPress:Function Reference/apply_filters|applied]].}}
{{Parameter|$function_to_add|callback|The name of the function to be called when the filter is [[WordPress:Function Reference/apply_filters|applied]].}}
{{Parameter|$function_to_add|callback|当[[WordPress:Function Reference/apply_filters|应用]]filter的时候,调用的函数名。}}
{{Parameter|$priority|integer|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.|option|10}}
{{Parameter|$priority|integer|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.|option|10}}
{{Parameter|$priority|integer|用来指定,函数与一个特别的action相联合时的属性。较小的数字代表执行地较早,拥有同等优先级的函数的执行属性与它们添加到action上的顺序相同。|option|10}}
{{Parameter|$accepted_args|integer|The number of arguments the function(s) accept(s). In WordPress 1.5.1 and newer. hooked functions can take extra arguments that are set when  the matching do_action() or apply_filters() call is run.}}
{{Parameter|$accepted_args|integer|The number of arguments the function(s) accept(s). In WordPress 1.5.1 and newer. hooked functions can take extra arguments that are set when  the matching do_action() or apply_filters() call is run.}}
{{Parameter|$accepted_args|integer|函数接受的参数的数目。在WordPress1.5.1版本以及更新的版本中。Hooked函数可以得到matching do_action() or apply_filters() call 运行时,设置的额外的参数。}}


You may need to supply a pointer to the function's namespace for some filter callbacks, e.g.  
You may need to supply a pointer to the function's namespace for some filter callbacks, e.g.  
你可能要为同样的filter callbacks提供pointer指向函数的名字空间。
%%% <?add_filter('media_upload_newtab', array(&$this, 'media_upload_mycallback'));?> %%%


%%% <?add_filter('media_upload_newtab', array(&$this, 'media_upload_mycallback'));?> %%%
%%% <?add_filter('media_upload_newtab', array(&$this, 'media_upload_mycallback'));?> %%%


Otherwise WordPress looks in its own namespace for the function, which can cause abnormal behaviour.
Otherwise WordPress looks in its own namespace for the function, which can cause abnormal behaviour.
否则,WordPress会在自身名字空间查找函数,会导致不正常的操作。


== Return ==  
== Return ==  
== 返回 ==
<tt>true</tt> if the <tt>$function_to_add</tt> is added successfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment.
<tt>true</tt> if the <tt>$function_to_add</tt> is added successfully to filter <tt>$tag</tt>. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching <tt>do_action()</tt> or <tt>apply_filters()</tt> call is run. For example, the action <tt>comment_id_not_found</tt> will pass any functions that hook onto it the ID of the requested comment.
如果<tt>$function_to_add</tt>成功地加到了filter <tt>$tag</tt>上,返回<tt>正确的</tt>。你的函数拥有多少个参数。在WordPress1.5.1+,hooked函数拥有matching <tt>do_action()</tt> 或者<tt>apply_filters()</tt> call运行时,设置的额外的函数。例如,action <tt>comment_id_not_found</tt>会传递任何hook onto需要的评论ID的函数。

2008年7月21日 (一) 14:28的版本

Description

描述

Hooks a function to a specific filter action. 将一个函数hook到一个特别的filter action。

Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Plugins can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API. See the WordPress:Plugin API for a list of filter hooks.

Filters是WordPress发行的hooks,用来更改不同类型的文本,再将这些文本添加到数据库或者发送到浏览器屏面。这是,插件可以指定一个或者更多的PHP函数使用Filter API,更改特别类型的文本。请看看插件API上关于filter hooks的一个列表。

Usage

用法

%%% <?php add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1); ?> %%%

%%% <?php add_filter($tag, $function_to_add, $priority = 10, $accepted_args = 1); ?> %%%

Parameters

参数

You may need to supply a pointer to the function's namespace for some filter callbacks, e.g.

你可能要为同样的filter callbacks提供pointer指向函数的名字空间。

%%% <?add_filter('media_upload_newtab', array(&$this, 'media_upload_mycallback'));?> %%%

%%% <?add_filter('media_upload_newtab', array(&$this, 'media_upload_mycallback'));?> %%%

Otherwise WordPress looks in its own namespace for the function, which can cause abnormal behaviour.

否则,WordPress会在自身名字空间查找函数,会导致不正常的操作。

Return

返回

true if the $function_to_add is added successfully to filter $tag. How many arguments your function takes. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. For example, the action comment_id_not_found will pass any functions that hook onto it the ID of the requested comment.

如果$function_to_add成功地加到了filter $tag上,返回正确的。你的函数拥有多少个参数。在WordPress1.5.1+,hooked函数拥有matching do_action() 或者apply_filters() call运行时,设置的额外的函数。例如,action comment_id_not_found会传递任何hook onto需要的评论ID的函数。