Site icon Hip-Hop Website Design and Development

How to call do_action() to pass arguments to hooked functions that take different number of args?

Here is a simple example to explain my question. 3 functions are hooked into the myaction. Each take a different number of args and the args can be a number of an array of numbers. So args can also be different data type.


add_action('myaction', 'my_multiplication', 20, 3);
add_action('myaction', 'my_addition', 30, 1);
add_action('myaction', 'my_division', 50, 2);

function my_addition ($a = array()) {
    $sum = 0;
    echo '

'; foreach ($a as $i => $val) { $sum += $val; echo ($i ? ' + ' : '') . $val; } echo ' = ' . $sum . '

'; } function my_multiplication ($a, $b, $c) { echo '

' . $a . ' * ' . $b . ' * ' . $c . ' = ' . ($a * $b * $c) . '

'; } function my_division ($a, $b) { echo '

' . $a . ' / ' . $b . ' = ' . ($a / $b) . '

'; }

How do I make a do_action call to run the 3 hooked function?
Here was what I tried, which did not work. I want 2, 3, 4 be passed for multiplication, array(11, 22, 33) for addition, and 60, 20 for division.


do_action('myaction', 2, 3, 4, array(11, 22, 33), 60, 20);