Skip to content

Instantly share code, notes, and snippets.

@ocean90 ocean90/debug.php
Created Oct 12, 2011

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

bueltge commented Oct 13, 2011

Ich nutze dies hier: https://gist.github.com/1000143
und In debug objects (http://wordpress.org/extend/plugins/debug-objects/), schon älter, habe ich auch eine Ausleitung drin.
Vielleicht kannst du was verbessern, ergänzen.

@ocean90

This comment has been minimized.

Copy link
Owner Author

ocean90 commented Oct 13, 2011

Frank, dein Gist listet alle Hooks auf, meins nur die, wo zB Plugins sich eingeklinkt haben.

Debug Objects kommt da schon eher ran, hat aber den Fehler, dass Klassen Funktionen nicht angezeigt werden.

@bueltge

This comment has been minimized.

Copy link

bueltge commented Oct 13, 2011

ja, wobei ich das Plugin vorrangig zum Finden von Hooks nutze oder Schulungen
Debug Objects müsste man dann mal ergänzen; Zeit.

@bueltge

This comment has been minimized.

Copy link

bueltge commented Oct 15, 2011

Habe nochmal geschaut, Klassen sind drin; aber die Params der Funktionen nicht; die habe ich aus dem Array nicht geholt; kann ich mal nachholen.

@ocean90

This comment has been minimized.

Copy link
Owner Author

ocean90 commented Oct 15, 2011

Hab dir eine Mail geschickt. :)

@bueltge

This comment has been minimized.

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
You can’t perform that action at this time.