WordPress:Function Reference/add filter

来自站长百科
Fludlen讨论 | 贡献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的函数。