$priority parameter in the
register() method is intended to allow for prioritizing the order in which callbacks are run, however, this priority was effectively not used, so callbacks would be run in the order different priorities were registered, not ordered by the priorities.
This commit fixes this + adds a unit test to safeguard the fix.
I've elected to add the sorting to the
dispatch() method, rather than the
register() method for performance reasons.
Sorting arrays can be expensive and this way, only the subarrays of those hooks which are actually being run will be sorted, instead of sorting the subarray every time a new callback is registered, whether the hook on which the callback is registered will be called or not.