1

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

1
  • 2
    It's helpful to search Google with the function name: add_action WordPress. Most functions are pretty well documented in the Codex. Feb 27, 2012 at 15:03

2 Answers 2

3

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

3
  • Ok nice, But what does this hook do?
    – Dr Deo
    Feb 27, 2012 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 Feb 27, 2012 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, 2012 at 6:59
2

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.

1
  • 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, 2012 at 15:13

Your Answer

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

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