bobbingwide / oik-bwtrace

debug trace for WordPress
https://www.oik-plugins.com/oik-plugins/oik-bwtrace-debug-trace-for-wordpress/
GNU General Public License v2.0
6 stars 1 forks source link

bw_trace_get_attached_hook_count() incorrect since WordPress 4.7 #64

Closed bobbingwide closed 6 years ago

bobbingwide commented 6 years ago

Since WordPress 4.7.0 filters and hooks are now stored in the global $wp_filter as instances of class WP_hook. The logic used to determine how many functions are attached to a particular hook is no longer working. In the [hook] shortcode generated at trace shutdown we just get 0's.

Expected output

[hook the_content filter 1 1 16]
[hook get_the_excerpt filter 2 1 3]
[hook the_excerpt filter 1 1 7]

Actual output

[hook the_content filter 1 1 0]
[hook get_the_excerpt filter 2 1 0]
[hook the_excerpt filter 1 1 0]

Proposed solution

We now need to count the items in the $hook->callbacks property. The code need not be backward compatible with earlier versions of WordPress.

Further information

The same value for the number of attached functions should be shown when the hook is displayed in context e.g.

[hook replace_editor;admin_enqueue_scripts;the_content filter 1 1 16]

The meanings of the three numeric values in the [hook] shortcode are:

  1. Parameter count
  2. Number of invocations
  3. Number of attached functions
[hook gettext filter 3 4818 1]
[hook map_meta_cap filter 4 328 1]
[hook user_has_cap filter 4 328 2]

The [hook] shortcode is provided by https://github.com/bobbingwide/oik-shortcodes and was used in the https://github.com/bobbingwide/oik-requests prototype plugin.