WordPress hat viele Filter, wo sich Entwickler einklinken können. Durch einen Filter ist es möglich, bestimmte Daten vor der Ausgabe zu filtern.
Manchmal ist es dann interessant zu wissen, welche Funktion welchen Ausgabe filtert.Dafür habe ich mir folgende Funktion geschrieben, welche jeder gerne benutzen und weiter entwickeln darf.
<?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 https://dominikschilling.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>';
}

Ein Dank geht an Andrey Savchenko für die Idee.
Siehe auch “Instrument Hooks for WordPress” von Mike Schinkel auf Github. Ist sehr ähnlich und vor allem sehr nützlich.
Hi Dominik,
ich möchte kurz auf ein Gist von Frank verweisen, in dem er das Problem sehr schon gelöst hat!
https://gist.github.com/1000143
Alternativ dazu steht mein Gist, mit einer Brute-Force-Methode bereit.
https://gist.github.com/1077658
Vielspaß René
@Ralf und Rene,
danke für eure Kommentare. Das von Frank bzw Mike (wer hats nun entwickelt?) kannte ich.
Allerdings gibt es einen Unterschied. Meine Version listet nur die Filter auf, auf welche auch zugegriffen wird. Die Version von Frank/Mike listet alle Filter auf, die zur Verfügung stehen.
Rene, deine Version ist aber böse.
Hi Herr Schilling … vielen Dank auch an Rene,
auch wenn der Beitrag ein wenig älter erscheint ist die Problematik bei älteren Blogs noch von Nöten. Egal ob Frank oder Mike der erste war, geholfen hats mir jedenfalls schon alle Filter mal gelistet zu bekommen und den Focus darauf zu setzen.
Nochmals herzlichen Dank!
Gruß
DonDon