function generate_data_array() { $child_mods = Inherit_Theme_Mods::get_theme_mods_of($this->child_slug); $parent_mods = Inherit_Theme_Mods::get_theme_mods_of($this->parent_slug); $stored_mods = Inherit_Theme_Mods::get_stored_mods(); if (!$child_mods) { $child_mods = array(); } if (!$parent_mods) { $parent_mods = array(); } if (!$stored_mods) { $stored_mods = array(); } $keys = array_unique(array_merge(array_keys($child_mods), array_keys($parent_mods), array_keys($stored_mods))); // helper function function decorate_mod($key, $mods, $col) { $data_key = 'data-key="' . esc_attr($key) . '"'; $data_col = 'data-col="' . esc_attr($col) . '"'; if (!array_key_exists($key, $mods)) { return "<span class=\"ITM-list-data\" {$data_key} {$data_col}><small class=\"no-value\">" . __('(no value)', 'inherit-theme-mods') . '</small></span>'; } $value = esc_html(maybe_serialize($mods[$key])); $match_color = preg_match('/^#?([0-9,a-f,A-F]{3}|[0-9,a-f,A-F]{6})$/', $value); $match_inmageURL = preg_match('/\\.(jpg|jpeg|png|gif)$/i', $value); if (1 === $match_color) { # display color if color string $color_str = substr($value, 0, 1) === '#' ? $value : "#{$value}"; $style_attr = ITM_Util::style_attr(array('background-color' => $color_str)); # xss OK $value = esc_html($value); $value = "<div class=\"ITM-color-indication\" {$style_attr}></div><span class=\"ITM-list-data\" {$data_key} {$data_col}>{$value}</span>"; } else { if (1 === $match_inmageURL) { # display image if image url $value = esc_url($value); $value = "<img src=\"{$value}\" class=\"ITM-image-indication\" alt=\"\" /><br /><span class=\"ITM-list-data\" {$data_key} {$data_col}>{$value}</span>"; # xss OK } else { $value = "<span class=\"ITM-list-data ITM-serialized-text\" {$data_key} {$data_col}>" . esc_html($value) . '</span>'; } } return $value; } $result = array(); foreach ($keys as $key) { // Eliminate unnecessary field to see if (is_int($key)) { continue; } // transform slug into maybe translatable text // 'translate_word' -> 'Translate Word' // (is there any slugify/unslugify standard function?) $key_elements = explode('_', $key); foreach ($key_elements as $index => $element) { $key_elements[$index] = strtoupper(substr($element, 0, 1)) . substr($element, 1); } // try translate $key_parsed = ITM_Util::__chained(implode(' ', $key_elements), array($this->child_slug, $this->parent_slug, 'inherit-theme-mods', 'default')); array_push($result, array('Key' => $key_parsed, 'key' => $key_parsed, 'native_key' => $key, 'parent-theme' => decorate_mod($key, $parent_mods, 'parent-theme'), 'child-theme' => decorate_mod($key, $child_mods, 'child-theme'), 'trashed' => decorate_mod($key, $stored_mods, 'trashed'))); } $this->data = $result; }
function test_get_theme_mods_of_fails() { $this->assertFalse(Inherit_Theme_Mods::get_theme_mods_of('undefined-theme-slug')); }