Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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

share|improve this answer

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.

share|improve this answer
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
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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