If you worked for even just a little while with WordPress, then you must know by now that action and filter hooks are the cornerstone of its extensibility. Through the Plugin API, and using functions such as add_action(), do_action(), add_filter() and apply_filters() we can build almost any thing we can think of on top of the core, often in the form of plugins and themes, but there are still problems that can appear when we implement them. One of these problems has to do with how much control we have over the functions and class methods that we add to actions and filters. Functions like do_action() and apply_filters() use call_user_func_array() internally, which is a native PHP function that allows to call a function (or class method) dynamically. The functions called using call_user_func_array() should be publicly accessible. That’s pretty obvious for functions, since they are always public and you can use them everywhere once they have been declared, but class methods need to be public too in order to work with call_user_func_array(). That shouldn’t be a problem by itself, but sometimes you may need some functions and methods to not be used outside of the scope of the action or filter
Share This