PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.8.0
Import WP – CSV & XML Import Export for WordPress v2.8.0
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 / Plugin / Menu.php

Menu.php in Import WP – CSV & XML Import Export for WordPress 2.8.0, at class/Common/Plugin/Menu.php

198 lines 7.3 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\Plugin;
4
5 use ImportWP\Common\Exporter\Mapper\CommentMapper;
6 use ImportWP\Common\Exporter\Mapper\PostMapper;
7 use ImportWP\Common\Exporter\Mapper\TaxMapper;
8 use ImportWP\Common\Exporter\Mapper\UserMapper;
9 use ImportWP\Common\Importer\ImporterManager;
10 use ImportWP\Common\Importer\Template\TemplateManager;
11 use ImportWP\Common\Migration\Migrations;
12 use ImportWP\Common\Properties\Properties;
13 use ImportWP\Common\UI\ViewManager;
14
15 class Menu
16 {
17 /**
18 * @var Properties
19 */
20 private $properties;
21 /**
22 * @var ViewManager
23 */
24 private $view_manager;
25 /**
26 * @var ImporterManager
27 */
28 private $importer_manager;
29 /**
30 * @var TemplateManager $template_manager
31 */
32 private $template_manager;
33
34 public function __construct(Properties $properties, ViewManager $view_manager, ImporterManager $importer_manager, TemplateManager $template_manager)
35 {
36 $this->properties = $properties;
37 $this->view_manager = $view_manager;
38 $this->importer_manager = $importer_manager;
39 $this->template_manager = $template_manager;
40
41 add_action('admin_menu', array($this, 'register_tools_menu'));
42 add_action('tool_box', array($this->view_manager, 'tool_box'));
43 add_filter('plugin_action_links_' . $this->properties->plugin_basename, array($this, 'add_plugin_links'));
44 }
45
46 public function register_tools_menu()
47 {
48 $title = __('Import WP', $this->properties->plugin_domain);
49
50 $hook_suffix = add_management_page($title, $title, 'export', $this->properties->plugin_domain, array(
51 $this->view_manager,
52 'plugin_page'
53 ));
54
55 add_action('load-' . $hook_suffix, array($this, 'load_assets'));
56 }
57
58 public function add_plugin_links($links)
59 {
60 return array_merge(
61 [
62 '<a href="' .
63 admin_url('tools.php?page=' . $this->properties->plugin_domain) .
64 '">' . __('Dashboard', 'importwp') . '</a>',
65 '<a href="' .
66 admin_url('tools.php?page=' . $this->properties->plugin_domain . '&tab=settings') .
67 '">' . __('Settings', 'importwp') . '</a>',
68 ],
69 $links
70 );
71 }
72
73 public function load_assets()
74 {
75 $asset_file = include(plugin_dir_path($this->properties->plugin_file_path) . 'dist/index.asset.php');
76
77 wp_register_script($this->properties->plugin_domain . '-bundle', plugin_dir_url($this->properties->plugin_file_path) . 'dist/index.js', $asset_file['dependencies'], $asset_file['version'], 'all');
78
79 $matches = false;
80 preg_match('/^https?:\/\/[^\/]+(.*?)$/', admin_url('/tools.php?page=' . $this->properties->plugin_domain), $matches);
81 $ajax_base = $matches[1];
82
83 /**
84 * Generate template data
85 */
86 $templates = $this->importer_manager->get_templates();
87 $template_data = [];
88 foreach ($templates as $template_id => $template) {
89
90 $template_class = $this->template_manager->load_template($template);
91
92 $template_data[] = [
93 'id' => $template_id,
94 'label' => $template_class->get_name(),
95 'map' => [],
96 'settings' => $template_class->register_settings(),
97 'options' => $template_class->register_options(),
98 ];
99 }
100
101 $migrations = new Migrations();
102 $is_setup = $migrations->isSetup() ? 'yes' : 'no';
103
104 wp_localize_script($this->properties->plugin_domain . '-bundle', 'iwp', array(
105 'root' => esc_url_raw(rest_url()),
106 'nonce' => wp_create_nonce('wp_rest'),
107 'admin_base' => $ajax_base,
108 'ajax_base' => rest_url('/' . $this->properties->rest_namespace . '/' . $this->properties->rest_version),
109 'templates' => $template_data,
110 'is_setup' => $is_setup,
111 'plugin_url' => plugin_dir_url($this->properties->plugin_file_path),
112 'version' => $this->properties->plugin_version,
113 'encodings' => $this->properties->encodings,
114 'is_pro' => $this->properties->is_pro ? 'yes' : 'no',
115 'export_fields' => $this->get_export_fields(),
116 'registered_addons' => apply_filters('iwp/register_js', []),
117 'global_notices' => apply_filters('iwp/frontent/notices', [])
118 ));
119
120 wp_enqueue_script($this->properties->plugin_domain . '-bundle');
121
122 wp_enqueue_style($this->properties->plugin_domain . '-bundle-styles', plugin_dir_url($this->properties->plugin_file_path) . 'dist/index.css', array(), $asset_file['version'], 'all');
123
124 $this->load_help_tabs();
125
126 do_action('iwp/enqueue_assets');
127 }
128
129 private function get_export_fields()
130 {
131
132 $fields = array();
133 $comments = array();
134
135 $post_types = get_post_types();
136 foreach ($post_types as $post_type => $label) {
137 $mapper = new PostMapper($post_type);
138 $fields[] = array(
139 'id' => $post_type,
140 'label' => 'Post Type: ' . $label,
141 'fields' => $mapper->get_fields()
142 );
143
144 if (post_type_supports($post_type, 'comments')) {
145 $mapper = new CommentMapper($post_type);
146 $comments[] = array(
147 'id' => 'ewp_comment_' . $post_type,
148 'label' => 'Comments: ' . $label,
149 'fields' => $mapper->get_fields()
150 );
151 }
152 }
153
154 $fields = array_merge($fields, $comments);
155
156 $mapper = new UserMapper();
157 $fields[] = array(
158 'id' => 'user',
159 'label' => 'Users',
160 'fields' => $mapper->get_fields()
161 );
162
163 $taxonomies = get_taxonomies(array(), 'objects');
164 foreach ($taxonomies as $taxonomy) {
165 $mapper = new TaxMapper($taxonomy->name);
166 $fields[] = array(
167 'id' => 'ewp_tax_' . $taxonomy->name,
168 'label' => 'Taxonomy: ' . $taxonomy->labels->name,
169 'fields' => $mapper->get_fields()
170 );
171 }
172
173
174 $fields = apply_filters('iwp/exporter/export_field_list', $fields);
175
176 return $fields;
177 }
178
179 private function load_help_tabs()
180 {
181 $screen = get_current_screen();
182
183 $screen->add_help_tab(array(
184 'id' => 'iwp_help_tab',
185 'title' => __('Overview'),
186 'content' => '<p>' . __('Import WP allows you to import any XML or CSV file into WordPress posts, pages, users, categories and tags.', 'importwp') . '</p>',
187 ));
188
189 $screen->add_help_tab([
190 'id' => 'iwp_support_tab',
191 'title' => __('Plugin Support', 'importwp'),
192 'content' => '<p>' . __('Import WP has the following support:', 'importwp') . '</p>'
193 . '<p>' . __('<strong>Plugin documentation</strong> — Online documentation can be found at <a href="https://www.importwp.com/docs/?utm_campaign=support%2Bdocs&utm_source=Import%2BWP%2BFree&utm_medium=help%2Btab" target="_blank">https://www.importwp.com/docs/</a>', 'importwp') . '</p>'
194 . '<p>' . __('<strong>Support Tickets</strong> — Support requests are handled on our support system at <a href="https://helpdesk.importwp.com/" target="_blank">https://helpdesk.importwp.com/</a>', 'importwp') . '</p>',
195 ]);
196 }
197 }
198