• I know this is a topic that has been discussed a lot previously (e.g. here), but I still feel the topic needs clarification. I’m working on some formal documentation for this topic, so I’d really appreciate thorough and detailed responses.

    Firstly, since add_action() and add_filter() are really just referencing the same function (i.e. add_action() is just a wrapper around add_filter() ), doesn’t that mean that *any* time I have used add_action() in my plugins, I could just as easily replace it with add_filter()? I’ve tested this on a few plugins and their functionality seems unaffected. In other words, there is NO difference in execution, it’s merely a mnemonic distinction to give the developer a more memorable function name. Is that fair to say?

    The only difference I’m seeing is that hooks designated as “filters” are meant to tie to functions that actually return a value instead of just print it. e.g. consider the following ‘the_content’ hook:

    add_filter('the_content','my_function');
    function my_function($the_content) {
       return 'I am overwriting all content';
    }

    This plugin will override the content of all posts on the site. So… given a random hook, how can I tell if WP treats it as an action (where my functions don’t return a value) or if WP treats it like a filter (where my functions *must* return a value)?

    Secondly, can anyone provide an example of where add_action() or add_filter() uses the 4th parameter: accepted arguments?

    Is there any way to pass additional arguments to a function via the add_action() or add_filter() functions? E.g. imagine a simple function that prints out the time and a string identifier, e.g.
    print date() . ' was the time when '. $description . ' happened.';
    In such a case it would make sense to use the same function in all hooks, but simply pass a different description. Know what I mean?

    Thirdly, are the docs here: https://codex.www.ads-software.com/Plugin_API/Action_Reference and https://codex.www.ads-software.com/Plugin_API/Filter_Reference up to date with WP 3.0?

    Thanks for any input!

Viewing 1 replies (of 1 total)
  • Thread Starter fireproofsocks

    (@fireproofsocks)

    Ok, the lack of responses confirms my suspicions: that the distinction between actions and filters is murky at best, and that the WordPress architecture here is showing its age. I’ve noticed that some actions require additional arguments… it’s basically a clusterf*ck in there because there isn’t a firm grouping standard here:

    In a perfect world, there would be an event class, and actions, events, etc. would extend it in a logical fashion, but there doesn’t seem to be a defined list of what all the events are. Some are evidently hard-coded with unpredictable arguments…

    sigh… frustrated.

Viewing 1 replies (of 1 total)
  • The topic ‘Plugins vs. Filters Revisited’ is closed to new replies.