So I'm using WordPress for this project, and I'm not quite sure how to go about this neat & clean.
I've got 8 options total. If ANY of them are set, I need something to happen. I also need to execute it for each one set.
Let's use two, for now
if( (genesis_get_option('setting_one', 'settings') || genesis_get_option('setting_two', 'settings')) !== '')
{ // print() each one that is set }
You can see how doing it that way for 8 options would get very ugly very quickly. All of my settings all have an identical prefix: (setting_a
, setting_b
, setting_one
,setting_two
)
I was thinking something like
$settings = array_fill(1, 8, 'setting_');
$labels = array(1 => 'a', 'b', 'c', 'd', 'one', 'two', 'three', 'four');
.... but then I don't know where to go from there.
There's GOT to be some sort of clean way to do this?
A somewhat neater way would be:
$settings = array("setting_one","setting_two","setting_a");
$has_setting = false;
foreach($settings as $setting){
if(genesis_get_option($setting, 'settings') !== ''){
$has_setting = true;
break;
}
}
if($has_setting){
//Do stuff
}
Even better would be putting the check into a method to keep the code neater.
Edit: Just realised you need an action for each setting. In that case you can do it inside the loop.
if(false !== array_search(true,
array_map(
'genesis_get_option',
array('setting_one', 'setting_to' /* ... */ ),
array('value_one', 'value_two' /* ... */)
)
)) { /* ... */ }