All the additional arguments passed to do_action()
are passed as arguments, in order, to any hooked callback function. The callback functions can only choose how many of them to use, by setting the $accepted_args
parameter of add_action()
. They can’t choose which arguments to accept.
So you would need to do something like this:
add_action('myaction', 'my_multiplication', 20, 3); // Accept the first 3 arguments.
add_action('myaction', 'my_addition', 30, 4); // Accept the first 4 arguments.
add_action('myaction', 'my_division', 50, 6); // Accept the first 6 arguments.
function my_multiplication ($a, $b, $c) {
echo '' . $a . ' * ' . $b . ' * ' . $c . ' = ' . ($a * $b * $c) . '';
}
function my_addition ($a, $b, $c, $d = array()) {
$sum = 0;
echo '';
foreach ($d as $i => $val) {
$sum += $val;
echo ($i ? ' + ' : '') . $val;
}
echo ' = ' . $sum . '';
}
function my_division ($a, $b, $c, $d = array(), $e, $f) {
echo '' . $e . "https://wordpress.stackexchange.com/" . $f . ' = ' . ($e / $f) . '';
}
Note how my_addition()
needs to accept at least 4 arguments to get access to $d
, which contains the array, and my_division()
needs to accept all 6 arguments to get $e
and $f
, the last two numbers.