Skip to content

Instantly share code, notes, and snippets.

@ocean90
Created October 12, 2011 21:29
Show Gist options
  • Save ocean90/1282691 to your computer and use it in GitHub Desktop.
Save ocean90/1282691 to your computer and use it in GitHub Desktop.
WordPress function to debug WordPress filters
<?php
/**
* Debug WordPress filters.
*
* Use add_action( 'shutdown', 'ds_debug_filters' ) to display all used
* filters with the functions hooked into the filter.
*
* @author Dominik Schilling
* @license GPLv2
* @link http://wpgrafie.de/262/
*
* @version 0.1.1
*
* Changelog:
* Version 0.1.1 - Fixed string for more then 1 accepted arguments.
*
*/
function ds_debug_filters( $custom_tags = array() ) {
// $wp_filter Stores all of the filters
global $wp_filter;
if ( empty( $wp_filter ) )
return false;
// Check if custom tags are defined
if ( ! empty( $custom_tags ) ) {
// Check if custom tags are available
$tags = array_intersect( array_keys( $wp_filter), (array) $custom_tags );
if ( empty( $tags ) )
return false;
// Fill custom tags
foreach ( $tags as $tag )
$_wp_filter[$tag] = $wp_filter[$tag];
} else {
// Use default tags
$_wp_filter = $wp_filter;
}
echo '<pre id="wp-debug-filters">';
// Uncomment, if you want to sort by name of the filter hooks
// ksort( $_wp_filter );
foreach ( $_wp_filter as $tag => $data ) {
// Print tag name
printf(
'<br /><strong>%s</strong><br />',
esc_html( $tag )
);
// Sort by priority
ksort( $data );
foreach ( $data as $priority => $functions ) {
// Print priority once
printf(
'%s',
$priority
);
// Go through each function
foreach ( $functions as $function ) {
$_function = $function['function'];
$_args = $function['accepted_args'];
// Check function type
if ( is_array( $_function ) ) {
// Object class calling
if ( is_object( $_function[0] ) )
$class = get_class( $_function[0] );
else
$class = $_function[0];
$name = $class . '::' . $_function[1];
} else {
// Static calling
$name = $_function;
}
// Print function name and number of accepted arguments
printf(
"\t%s() (%s)<br />",
esc_html( $name ),
sprintf(
_n(
'1 accepted argument',
'%s accepted arguments',
$_args
),
$_args
)
);
}
}
}
echo '</pre>';
}
@bueltge
Copy link

bueltge commented Oct 19, 2011

Hi Dominik,
sorry, bin landunter, daher noch keine Antwort; bin in jedem Fall dankbar!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment