PluginProbe
Import WP – CSV & XML Import Export for WordPress / 2.8.3
Import WP – CSV & XML Import Export for WordPress v2.8.3
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.3, at class/Common/Plugin/Menu.php

200 lines 7.5 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 $unique_fields = $this->template_manager->get_template_unique_fields($template_class);
92
93 $template_data[] = [
94 'id' => $template_id,
95 'label' => $template_class->get_name(),
96 'map' => [],
97 'settings' => $template_class->register_settings(),
98 'options' => $template_class->register_options(),
99 'unique_fields' => $unique_fields
100 ];
101 }
102
103 $migrations = new Migrations();
104 $is_setup = $migrations->isSetup() ? 'yes' : 'no';
105
106 wp_localize_script($this->properties->plugin_domain . '-bundle', 'iwp', array(
107 'root' => esc_url_raw(rest_url()),
108 'nonce' => wp_create_nonce('wp_rest'),
109 'admin_base' => $ajax_base,
110 'ajax_base' => rest_url('/' . $this->properties->rest_namespace . '/' . $this->properties->rest_version),
111 'templates' => $template_data,
112 'is_setup' => $is_setup,
113 'plugin_url' => plugin_dir_url($this->properties->plugin_file_path),
114 'version' => $this->properties->plugin_version,
115 'encodings' => $this->properties->encodings,
116 'is_pro' => $this->properties->is_pro ? 'yes' : 'no',
117 'export_fields' => $this->get_export_fields(),
118 'registered_addons' => apply_filters('iwp/register_js', []),
119 'global_notices' => apply_filters('iwp/frontent/notices', [])
120 ));
121
122 wp_enqueue_script($this->properties->plugin_domain . '-bundle');
123
124 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');
125
126 $this->load_help_tabs();
127
128 do_action('iwp/enqueue_assets');
129 }
130
131 private function get_export_fields()
132 {
133
134 $fields = array();
135 $comments = array();
136
137 $post_types = get_post_types();
138 foreach ($post_types as $post_type => $label) {
139 $mapper = new PostMapper($post_type);
140 $fields[] = array(
141 'id' => $post_type,
142 'label' => 'Post Type: ' . $label,
143 'fields' => $mapper->get_fields()
144 );
145
146 if (post_type_supports($post_type, 'comments')) {
147 $mapper = new CommentMapper($post_type);
148 $comments[] = array(
149 'id' => 'ewp_comment_' . $post_type,
150 'label' => 'Comments: ' . $label,
151 'fields' => $mapper->get_fields()
152 );
153 }
154 }
155
156 $fields = array_merge($fields, $comments);
157
158 $mapper = new UserMapper();
159 $fields[] = array(
160 'id' => 'user',
161 'label' => 'Users',
162 'fields' => $mapper->get_fields()
163 );
164
165 $taxonomies = get_taxonomies(array(), 'objects');
166 foreach ($taxonomies as $taxonomy) {
167 $mapper = new TaxMapper($taxonomy->name);
168 $fields[] = array(
169 'id' => 'ewp_tax_' . $taxonomy->name,
170 'label' => 'Taxonomy: ' . $taxonomy->labels->name,
171 'fields' => $mapper->get_fields()
172 );
173 }
174
175
176 $fields = apply_filters('iwp/exporter/export_field_list', $fields);
177
178 return $fields;
179 }
180
181 private function load_help_tabs()
182 {
183 $screen = get_current_screen();
184
185 $screen->add_help_tab(array(
186 'id' => 'iwp_help_tab',
187 'title' => __('Overview'),
188 'content' => '<p>' . __('Import WP allows you to import any XML or CSV file into WordPress posts, pages, users, categories and tags.', 'importwp') . '</p>',
189 ));
190
191 $screen->add_help_tab([
192 'id' => 'iwp_support_tab',
193 'title' => __('Plugin Support', 'importwp'),
194 'content' => '<p>' . __('Import WP has the following support:', 'importwp') . '</p>'
195 . '<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>'
196 . '<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>',
197 ]);
198 }
199 }
200