How to get (loop through to disable unnecessary) all functions with priority '1'
attached to hook 'wp_head'
('_wp_render_title_tag'
, 'wp_enqueue_scripts'
, 'noindex'
etc.)?
It is necessary to get it automatically, so that after each new version of WordPress do not keep track of whether the priority '1'
something else.
Something like:
$array_priority_1 = [];
if (doing_action('wp_head')) {
// Here we get and iterate over all functions related to 'wp_head'
// and immediately check their priority '1'?
// suitable and added to the array '$array_priority_1'
//
// ...I do not know how to get them and check for priority
}
And here we are going through our ready array:
foreach ($array_priority_1 as ...
Thank you!
The global $wp_filter
store the hooks and have also his arguments, include the priority. So you can create a small function to debug them. The follow function should helps to list all functions, his arguments if fired on wp_head
. The foreach loop add the priority of a hook via the run, the doing. So you can list all functions for the hook wp_head
with priority 10 as example via var_dump($hooked[0][10]);
.
add_action('all', function($hook) {
if (doing_action('wp_head')) {
global $wp_filter;
if ( ! isset( $wp_filter[ $hook ] ) ) {
return;
}
$hooked = (array) $wp_filter[ $hook ];
foreach ( $hooked as $priority => $function ) {
// Prevent buffer overflows of PHP_INT_MAX on array keys.
// So reset the array keys.
$hooked = array_values( $hooked );
$hooked[] = $function;
}
// Print all functions with priority `1`.
print '<pre>'; print_r($hooked[0][1]); print '</pre>';
}
return $hook;
});
Result
For my test example print all functions with priority 1
Array
(
[_wp_render_title_tag] => Array
(
[function] => _wp_render_title_tag
[accepted_args] => 1
)
[wp_enqueue_scripts] => Array
(
[function] => wp_enqueue_scripts
[accepted_args] => 1
)
[noindex] => Array
(
[function] => noindex
[accepted_args] => 1
)
[wp_post_preview_js] => Array
(
[function] => wp_post_preview_js
[accepted_args] => 1
)
)
Additional hint, source
Also this function inside a debug helper plugin should helps you to understand it – https://github.com/bueltge/debug-objects/blob/master/inc/class-page_hooks.php#L90