public function transform($fields) { return array_map(function ($control) { $value = array_key_exists('value', $control) ? $control['value'] : ''; if (is_string($value) && startsWith($value, '@')) { $option = str_replace('@', '', $value); $pieces = explode(".", $option); if (count($pieces) == 2) { $options = \Onepager::getOption($pieces[0]); if (is_array($options) && array_key_exists($pieces[1], $options)) { $control['value'] = $options[$pieces[1]]; } else { $control['value'] = ""; } } else { $control['value'] = \Onepager::getOption($option); } } //obligatory name $name = array_key_exists('name', $control) ? $control['name'] : ""; //optional $type = isset($control['type']) ? $control['type'] : "text"; switch ($type) { case 'divider': $default = array('label' => 'divider'); break; case 'note': $default = array('text' => 'note'); break; case 'link': $default = array('value' => array('url' => array_get($control, 'url', ''), 'text' => array_get($control, 'url', ''), 'target' => array_get($control, 'url', false))); break; case 'repeater': $control['fields'] = array_map(function ($control) { return $this->transform($control); }, $control['fields']); $default = array("label" => ucfirst($name), "type" => "repeater", "class" => "{$name}-control", "help" => "", "fields" => array()); break; default: $default = array("placeholder" => ucfirst($name), "label" => ucfirst($name), "type" => $type, "class" => "{$name}-control", "help" => "", "value" => ''); //because react-bootstrap expects addonAfter //append is just a syntactical sugar if (array_key_exists('append', $control)) { $default['addonAfter'] = $control['append']; } //because react-bootstrap expects addonBefore //prepend is just a syntactiacal sugar if (array_key_exists('prepend', $control)) { $default['addonBefore'] = $control['prepend']; } } $control = array_merge($default, $control); return $control; }, $fields); }
Onepager::addPresets("default", array(['primary' => 'red', 'secondary' => 'yellow'], ['primary' => 'green', 'secondary' => 'yellow'])); Onepager::addPresets("default", array(['primary' => 'blue', 'secondary' => 'yellow'], ['primary' => 'green', 'secondary' => 'yellow', 'a1' => 'pink', 'a2' => 'red'])); add_action('wp_head', function () { // Favicion echo '<link rel="icon" href="' . Onepager::getOption('favicon') . '">'; // Google Analytics echo Onepager::getOption('google_analytics'); // Full pager if (Onepager::getOption('full_screen')) { echo '<script> jQuery(document).ready(function() { jQuery(".op-sections").fullpage({ sectionSelector: ".op-section", css3: true, scrollingSpeed: 100, scrollBar: true }); }); </script>'; } }); if (Onepager::getOption('full_screen')) { add_action('wp_enqueue_scripts', function () { $q = onepager()->asset(); // Full page // $q->script( 'op-easings', asset( 'assets/js/jquery.easings.min.js' ) ); $q->script('op-slimscroll', asset('assets/js/jquery.slimscroll.min.js')); $q->script('op-fullpage', asset('assets/js/jquery.fullPage.js')); $q->style('op-fullpage', asset('assets/css/jquery.fullPage.css')); }); }