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.


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


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.

  • 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 Sep 13 '12 at 8:01
  • In that case declare a global and modify its value instead of whats past to your hooked functions. – Bainternet Sep 13 '12 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 Sep 13 '12 at 12:12
  • MUCH simpler! Thanks, I would never thought of that (no idea why... but I just wouldn't...) – frnhr Apr 13 '13 at 23:43

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