can I do something like that? to pass arguments to my function? I already studied add_action doc but did not figure out how to do it. What the exact syntax to pass two arguments would look like. In particular how to pass text & integer arguments.
function recent_post_by_author($author,$number_of_posts) {
some commands;
}
add_action('thesis_hook_before_post','recent_post_by_author',10,'author,2')
UPDATE
it seems to me that it is done somehow through do_action but how? :-)
I've wrote wordpress plugin long time ago, but I went to Wordpress Codex and I think that's possible: http://codex.wordpress.org/Function_Reference/add_action
I think you should pass them as an array. Look under examples "take arguments".
Bye
I use closure for PHP 5.3+. I can then pass the default values and mine without globals. (example for add_filter)
Instead of:
it should be:
...where 2 is the number of arguments and 10 is the priority in which the function will be executed. You don't list your arguments in add_action. This initially tripped me up. Your function then looks like this:
Both the add_action and function go in functions.php and you specify your arguments in the template file (page.php for example) with do_action like so:
Hope this helps.
I have made a code to send parameters and process.
I ran into the same issue and solved it by using global variables. Like so:
A bit sloppy but it works.
Yes you can! The trick really is in what type of function you pass to add_action and what you expect from do_action.
We can do it with a closure.
Here is a simplified example of a closure working
Anonymous vs. Closure
Proxy Function Class
Example Usage #1
Example Usage #2