Join Carrie Dils for an in-depth discussion in this video WP_Hook vs. $wp_filter, part of Advanced WordPress: Action and Filter Hooks.
- [Instructor] In the past, all of the hooks in the Plugin API and any callback functions hooked to them were stored in a global variable called wp_filter, as an array. A very big one, at that. The problem was that if you had a recursive callback, which is a function that calls itself from within itself, or a callback that changed other hooked callbacks already running on an action or filter, you could get some really crazy, unanticipated results. In WordPress 4.7, the WP_Hook class was introduced to address the issue.
Here's the original WordPress Core Development ticket, where the issue with wp_filter was first mentioned. And you can see that it was quite a while back and only recently has WordPress introduced a major code refactoring to handle how hooks are dealt with. Now, WordPress Core Development has always been vigilant about maintaining backward compatibility, so coming up with a new solution that wouldn't break a lot of old code was critical. Really, the only people who were directly impacted by this change were plugin developers, who were accessing wp_filter directly, rather than using the Plugin API.
Basically, they were kind of doing a no-no. So, you probably know at this point whether you were affected, but just in case, here's an article outlining how you can bring your code up to date. The cause of WP_Hook class was such a big change in WordPress, I wanted to mention it in this course, but really, your main takeaway should be this: the overwhelming majority of the time, you won't need to access either WP_Hook or wp_filter. Just use the Plugin API. If you want to dig in more on the topic, here's a really great article from the folks over at Delicious Brains.
- Actions and filters explained
- Identifying available hooks and filters
- Looking at load order
- Understanding callback functions
- Creating custom hooks
- Using third-party hooks
- Building a new WordPress plugin with filters and actions