Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am reading the source of a plugin (gallery to slideshow plugin) to make it behave like i want and it is using an action

add_action( 'the_posts', array( &$this, 'have_gallery' ), 10, 1 );

I want to know what those extra parameters (10,1) mean but i cant find the documentation of this action. Please help

share|improve this question
2  
It's helpful to search Google with the function name: add_action WordPress. Most functions are pretty well documented in the Codex. –  Brian Fegter Feb 27 '12 at 15:03

2 Answers 2

up vote 3 down vote accepted

those parameters aren't unique to the_posts, they're parameters for the add_action() function

add_action( $tag, $function_to_add, $priority, $accepted_args ); 

the 10 is just the default priority and 1 is the default number of accepted arguments. since they're both default, you don't really need either.

http://codex.wordpress.org/Function_Reference/add_action

share|improve this answer
    
Ok nice, But what does this hook do? –  Dr Deo Feb 27 '12 at 15:08
    
did you check the codex? add_action adds a function to a wordpress action. so your plugin is telling wordpress to run its 'have_gallery' function when wordpress runs the the_posts() action –  helgatheviking Feb 27 '12 at 16:52
    
By the way, if you check the source for add_action, you'll see it uses ksort on the plugin event array per each event. This means that negative values are possible and will sort higher than zero. PHP5 will let you create a key with the max negative value of -1410065407. So, if you hook the init event with that priority, it will likely be the first event ever run. Just remember that if you don't need that early of a priority, go with something in the 10+ range. In my case, I needed it to build a plugin to block bad spiders. –  Volomike May 2 '12 at 6:59

This is rather add_action() related.

add_action( 
   'the_posts', //$tag
   array( &$this, 'have_gallery' ), //$function_to_add
   10, //$priority - run priority, when to execute given action 
   1 //$accepted_args - number of accepted arguments, one in this case
);

10 means default run priority and 1 stands for one argument that this function takes.

share|improve this answer
    
Thanks for the Quick response. But i wonder how on earth the plugin writer came across this hook and used it without documentation. –  Dr Deo Feb 27 '12 at 15:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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