Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Show callbacks using `comment_text` or `get_comment_text` filters
// to be added in functions.php within the PHP tags
function spc_list_comment_filters() {
// exit if not on a page that show comments (the Comments page or Edit post/page screen)
global $pagenow;
if ( 'edit-comments.php' != $pagenow && 'post.php' != $pagenow ) {
return;
}
// get global variable containing list of registered filters
global $wp_filter;
// build string to be output
$output = '<div style="margin-left:160px; padding-bottom:60px; padding-left:20px;">';
$output .= '<h1>Show Parent Comment Debug Info</h1>';
// loop through each filter and output comment_text and get_comment_text
foreach ( $wp_filter as $key => $val ) {
if ( $key == 'comment_text' || $key == 'get_comment_text' ) {
$output .= "<h2>$key</h2><ul>";
// loop through each callback that access these filters and list their details
$callbacks = $val->callbacks;
foreach ( $callbacks as $key2 => $value2 ) {
$output .= "<li>add_action( '$key', '" . key($value2) . "', '" . $key2 . "', '" . $value2[key($value2)]['accepted_args'] . "');";
// let try to get the file where the function lives. Note only for functions, not classes (4.7 had changes so my old code won't work for classes)
try {
$ref = new ReflectionFunction( key($value2) );
$output .= " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Function defined in: " . $ref->getFileName();
}
catch ( Exception $e ) {
$output .= " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Function defined in: File name not available";
}
$output .= "</li>";
}
$output .= '</ul>';
}
}
// close the div and output the string
$output .= '</div>';
echo $output;
}
add_action( 'admin_footer', 'spc_list_comment_filters' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.