2

I have successive hooks to an action which are passed an associative array like: do_action($array)

I am trying to update the values in this array in the multiple add_action calls, however each add_action is getting a copy of the passed array, not a reference.

How do I pass a reference? I am using PHP 5.

0

2 Answers 2

5

The way to pass by reference to a WP action is with: do_action_ref_array('action_hook', array(&$data) );

4

do_action which is hooked using add_action is not meant for altering values more then its meant for executing your function at a certain point. Instead use apply_filter which is hooked using add_filter which is meant to allow altering a value.

4
  • Thanks Bainternet, I'm working with a plugin so it's not possible to change add_action to add_filter without editing their core.
    – Boyster
    Commented Sep 13, 2012 at 8:01
  • In that case declare a global and modify its value instead of whats past to your hooked functions.
    – Bainternet
    Commented Sep 13, 2012 at 8:55
  • 1
    Haha why didn't I think of that? I'm always looking for a more complicated way to do things! :-/
    – Boyster
    Commented Sep 13, 2012 at 12:12
  • MUCH simpler! Thanks, I would never thought of that (no idea why... but I just wouldn't...)
    – frnhr
    Commented Apr 13, 2013 at 23:43

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