PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.7.1
Import WP – CSV & XML Import Export for WordPress v2.7.1
2.15.1 2.15.0 2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 All 144 releases
jc-importer / class / Common / Importer / Template / PageTemplate.php

PageTemplate.php in Import WP – CSV & XML Import Export for WordPress 2.7.1, at class/Common/Importer/Template/PageTemplate.php

60 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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