4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Administration |
6 * @subpackage Administration |
7 */ |
7 */ |
8 |
8 |
9 define('WP_LOAD_IMPORTERS', true); |
9 define( 'WP_LOAD_IMPORTERS', true ); |
10 |
10 |
11 /** Load WordPress Bootstrap */ |
11 /** Load WordPress Bootstrap */ |
12 require_once( dirname( __FILE__ ) . '/admin.php' ); |
12 require_once( dirname( __FILE__ ) . '/admin.php' ); |
13 |
13 |
14 if ( ! current_user_can( 'import' ) ) { |
14 if ( ! current_user_can( 'import' ) ) { |
15 wp_die( __( 'Sorry, you are not allowed to import content.' ) ); |
15 wp_die( __( 'Sorry, you are not allowed to import content.' ) ); |
16 } |
16 } |
17 |
17 |
18 $title = __('Import'); |
18 $title = __( 'Import' ); |
19 |
19 |
20 get_current_screen()->add_help_tab( array( |
20 get_current_screen()->add_help_tab( |
21 'id' => 'overview', |
21 array( |
22 'title' => __('Overview'), |
22 'id' => 'overview', |
23 'content' => '<p>' . __('This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.') . '</p>' . |
23 'title' => __( 'Overview' ), |
24 '<p>' . __('In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.') . '</p>', |
24 'content' => '<p>' . __( 'This screen lists links to plugins to import data from blogging/content management platforms. Choose the platform you want to import from, and click Install Now when you are prompted in the popup window. If your platform is not listed, click the link to search the plugin directory for other importer plugins to see if there is one for your platform.' ) . '</p>' . |
25 ) ); |
25 '<p>' . __( 'In previous versions of WordPress, all importers were built-in. They have been turned into plugins since most people only use them once or infrequently.' ) . '</p>', |
|
26 ) |
|
27 ); |
26 |
28 |
27 get_current_screen()->set_help_sidebar( |
29 get_current_screen()->set_help_sidebar( |
28 '<p><strong>' . __('For more information:') . '</strong></p>' . |
30 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
29 '<p>' . __('<a href="https://codex.wordpress.org/Tools_Import_Screen">Documentation on Import</a>') . '</p>' . |
31 '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Import_Screen">Documentation on Import</a>' ) . '</p>' . |
30 '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
32 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
31 ); |
33 ); |
32 |
34 |
33 if ( current_user_can( 'install_plugins' ) ) { |
35 if ( current_user_can( 'install_plugins' ) ) { |
34 // List of popular importer plugins from the WordPress.org API. |
36 // List of popular importer plugins from the WordPress.org API. |
35 $popular_importers = wp_get_popular_importers(); |
37 $popular_importers = wp_get_popular_importers(); |
36 } else { |
38 } else { |
37 $popular_importers = array(); |
39 $popular_importers = array(); |
38 } |
40 } |
39 |
41 |
40 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' |
42 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' |
41 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
43 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
42 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
44 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
57 |
59 |
58 <div class="wrap"> |
60 <div class="wrap"> |
59 <h1><?php echo esc_html( $title ); ?></h1> |
61 <h1><?php echo esc_html( $title ); ?></h1> |
60 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
62 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
61 <div class="error"> |
63 <div class="error"> |
62 <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php |
64 <p><strong><?php _e( 'ERROR:' ); ?></strong> |
63 /* translators: %s: importer slug */ |
65 <?php |
64 printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' ); |
66 /* translators: %s: importer slug */ |
65 ?></p> |
67 printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' ); |
|
68 ?> |
|
69 </p> |
66 </div> |
70 </div> |
67 <?php endif; ?> |
71 <?php endif; ?> |
68 <p><?php _e('If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:'); ?></p> |
72 <p><?php _e( 'If you have posts or comments in another system, WordPress can import those into this site. To get started, choose a system to import from below:' ); ?></p> |
69 |
73 |
70 <?php |
74 <?php |
71 // Registered (already installed) importers. They're stored in the global $wp_importers. |
75 // Registered (already installed) importers. They're stored in the global $wp_importers. |
72 $importers = get_importers(); |
76 $importers = get_importers(); |
73 |
77 |
74 // If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
78 // If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
75 foreach ( $popular_importers as $pop_importer => $pop_data ) { |
79 foreach ( $popular_importers as $pop_importer => $pop_data ) { |
76 if ( isset( $importers[ $pop_importer ] ) ) |
80 if ( isset( $importers[ $pop_importer ] ) ) { |
77 continue; |
81 continue; |
78 if ( isset( $importers[ $pop_data['importer-id'] ] ) ) |
82 } |
|
83 if ( isset( $importers[ $pop_data['importer-id'] ] ) ) { |
79 continue; |
84 continue; |
|
85 } |
80 |
86 |
81 // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. |
87 // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. |
82 $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] ); |
88 $importers[ $pop_data['importer-id'] ] = array( |
|
89 $pop_data['name'], |
|
90 $pop_data['description'], |
|
91 'install' => $pop_data['plugin-slug'], |
|
92 ); |
83 } |
93 } |
84 |
94 |
85 if ( empty( $importers ) ) { |
95 if ( empty( $importers ) ) { |
86 echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful |
96 echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: make more helpful |
87 } else { |
97 } else { |
88 uasort( $importers, '_usort_by_first_member' ); |
98 uasort( $importers, '_usort_by_first_member' ); |
89 ?> |
99 ?> |
90 <table class="widefat importers striped"> |
100 <table class="widefat importers striped"> |
91 |
101 |
92 <?php |
102 <?php |
93 foreach ( $importers as $importer_id => $data ) { |
103 foreach ( $importers as $importer_id => $data ) { |
94 $plugin_slug = $action = ''; |
104 $plugin_slug = $action = ''; |
95 $is_plugin_installed = false; |
105 $is_plugin_installed = false; |
96 |
106 |
97 if ( isset( $data['install'] ) ) { |
107 if ( isset( $data['install'] ) ) { |
98 $plugin_slug = $data['install']; |
108 $plugin_slug = $data['install']; |
99 |
109 |
100 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
110 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
101 // Looks like an importer is installed, but not active. |
111 // Looks like an importer is installed, but not active. |
102 $plugins = get_plugins( '/' . $plugin_slug ); |
112 $plugins = get_plugins( '/' . $plugin_slug ); |
103 if ( ! empty( $plugins ) ) { |
113 if ( ! empty( $plugins ) ) { |
104 $keys = array_keys( $plugins ); |
114 $keys = array_keys( $plugins ); |
105 $plugin_file = $plugin_slug . '/' . $keys[0]; |
115 $plugin_file = $plugin_slug . '/' . $keys[0]; |
106 $url = wp_nonce_url( add_query_arg( array( |
116 $url = wp_nonce_url( |
107 'action' => 'activate', |
117 add_query_arg( |
108 'plugin' => $plugin_file, |
118 array( |
109 'from' => 'import', |
119 'action' => 'activate', |
110 ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_file ); |
120 'plugin' => $plugin_file, |
111 $action = sprintf( |
121 'from' => 'import', |
|
122 ), |
|
123 admin_url( 'plugins.php' ) |
|
124 ), |
|
125 'activate-plugin_' . $plugin_file |
|
126 ); |
|
127 $action = sprintf( |
112 '<a href="%s" aria-label="%s">%s</a>', |
128 '<a href="%s" aria-label="%s">%s</a>', |
113 esc_url( $url ), |
129 esc_url( $url ), |
114 /* translators: %s: Importer name */ |
130 /* translators: %s: Importer name */ |
115 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
131 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
116 __( 'Run Importer' ) |
132 __( 'Run Importer' ) |
120 } |
136 } |
121 } |
137 } |
122 |
138 |
123 if ( empty( $action ) ) { |
139 if ( empty( $action ) ) { |
124 if ( is_main_site() ) { |
140 if ( is_main_site() ) { |
125 $url = wp_nonce_url( add_query_arg( array( |
141 $url = wp_nonce_url( |
126 'action' => 'install-plugin', |
142 add_query_arg( |
127 'plugin' => $plugin_slug, |
143 array( |
128 'from' => 'import', |
144 'action' => 'install-plugin', |
129 ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug ); |
145 'plugin' => $plugin_slug, |
|
146 'from' => 'import', |
|
147 ), |
|
148 self_admin_url( 'update.php' ) |
|
149 ), |
|
150 'install-plugin_' . $plugin_slug |
|
151 ); |
130 $action = sprintf( |
152 $action = sprintf( |
131 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', |
153 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', |
132 esc_url( $url ), |
154 esc_url( $url ), |
133 esc_attr( $plugin_slug ), |
155 esc_attr( $plugin_slug ), |
134 esc_attr( $data[0] ), |
156 esc_attr( $data[0] ), |
135 /* translators: %s: Importer name */ |
157 /* translators: %s: Importer name */ |
136 esc_attr( sprintf( __( 'Install %s' ), $data[0] ) ), |
158 esc_attr( sprintf( __( 'Install %s now' ), $data[0] ) ), |
137 __( 'Install Now' ) |
159 __( 'Install Now' ) |
138 ); |
160 ); |
139 } else { |
161 } else { |
140 $action = sprintf( |
162 $action = sprintf( |
141 /* translators: URL to wp-admin/import.php */ |
163 /* translators: URL to wp-admin/import.php */ |
158 |
183 |
159 $is_plugin_installed = true; |
184 $is_plugin_installed = true; |
160 } |
185 } |
161 |
186 |
162 if ( ! $is_plugin_installed && is_main_site() ) { |
187 if ( ! $is_plugin_installed && is_main_site() ) { |
163 $url = add_query_arg( array( |
188 $url = add_query_arg( |
164 'tab' => 'plugin-information', |
189 array( |
165 'plugin' => $plugin_slug, |
190 'tab' => 'plugin-information', |
166 'from' => 'import', |
191 'plugin' => $plugin_slug, |
167 'TB_iframe' => 'true', |
192 'from' => 'import', |
168 'width' => 600, |
193 'TB_iframe' => 'true', |
169 'height' => 550, |
194 'width' => 600, |
170 ), network_admin_url( 'plugin-install.php' ) ); |
195 'height' => 550, |
|
196 ), |
|
197 network_admin_url( 'plugin-install.php' ) |
|
198 ); |
171 $action .= sprintf( |
199 $action .= sprintf( |
172 ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>', |
200 ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>', |
173 esc_url( $url ), |
201 esc_url( $url ), |
174 /* translators: %s: Importer name */ |
202 /* translators: %s: Importer name */ |
175 esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), |
203 esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), |