Created
June 10, 2024 18:06
-
-
Save everaldomatias/ccf173e660d1c7104c526b2e80510ca2 to your computer and use it in GitHub Desktop.
WordPress log functions hooked
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_loaded', function() { | |
function list_hook_callbacks( $hook_name ) { | |
global $wp_filter; | |
if ( ! isset( $wp_filter[$hook_name] ) ) { | |
return []; | |
} | |
$hook = $wp_filter[$hook_name]; | |
if ( is_a( $hook, 'WP_Hook' ) ) { | |
return $hook->callbacks; | |
} elseif ( is_array( $hook ) ) { | |
return $hook; | |
} | |
return []; | |
} | |
// Listar todos os callbacks do hook 'the_posts' | |
$callbacks = list_hook_callbacks( 'the_posts' ); | |
if ( ! empty( $callbacks ) ) { | |
foreach ( $callbacks as $priority => $functions ) { | |
foreach ( $functions as $function ) { | |
if ( is_string( $function['function'] ) ) { | |
do_action( 'logger', "Hook 'the_posts' -> Função: " . $function['function'] ); | |
} elseif ( is_array( $function['function'] ) ) { | |
$class = is_object( $function['function'][0] ) ? get_class( $function['function'][0] ) : $function['function'][0]; | |
$method = $function['function'][1]; | |
do_action( 'logger', "Hook 'the_posts' -> Método: " . $class . "::" . $method ); | |
} elseif ( is_a( $function['function'], 'Closure' ) ) { | |
do_action( 'logger', "Hook 'the_posts' -> Função anônima" ); | |
} else { | |
do_action( 'logger', "Hook 'the_posts' -> Tipo desconhecido" ); | |
} | |
} | |
} | |
} else { | |
do_action( 'logger', "Hook 'the_posts' não possui callbacks registrados." ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment