| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Importer\Template; |
| 4 |
|
| 5 |
use ImportWP\Common\Importer\ParsedData; |
| 6 |
use ImportWP\EventHandler; |
| 7 |
|
| 8 |
class PageTemplate extends PostTemplate |
| 9 |
{ |
| 10 |
protected $name = 'Page'; |
| 11 |
|
| 12 |
public function __construct(EventHandler $event_handler) |
| 13 |
{ |
| 14 |
parent::__construct($event_handler); |
| 15 |
$this->default_template_options['post_type'] = 'page'; |
| 16 |
} |
| 17 |
|
| 18 |
public function register() |
| 19 |
{ |
| 20 |
$groups = parent::register(); |
| 21 |
|
| 22 |
$templates = array('default' => 'Default Template'); |
| 23 |
$templates = array_merge($templates, wp_get_theme()->get_page_templates()); |
| 24 |
|
| 25 |
$template_list = []; |
| 26 |
foreach ($templates as $id => $name) { |
| 27 |
$template_list[] = ['value' => $id, 'label' => $name]; |
| 28 |
} |
| 29 |
|
| 30 |
$groups[0]['fields'][] = $this->register_field('Page Template', '_wp_page_template', [ |
| 31 |
'options' => $template_list, |
| 32 |
'options_default' => 'default', |
| 33 |
'tooltip' => __('Select a page template from your active theme', 'importwp') |
| 34 |
]); |
| 35 |
|
| 36 |
return $groups; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Process data before record is importer. |
| 41 |
* |
| 42 |
* Alter data that is passed to the mapper. |
| 43 |
* |
| 44 |
* @param ParsedData $data |
| 45 |
* @return ParsedData |
| 46 |
*/ |
| 47 |
public function pre_process(ParsedData $data) |
| 48 |
{ |
| 49 |
$this->field_map['_wp_page_template'] = 'post._wp_page_template'; |
| 50 |
|
| 51 |
if (true !== $this->importer->isEnabledField('post._wp_page_template')) { |
| 52 |
$temp = $data->getData(); |
| 53 |
unset($temp['post._wp_page_template']); |
| 54 |
$data->replace($temp); |
| 55 |
} |
| 56 |
|
| 57 |
return parent::pre_process($data); |
| 58 |
} |
| 59 |
} |
| 60 |
|