diff --git a/src/Module/Acf.php b/src/Module/Acf.php index e51119e..2254e77 100644 --- a/src/Module/Acf.php +++ b/src/Module/Acf.php @@ -2,6 +2,8 @@ namespace Sober\Controller\Module; +use Sober\Controller\Utils; + class Acf { // Config @@ -32,6 +34,21 @@ private function setReturnFilter() : false); } + /** + * Recursively iterates over array and adds a new snake cased keys=>value for all kebab cased keys + * + * Return void + */ + private function recursiveSnakeCase(&$data) { + foreach ($data as $key => $val) { + if (is_array($val)) { + $this->recursiveSnakeCase($val); + } else { + $data[Utils::convertKebabCaseToSnakeCase($key)] = $val; + } + } + } + /** * Set Data Return Format * @@ -88,6 +105,8 @@ public function setData($acf) $this->data[$item] = get_field($item, $query); } } + + $this->recursiveSnakeCase($this->data); } /** diff --git a/src/Utils.php b/src/Utils.php index 2b7ca59..dffa60d 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -69,4 +69,15 @@ public static function convertToKebabCase($str) { return strtolower(preg_replace('/(?