WordPress Filter debuggen
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 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 filtersglobal $wp_filter;if ( empty( $wp_filter ) )return false;// Check if custom tags are definedif ( ! 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 tagsforeach ( $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 nameprintf('<br /><strong>%s</strong><br />',esc_html( $tag ));// Sort by priorityksort( $data );foreach ( $data as $priority => $functions ) {// Print priority onceprintf('%s',$priority);// Go through each functionforeach ( $functions as $function ) {$_function = $function['function'];$_args = $function['accepted_args'];// Check function typeif ( is_array( $_function ) ) {// Object class callingif ( 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 argumentsprintf("t%s() (%s)<br />",esc_html( $name ),sprintf(_n('1 accepted argument','%s accepted arguments',$_args),$_args));}}}echo '</pre>';}

Mögliche Ausgabe der Funktion
Ein Dank geht an Andrey Savchenko für die Idee.
3 Kommentare zu WordPress Filter debuggen
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.