3

I would be grateful if someone could point out a link. I understand this may have a very lengthy answer but I searched and couldn't find any resource.

Alternatively, it would also be nice if someone can just state the order in which hooks are fired. I'm sure there wont be many since I am only concerned about the "published" posts.

Thanks in advance.

1 Answer 1

3

What exactly do you mean with "published"?

One thing you can try is this :

http://planetozh.com/blog/my-projects/wordpress-hooks-filter-flow/

The script runs in your WordPress root (or in /wp-admin/ if you prefer) and enumerates filters that are loaded in your blog. Hooks are displayed alphabetically, and for each hook, active filters (or actions, they’re the same) are listed in their execution order, which is either defined by their priority or by their loading order. The purpose of such a list is to help hunt plugin bugs down, and let you wisely fine-tune plugin priorities if needed.

Edit : I just found one promising looking plugin for this task : http://wordpress.org/extend/plugins/wordpress-hook-sniffer/

Alternativly you can change the /wp-includes/plugin.php file and log all hooks fired into log files. You then just have to "publish" a post and look which hooks has fired.

Following changes you have to made:

// in apply_filters(..)
$log = array();
do {
    foreach( (array) current($wp_filter[$tag]) as $the_ )
        if ( !is_null($the_['function']) ){
            $args[1] = $value;
            $log[] = $the_;
            $value = call_user_func_array($the_['function'], array_slice($args, 1, (int) $the_['accepted_args']));
        }
} while ( next($wp_filter[$tag]) !== false );
$filename = ABSPATH."/hooks.$tag.log"
file_put_contents($filename,file_get_contents($filename) ."\n". print_r($log,true));

// in apply_filters_ref_array(..)
$log = array();
do {
    foreach( (array) current($wp_filter[$tag]) as $the_ )
        $log[] = $the_;
        if ( !is_null($the_['function']) )
            $args[0] = call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

} while ( next($wp_filter[$tag]) !== false );
$filename = ABSPATH."/hooks.$tag.log"
file_put_contents($filename,file_get_contents($filename) ."\n". print_r($log,true));


// in do_action(..)
$log = array();
do {
    foreach ( (array) current($wp_filter[$tag]) as $the_ )
        $log[] = $the_;
        if ( !is_null($the_['function']) )
            call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

} while ( next($wp_filter[$tag]) !== false );
$filename = ABSPATH."/hooks.$tag.log"
file_put_contents($filename,file_get_contents($filename) ."\n". print_r($log,true));

// in do_action_ref_array(..)
$log = array();
do {
    foreach( (array) current($wp_filter[$tag]) as $the_ )
        $log[] = $the_;
        if ( !is_null($the_['function']) )
            call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args']));

} while ( next($wp_filter[$tag]) !== false );
$filename = ABSPATH."/hooks.$tag.log"
file_put_contents($filename,file_get_contents($filename) ."\n". print_r($log,true));
1
  • Thank You! This answers more than I asked and has been tremendous help... I hope if someone manages to stumble upon this, they wont regret it... btw.. what I actually wanted to find out is which hook is fired last when any post is posted in wordpress by clicking the publish button... so that i can add a function to it... this has been great help... I dont have enough experience points to give it a 1-up... sorry about that...
    – BAU
    Mar 29, 2012 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.