Action Hooks versus Filter hooks - I'm confused (4 posts)

  1. rizman
    Posted 6 years ago #

    Hi there,
    I'm currently starting WP plugin development. I'm a reasonable programmer although I've never worked with PHP before. Only .NET related technology.

    But there just seems to be something I don't get in WP. What's the difference between Action hooks and filter hooks?

    When I look at the source for apply_action in plugin.php, I'm really confused as add_action just calls add_filter. So why the difference?

    function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
    	return add_filter($tag, $function_to_add, $priority, $accepted_args);

    I figured it might be used for backwards compatibility due to legacy code? If that is the case, what should be used today i.e. what is the recommended way to hook functions?

  2. rizman
    Posted 6 years ago #

    No one there who can clarify this? I'm sure others might be interested in the difference too. Or I'm just plain stupid. That's another possibility :-)

  3. kharisma
    Posted 6 years ago #

    I guess you will have figured it out by now, since 2 months have passed.

    Adding a filter is the same as adding an action (hence the code is identical). The difference is in how they are processed once they are called (do_action and apply_filters).

    Filters are given a seed, and each successive filter for the same hook processes the result of the previous one.

    Actions work independently of each other. Each one does what they want with the parameters (if any) they are passed.

  4. Joost
    Posted 6 years ago #

    As far as I understand it, filters really alter the information, while actions just take the information, "take action", but don't actually change it.

Topic Closed

This topic has been closed to new replies.

About this Topic