Created
April 13, 2017 03:22
-
-
Save Stephen-Cronin/4059c6d308c1847ba700182fa195cf4f to your computer and use it in GitHub Desktop.
Show callbacks using `comment_text` or `get_comment_text` filters
This file contains 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
// 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 .= " Function defined in: " . $ref->getFileName(); | |
} | |
catch ( Exception $e ) { | |
$output .= " 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