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

196 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 wp_register_script($this->properties->plugin_domain . '-bundle', plugin_dir_url($this->properties->plugin_file_path) . 'dist/base/js/bundle.js', array(), $this->properties->plugin_version, 'all');
76
77 $matches = false;
78 preg_match('/^https?:\/\/[^\/]+(.*?)$/', admin_url('/tools.php?page=' . $this->properties->plugin_domain), $matches);
79 $ajax_base = $matches[1];
80
81 /**
82 * Generate template data
83 */
84 $templates = $this->importer_manager->get_templates();
85 $template_data = [];
86 foreach ($templates as $template_id => $template) {
87
88 $template_class = $this->template_manager->load_template($template);
89
90 $template_data[] = [
91 'id' => $template_id,
92 'label' => $template_class->get_name(),
93 'map' => [],
94 'settings' => $template_class->register_settings(),
95 'options' => $template_class->register_options(),
96 ];
97 }
98
99 $migrations = new Migrations();
100 $is_setup = $migrations->isSetup() ? 'yes' : 'no';
101
102 wp_localize_script($this->properties->plugin_domain . '-bundle', 'iwp', array(
103 'root' => esc_url_raw(rest_url()),
104 'nonce' => wp_create_nonce('wp_rest'),
105 'admin_base' => $ajax_base,
106 'ajax_base' => rest_url('/' . $this->properties->rest_namespace . '/' . $this->properties->rest_version),
107 'templates' => $template_data,
108 'is_setup' => $is_setup,
109 'plugin_url' => plugin_dir_url($this->properties->plugin_file_path),
110 'version' => $this->properties->plugin_version,
111 'encodings' => $this->properties->encodings,
112 'is_pro' => $this->properties->is_pro ? 'yes' : 'no',
113 'export_fields' => $this->get_export_fields(),
114 'registered_addons' => apply_filters('iwp/register_js', []),
115 'global_notices' => apply_filters('iwp/frontent/notices', [])
116 ));
117
118 wp_enqueue_script($this->properties->plugin_domain . '-bundle');
119
120 wp_enqueue_style($this->properties->plugin_domain . '-bundle-styles', plugin_dir_url($this->properties->plugin_file_path) . 'dist/base/css/style.bundle.css', array(), $this->properties->plugin_version, 'all');
121
122 $this->load_help_tabs();
123
124 do_action('iwp/enqueue_assets');
125 }
126
127 private function get_export_fields()
128 {
129
130 $fields = array();
131 $comments = array();
132
133 $post_types = get_post_types();
134 foreach ($post_types as $post_type => $label) {
135 $mapper = new PostMapper($post_type);
136 $fields[] = array(
137 'id' => $post_type,
138 'label' => 'Post Type: ' . $label,
139 'fields' => $mapper->get_fields()
140 );
141
142 if (post_type_supports($post_type, 'comments')) {
143 $mapper = new CommentMapper($post_type);
144 $comments[] = array(
145 'id' => 'ewp_comment_' . $post_type,
146 'label' => 'Comments: ' . $label,
147 'fields' => $mapper->get_fields()
148 );
149 }
150 }
151
152 $fields = array_merge($fields, $comments);
153
154 $mapper = new UserMapper();
155 $fields[] = array(
156 'id' => 'user',
157 'label' => 'Users',
158 'fields' => $mapper->get_fields()
159 );
160
161 $taxonomies = get_taxonomies(array(), 'objects');
162 foreach ($taxonomies as $taxonomy) {
163 $mapper = new TaxMapper($taxonomy->name);
164 $fields[] = array(
165 'id' => 'ewp_tax_' . $taxonomy->name,
166 'label' => 'Taxonomy: ' . $taxonomy->labels->name,
167 'fields' => $mapper->get_fields()
168 );
169 }
170
171
172 $fields = apply_filters('iwp/exporter/export_field_list', $fields);
173
174 return $fields;
175 }
176
177 private function load_help_tabs()
178 {
179 $screen = get_current_screen();
180
181 $screen->add_help_tab(array(
182 'id' => 'iwp_help_tab',
183 'title' => __('Overview'),
184 'content' => '<p>' . __('Import WP allows you to import any XML or CSV file into WordPress posts, pages, users, categories and tags.', 'importwp') . '</p>',
185 ));
186
187 $screen->add_help_tab([
188 'id' => 'iwp_support_tab',
189 'title' => __('Plugin Support', 'importwp'),
190 'content' => '<p>' . __('Import WP has the following support:', 'importwp') . '</p>'
191 . '<p>' . __('<strong>Plugin documentation</strong> — Online documentation can be found at <a href="https://www.importwp.com/documentation/?utm_campaign=support%2Bdocs&utm_source=Import%2BWP%2BFree&utm_medium=help%2Btab" target="_blank">https://www.importwp.com/documentation/</a>', 'importwp') . '</p>'
192 . '<p>' . __('<strong>Support Tickets</strong> — Support requests are handled on our support system at <a href="https://support.jclabs.co.uk/" target="_blank">https://support.jclabs.co.uk/</a>', 'importwp') . '</p>',
193 ]);
194 }
195 }
196