WordPress:Function Reference/add filter

来自站长百科
Xxf3325讨论 | 贡献2008年7月19日 (六) 15:02的版本 (新页面: == 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...)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航、​ 搜索

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 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.

Usage

%%% <?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.

%%% <?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.

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.