Jason
Expert
Gunning for gold!
Member Likes (0)
Trying to create a foreach loop to loop through pre_site_options
(See code Below - Main question box doesn't have a code button)

Responses (8)
Member (joined November 2011) Likes (0)
The basic idea is that for each option name in the array, it will return the value for the option from the main site_id = 1
This works, as long as I don't put it in a loop. The problem with that is I have to create a new function for each item in the array, and that's not efficient or proper.
All my reading has told me I need to pass the variable using an apply_filter statement, but I (not for a lack of trying) cannot figure it out.
This is a working example of replacing a single option.
Member (joined November 2011) Likes (0)
BTW, the code preview formatted thing on this page, doesn't keep line numbers correct for long lines. There's a lot less code here than it looks like.
For example, that function in the bottom box is only two lines, not 5.
Support Kangaroo (joined March 2011) Likes (1)Liked by: 
Greetings Jason,
Thank you for this great question and a significant item to bring up.
I will certainly be passing this on to one of the lead developers/coders to look at for there invaluable input and advice for this project.
I will see if I can get one of them in here asap.
Cheers, Joe
Member (joined November 2011) Likes (0)
Maybe @Aaron or @Mason could chime in on this one?
Support Kangaroo (joined March 2011) Likes (1)Liked by: 
Greetings Jason,
As mentioned in my last post I would:
In which I have, as a matter of fact to Aaron.
Hopefully when making his rounds he will find the time to make it in here and address this custom coding without further ado.
Cheers, Joe
Developer (joined January 2012) Likes (1)Liked by: 
First order of business is that this filter doesn't exist in WP v3.4
http://adambrown.info/p/wp_hooks/hook/pre_site_option_%7B$key%7D
So I'd find another way to do it.
There's no way to tell from inside a common master function which option it came in from. You can't pass parameters in an add_filter(). If I really had to do it I might be able to construct anonymouse functions so that you could pass params in a stub.
Cludge though.
Or short stub functions
The in your loop create the filter function names the same way.
Member (joined November 2011) Likes (0)
@Arnold
Sorry, but it IS in WP 3.4
http://adambrown.info/p/wp_hooks/hook/pre_site_option_%7B$option%7D
You just happened to find the wrong reference, but that's ok, I won't hold it against ya!
(I did the same thing!)
I tried an anonymous function already and that didn't work.
HOWEVER!!!
TADA!
I found a work around, and it's working great! I used an empty class to hold the variable and created a new instance within the loop. Then I had my function use the variable from the class that was being reset in each new instance.
It reduced my file by hundreds of lines! (Literally)
Thank you for looking into it for me, it took me 3 weeks of research to figure it out. Now I know what to do anytime I need to loop through a filter that doesn't support parameters.
Member (joined November 2011) Likes (0)
BTW,
Thanks @Joe,
and @Arnold the only difference between the link you sent me, and I sent you was the $key vs $option. Since WP 2.9 they dropped the $key in favor of $option, but for some reason it's much further down the page.
I'm assuming key was a number and option is the name?
Become a member