function seek_options($haystack, $needles) { // function to return ALL VALUES of a same key from a multidimensional array - mostly used to insert default values in DB at theme init $found = ''; foreach ($haystack as $key => $value) { $seek = FALSE; if ($key === $needles) { $result = $value . " "; //delimiter for implode latter used if (array_key_exists('font_changer', $haystack) && !empty($haystack['font_changer'])) { $result .= $value . " " . $value . "_font "; } if (array_key_exists('color_changer', $haystack) && !empty($haystack['color_changer'])) { $result .= $value . " " . $value . "_color "; } if (array_key_exists('font_size_changer', $haystack) && !empty($haystack['font_size_changer'])) { $result .= $value . " " . $value . "_size "; } if (array_key_exists('icons', $haystack) && !empty($haystack['icons'])) { $result .= $value . " " . $value . "_icon "; } return $result; } elseif (is_array($value)) { $seek = seek_options($value, $needles); if (!empty($seek) && $seek != '') { $found .= $seek; } } } if (!empty($found)) { return $found; } else { return FALSE; } }
function theme_options_defaults() { $my_var_that_holds_options = get_option(THEME_OPTIONS); //getting theme options from DB , if no options FALSE returned if (!$my_var_that_holds_options) { //checking if no theme options where setup (first time use of theme) $result = seek_options($this->admin_options, 'id'); //getting all fields with key = 'id' from theme options array $ids = explode(' ', trim($result)); foreach ($ids as $id) { //building defaults as '' $defaults[$id] = ''; } update_option(THEME_OPTIONS, $defaults); //Inserting defaults to DB } }