Comment savoir quelles fonctions sont accrochées à une action / filtre?
-
-
Je suis sûr que celafait ce que vous voulez: [@ Rarst's Debug WordPress hooks] (http://www.rarst.net/script/debug-wordpress-hooks/)I'm pretty sure that this does what you want: [@Rarst's Debug WordPress hooks](http://www.rarst.net/script/debug-wordpress-hooks/)
- 0
- 2011-05-16
- anu
-
jetez un œil à [** cette réponse **] (http://wordpress.stackexchange.com/questions/307/where-can-i-find-a-list-of-wordpress-hooks/339#339)pourune question similaireet plusprécisément leplugin qui yestpostéparmike.take a look at [**this answer**](http://wordpress.stackexchange.com/questions/307/where-can-i-find-a-list-of-wordpress-hooks/339#339) to a similar question and more specifically the plugin posted there by mike.
- 0
- 2011-05-16
- Bainternet
-
Jepeuxme tromper,mais celane produit-ilpas simplement une liste complète des crochets?Lafaçon dontje lis la questionest qu'il veut savoir quellesfonctions sont attachées au crochet.I could be wrong, but doesn't that just produce a comprehensive list of hooks? The way I'm reading the question is the he wants to know what functions are attached to the hook.
- 1
- 2011-05-16
- anu
-
Partiellementfaux,il a dit "parexemple ce quiest accroché à wp_head",donc c'est une liste complèteet pas seulement un seul hook.Partially wrong, he said "for example what's hooked to wp_head", so its a full list not only a single hook.
- 0
- 2011-05-16
- Bainternet
-
Eneffet,je voulais voir quellesfonctions sont attachées à un hookparticulier,doncparexemple,si 10fonctions sont accrochées à `wp_head`,j'aimeraisen lister 10.Indeed, I wanted to see what functions are attached to a particular hook, so for example if 10 functions are hooked to `wp_head` then I'd like to list those 10.
- 0
- 2011-05-16
- Javier Villanueva
-
ehbien,ceplugin listeratoutes lesfonctions qui y sont accrochées.well that plugin will list all functions that are hooked with there hook.
- 0
- 2011-05-16
- Bainternet
-
je suistombé sur ceplugin quiest assezgénialpour ce https://wordpress.org/plugins/simply-show-hooks/just stumbled across this plugin which is pretty great for this https://wordpress.org/plugins/simply-show-hooks/
- 0
- 2016-01-14
- Bryan Willis
-
Pour contribuer - dans ce domaine,cen'estpastrès convivial d'utiliser lesinformations de hooks collectées,et spécialementpas sur «wp_head».Lemoyen leplusproche (expliqué)est l'extrait de code: fonction list_hooks ($ hook='') ... trouvé à: https://stackoverflow.com/a/26680808/2445357 Celafonctionne àpartir de 2018et a étégénialpour cetype de solutions.Voustrouverez des hooks dans desplugins,des classeset des objetsimbriquéset les comptereztous!Ou une listefacile où résident lesfonctions,etc.To contribute - in this matter, its not so very friendly to use the collected hooks information, and specially not on 'wp_head'. The closest correct way (explained) is the snippet: function list_hooks($hook = '') ... found at : https://stackoverflow.com/a/26680808/2445357 That works as of 2018 and been awsome for this kind of solutions. You will found hooks from plugins, classes and nestled object and count them all! Or easy list where the functions resident etc etc.
- 0
- 2018-06-09
- Jonas Lundman
-
6 réponses
- votes
-
- 2011-05-16
Regardez dans la variableglobale
$wp_filter
. Voirmon pluginpour une liste detous lesfiltres de commentaires pour unexemple:<?php /* Plugin Name: List Comment Filters Description: List all comment filters on wp_footer Version: 1.1 Author: Fuxia Scholz License: GPL v2 */ add_action( 'wp_footer', 'list_comment_filters' ); function list_comment_filters() { global $wp_filter; $comment_filters = array (); $h1 = '<h1>Current Comment Filters</h1>'; $out = ''; $toc = '<ul>'; foreach ( $wp_filter as $key => $val ) { if ( FALSE !== strpos( $key, 'comment' ) ) { $comment_filters[$key][] = var_export( $val, TRUE ); } } foreach ( $comment_filters as $name => $arr_vals ) { $out .= "<h2 id=$name>$name</h2><pre>" . implode( "\n\n", $arr_vals ) . '</pre>'; $toc .= "<li><a href='#$name'>$name</a></li>"; } print "$h1$toc</ul>$out"; }
Exemple de sortiepour
pre_comment_author_email
:array ( 10 => array ( 'trim' => array ( 'function' => 'trim', 'accepted_args' => 1, ), 'sanitize_email' => array ( 'function' => 'sanitize_email', 'accepted_args' => 1, ), 'wp_filter_kses' => array ( 'function' => 'wp_filter_kses', 'accepted_args' => 1, ), ), )
Look into the global variable
$wp_filter
. See my plugin for a list of all comment filters for an example:<?php /* Plugin Name: List Comment Filters Description: List all comment filters on wp_footer Version: 1.1 Author: Fuxia Scholz License: GPL v2 */ add_action( 'wp_footer', 'list_comment_filters' ); function list_comment_filters() { global $wp_filter; $comment_filters = array (); $h1 = '<h1>Current Comment Filters</h1>'; $out = ''; $toc = '<ul>'; foreach ( $wp_filter as $key => $val ) { if ( FALSE !== strpos( $key, 'comment' ) ) { $comment_filters[$key][] = var_export( $val, TRUE ); } } foreach ( $comment_filters as $name => $arr_vals ) { $out .= "<h2 id=$name>$name</h2><pre>" . implode( "\n\n", $arr_vals ) . '</pre>'; $toc .= "<li><a href='#$name'>$name</a></li>"; } print "$h1$toc</ul>$out"; }
Sample output for
pre_comment_author_email
:array ( 10 => array ( 'trim' => array ( 'function' => 'trim', 'accepted_args' => 1, ), 'sanitize_email' => array ( 'function' => 'sanitize_email', 'accepted_args' => 1, ), 'wp_filter_kses' => array ( 'function' => 'wp_filter_kses', 'accepted_args' => 1, ), ), )
-
- 2016-02-03
pour voir la liste desfonctions ou actions liées à un hook d'actionparticulier,vouspouvez utiliser le code suivant.
global $wp_filter; echo '<pre>'; var_dump( $wp_filter['wp_head'] ); echo '</pre>';
to see list of functions or actions hooked to a particular action hook you can use the following code.
global $wp_filter; echo '<pre>'; var_dump( $wp_filter['wp_head'] ); echo '</pre>';
-
- 2015-12-09
À desfins de débogage,un
global $wp_filter; echo "<pre>" . print_r($wp_filter, true) . "</pre>";
leferait ...
For debug-purposes a simple
global $wp_filter; echo "<pre>" . print_r($wp_filter, true) . "</pre>";
would do it ...
-
Dansmon cas,appeler `var_dump ($ wp_filter)`produisaittrop de sortie.J'aipréféré utiliser `var_dump ($ wp_filter ["
"])`.(Ilen va demêmepour `print_r` -j'aipersonnellementpréféré var_dump.) In my case, calling `var_dump($wp_filter)` produced too much output. I preferred using `var_dump($wp_filter[""])`. (Same goes for `print_r` - I personally preferred var_dump.) - 2
- 2017-06-17
- Acsor
-
- 2016-04-15
Cecimontre une liste defiltresplus lisible
function print_filters_for( $hook = '' ) { global $wp_filter; if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) return; $ret=''; foreach($wp_filter[$hook] as $priority => $realhook){ foreach($realhook as $hook_k => $hook_v){ $hook_echo=(is_array($hook_v['function'])?get_class($hook_v['function'][0]).':'.$hook_v['function'][1]:$hook_v['function']); $ret.= "\n$priority $hook_echo"; } } return $ret; }
This shows a more readable list of filters
function print_filters_for( $hook = '' ) { global $wp_filter; if( empty( $hook ) || !isset( $wp_filter[$hook] ) ) return; $ret=''; foreach($wp_filter[$hook] as $priority => $realhook){ foreach($realhook as $hook_k => $hook_v){ $hook_echo=(is_array($hook_v['function'])?get_class($hook_v['function'][0]).':'.$hook_v['function'][1]:$hook_v['function']); $ret.= "\n$priority $hook_echo"; } } return $ret; }
-
- 2017-02-21
J'aitrouvé la réponse de @Simone G utile,maisellen'apasprisen compte lefait queparfois lesfermeturespeuvent être accrochées.Voicima version laplus verbeuse (et laide):
if( isset($wp_filter[$filterName]) ){ foreach( $wp_filter[$filterName] as $priority => $hooks){ foreach ($hooks as $hook_k => $hook_v) { $hook_echo=(is_array($hook_v['function'])?get_class($hook_v['function'][0]).':'.$hook_v['function'][1]:$hook_v['function']); if(is_object($hook_echo) && ($hook_echo instanceof Closure)){ $hook_echo="closure"; } error_log($filterName." HOOKED (".serialize($priority)."): ".serialize($hook_k)."".serialize($hook_echo)); } } } else { error_log($filterName." NO FILTERS HOOKED"); }
I found the answer from @Simone G useful, but it didn't take into account the fact, that sometimes Closures can be hooked. Here's my more verbose (and ugly) version:
if( isset($wp_filter[$filterName]) ){ foreach( $wp_filter[$filterName] as $priority => $hooks){ foreach ($hooks as $hook_k => $hook_v) { $hook_echo=(is_array($hook_v['function'])?get_class($hook_v['function'][0]).':'.$hook_v['function'][1]:$hook_v['function']); if(is_object($hook_echo) && ($hook_echo instanceof Closure)){ $hook_echo="closure"; } error_log($filterName." HOOKED (".serialize($priority)."): ".serialize($hook_k)."".serialize($hook_echo)); } } } else { error_log($filterName." NO FILTERS HOOKED"); }
-
- 2020-06-23
Celame faitgagner dutemps carje peux voir directement dansn'importe quellepage https://wordpress.org/plugins/show-hooks/
It saves my time because I can see direcly in any page https://wordpress.org/plugins/show-hooks/
Existe-t-il unmoyen de savoir quellesfonctions sont liées à un hookparticulier?Parexemple,sije souhaite savoir quellesfonctions sont liées au hook
wp_head
.