Closed bobbingwide closed 4 years ago
In the first iteration I simply added the count. Then I decided to add a parameter so you could decide if the hook shortcode is generated when there are no implementers of the hook. Note: There are some times when you need to know about ALL hooks and other times when you need to know about the most used and their implementing functions.
I then changed some of the calls ( "most used" and "by hook name" ) which were using bw_trace() to bw_trace_create_hook_links(). "Most used" only logs the output when there are implementing functions.
The format of the hook shortcode is documented at https://www.oik-plugins.com/wordpress-plugins-from-oik-plugins/free-oik-plugins/oik-trace-plugin/settings-oik-action-options/action-options-options/count-action-hooks-and-filters/
[hook option_siteurl filter 2 111 1]
Trace attached hook functions
logic.Note: It's possible that some filter functions don't cater for all the parameters passed to it.
In this example the attached function was _config_wp_siteurl()
.
This only expects one parameter. But two are passed by get_option()
.
wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(344:0) bw_trace_parms(1) 5 0 2019-12-11T15:07:07+00:00 0.012678 0.005378 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 parameters: 2: Array ( [0] => https://s.b/wordpress [1] => siteurl )
wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(525:0) bw_trace_attached_hooks(1) 6 0 2019-12-11T15:07:07+00:00 0.012890 0.000212 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 option_siteurl : 0 bw_trace_parms;9 bw_trace_attached_hooks;9 bw_trace_backtrace;9 : 10 _config_wp_siteurl;1 wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(609:0) bw_trace_backtrace(1) 7 0 2019-12-11T15:07:07+00:00 0.013051 0.000161 cf=option_siteurl 48 4 0 2097152/2097152 256M F=193 2 Array ( [0] => https://s.b/wordpress [1] => siteurl )
I'm not going to add the above Comments to the documentation just yet. It could be a FAQ asking "Why doesn't the Number of args passed
match the number of parameters expected?"
The [hook] links shortcodes generated by oik-bwtrace action count logic, shows how many times a hook is invoked. If we're trying to improve performance we need some idea how many functions are registered against each hook.
Proposed solution
Alter
bw_trace_get_hook_links()
to invoke a new function calledbw_trace_get_attached_hook_count()
, which will provide a simple count of the attached hooks. Note: This will show the hooks attached at shutdown. It's probably good enough for the time being.