| @@ -10,8 +10,9 @@ | ||
| 10 | 10 | private $template_loops; |
| 11 | 11 | private $template_sections = []; |
| 12 | 12 | private $template_data = []; |
| 13 | 13 | private $i = -1; |
| 14 | + private $setup = false; | |
| 14 | 15 | |
| 15 | 16 | public function start() |
| 16 | 17 | { |
| 17 | 18 | // Generating a template, allows at a later date for custom templates to be added via user. |
| @@ -28,11 +29,28 @@ | ||
| 28 | 29 | fputs($this->fh, $this->template_sections['start'] . PHP_EOL); |
| 29 | 30 | |
| 30 | 31 | $data = $this->buildTemplateDataStructure([]); |
| 31 | 32 | $this->template_data = $data[0]; |
| 33 | + | |
| 34 | + update_option('iwp_exporter_xml_config', [ | |
| 35 | + 'template' => $this->template, | |
| 36 | + 'template_sections' => $this->template_sections, | |
| 37 | + 'template_data' => $this->template_data | |
| 38 | + ]); | |
| 32 | 39 | } |
| 33 | 40 | |
| 41 | + public function loadConfig() | |
| 42 | + { | |
| 34 | 43 | |
| 44 | + if (!$this->setup) { | |
| 45 | + $config = get_option('iwp_exporter_xml_config'); | |
| 46 | + $this->template = $config['template']; | |
| 47 | + $this->template_sections = $config['template_sections']; | |
| 48 | + $this->template_data = $config['template_data']; | |
| 49 | + $this->setup = true; | |
| 50 | + } | |
| 51 | + } | |
| 52 | + | |
| 35 | 53 | public function buildTemplateDataStructure($data) |
| 36 | 54 | { |
| 37 | 55 | $this->i++; |
| 38 | 56 | |
| @@ -225,8 +243,9 @@ | ||
| 225 | 243 | * @return void |
| 226 | 244 | */ |
| 227 | 245 | public function add($mapper) |
| 228 | 246 | { |
| 247 | + $this->loadConfig(); | |
| 229 | 248 | $output = $this->processLoop($this->template_data, $mapper); |
| 230 | 249 | fputs($this->fh, $output); |
| 231 | 250 | } |
| 232 | 251 | |
| @@ -298,8 +317,9 @@ | ||
| 298 | 317 | } |
| 299 | 318 | |
| 300 | 319 | public function end() |
| 301 | 320 | { |
| 321 | + $this->loadConfig(); | |
| 302 | 322 | fputs($this->fh, $this->template_sections['end'] . PHP_EOL); |
| 303 | 323 | fclose($this->fh); |
| 304 | 324 | } |
| 305 | 325 | |