Savvy WordPress user here, or at least trying to be. I have the hang of hooks and filters with the code in WP’s plugin.php
The only thing I cannot seem to understand is the $merged_filters global. The value for a tag is unset when a filter or action is added.
However, when an action or filter is executed, the $merged_filters[$tag] value is set to “true”.
What is the purpose of this?
Thank you
1 Answer
For those of you who may be wondering what this does – I have figured it out.
When a new function is added to an action/filter hook, it is added at the end of the array. However, WordPress specifies that those functions are to be executed by priority.
When a function is added, merged_filters is used to keep track of whether functions for a hook have been sorted by priority or not. merged_filters is checked on do_action/apply_filters to determine whether the functions should be sorted (by priority) or not before the hook is executed