开发者

WordPress - add_filter vs apply_filters vs add_action vs do_action

开发者 https://www.devze.com 2023-03-13 05:31 出处:网络
What are the difference between add_filter, apply_filters, add_action and do_action? I can see that do_action puts a tag in the code which can then be used by add_action. However, I can\'t see how ad

What are the difference between add_filter, apply_filters, add_action and do_action?

I can see that do_action puts a tag in the code which can then be used by add_action. However, I can't see how add_filter and apply_filters correlate with this. One would think that there would be a do_filter which would add a tag to the code, much like do_action; but neither of these seem to do this. And neither of them have a simple form like do_action( $tag ), but instead require callback functions as paramete开发者_JS百科rs.


Filters in wordpress are used to modify text. So, for instance:

Stripping SQL statements from a block of text before putting it in the database to avoid injection attacks. That would be a filter.

Actions are functions that are called when wordpress does something. For instance, (from docs), emailing someone when a post is written.

http://codex.wordpress.org/Function_Reference/add_action

http://codex.wordpress.org/Function_Reference/add_filter

0

精彩评论

暂无评论...
验证码 换一张
取 消