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 __DIR__ . '/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 into this site.' ) ); |
16 } |
16 } |
17 |
17 |
18 $title = __( 'Import' ); |
18 $title = __( 'Import' ); |
19 |
19 |
20 get_current_screen()->add_help_tab( |
20 get_current_screen()->add_help_tab( |
26 ) |
26 ) |
27 ); |
27 ); |
28 |
28 |
29 get_current_screen()->set_help_sidebar( |
29 get_current_screen()->set_help_sidebar( |
30 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
30 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
31 '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Import_Screen">Documentation on Import</a>' ) . '</p>' . |
31 '<p>' . __( '<a href="https://wordpress.org/support/article/tools-import-screen/">Documentation on Import</a>' ) . '</p>' . |
32 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
32 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
33 ); |
33 ); |
34 |
34 |
35 if ( current_user_can( 'install_plugins' ) ) { |
35 if ( current_user_can( 'install_plugins' ) ) { |
36 // List of popular importer plugins from the WordPress.org API. |
36 // List of popular importer plugins from the WordPress.org API. |
37 $popular_importers = wp_get_popular_importers(); |
37 $popular_importers = wp_get_popular_importers(); |
38 } else { |
38 } else { |
39 $popular_importers = array(); |
39 $popular_importers = array(); |
40 } |
40 } |
41 |
41 |
42 // 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'. |
43 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
43 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
44 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
44 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
45 if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops. |
45 if ( $importer_id !== $_GET['invalid'] ) { // Prevent redirect loops. |
46 wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) ); |
46 wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) ); |
47 exit; |
47 exit; |
48 } |
48 } |
49 unset( $importer_id ); |
49 unset( $importer_id ); |
50 } |
50 } |
51 |
51 |
52 add_thickbox(); |
52 add_thickbox(); |
53 wp_enqueue_script( 'plugin-install' ); |
53 wp_enqueue_script( 'plugin-install' ); |
54 wp_enqueue_script( 'updates' ); |
54 wp_enqueue_script( 'updates' ); |
55 |
55 |
56 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
56 require_once ABSPATH . 'wp-admin/admin-header.php'; |
57 $parent_file = 'tools.php'; |
57 $parent_file = 'tools.php'; |
58 ?> |
58 ?> |
59 |
59 |
60 <div class="wrap"> |
60 <div class="wrap"> |
61 <h1><?php echo esc_html( $title ); ?></h1> |
61 <h1><?php echo esc_html( $title ); ?></h1> |
62 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
62 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
63 <div class="error"> |
63 <div class="error"> |
64 <p><strong><?php _e( 'ERROR:' ); ?></strong> |
64 <p><strong><?php _e( 'Error:' ); ?></strong> |
65 <?php |
65 <?php |
66 /* translators: %s: importer slug */ |
66 /* translators: %s: Importer slug. */ |
67 printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' ); |
67 printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' ); |
68 ?> |
68 ?> |
69 </p> |
69 </p> |
70 </div> |
70 </div> |
71 <?php endif; ?> |
71 <?php endif; ?> |
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> |
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> |
73 |
73 |
91 'install' => $pop_data['plugin-slug'], |
91 'install' => $pop_data['plugin-slug'], |
92 ); |
92 ); |
93 } |
93 } |
94 |
94 |
95 if ( empty( $importers ) ) { |
95 if ( empty( $importers ) ) { |
96 echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: make more helpful |
96 echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: Make more helpful. |
97 } else { |
97 } else { |
98 uasort( $importers, '_usort_by_first_member' ); |
98 uasort( $importers, '_usort_by_first_member' ); |
99 ?> |
99 ?> |
100 <table class="widefat importers striped"> |
100 <table class="widefat importers striped"> |
101 |
101 |
102 <?php |
102 <?php |
103 foreach ( $importers as $importer_id => $data ) { |
103 foreach ( $importers as $importer_id => $data ) { |
104 $plugin_slug = $action = ''; |
104 $plugin_slug = ''; |
|
105 $action = ''; |
105 $is_plugin_installed = false; |
106 $is_plugin_installed = false; |
106 |
107 |
107 if ( isset( $data['install'] ) ) { |
108 if ( isset( $data['install'] ) ) { |
108 $plugin_slug = $data['install']; |
109 $plugin_slug = $data['install']; |
109 |
110 |
125 'activate-plugin_' . $plugin_file |
126 'activate-plugin_' . $plugin_file |
126 ); |
127 ); |
127 $action = sprintf( |
128 $action = sprintf( |
128 '<a href="%s" aria-label="%s">%s</a>', |
129 '<a href="%s" aria-label="%s">%s</a>', |
129 esc_url( $url ), |
130 esc_url( $url ), |
130 /* translators: %s: Importer name */ |
131 /* translators: %s: Importer name. */ |
131 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
132 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
132 __( 'Run Importer' ) |
133 __( 'Run Importer' ) |
133 ); |
134 ); |
134 |
135 |
135 $is_plugin_installed = true; |
136 $is_plugin_installed = true; |
152 $action = sprintf( |
153 $action = sprintf( |
153 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', |
154 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', |
154 esc_url( $url ), |
155 esc_url( $url ), |
155 esc_attr( $plugin_slug ), |
156 esc_attr( $plugin_slug ), |
156 esc_attr( $data[0] ), |
157 esc_attr( $data[0] ), |
157 /* translators: %s: Importer name */ |
158 /* translators: %s: Importer name. */ |
158 esc_attr( sprintf( __( 'Install %s now' ), $data[0] ) ), |
159 esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $data[0] ) ), |
159 __( 'Install Now' ) |
160 __( 'Install Now' ) |
160 ); |
161 ); |
161 } else { |
162 } else { |
162 $action = sprintf( |
163 $action = sprintf( |
163 /* translators: URL to wp-admin/import.php */ |
164 /* translators: %s: URL to Import screen on the main site. */ |
164 __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), |
165 __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), |
165 get_admin_url( get_current_network_id(), 'import.php' ) |
166 get_admin_url( get_current_network_id(), 'import.php' ) |
166 ); |
167 ); |
167 } |
168 } |
168 } |
169 } |
174 self_admin_url( 'admin.php' ) |
175 self_admin_url( 'admin.php' ) |
175 ); |
176 ); |
176 $action = sprintf( |
177 $action = sprintf( |
177 '<a href="%1$s" aria-label="%2$s">%3$s</a>', |
178 '<a href="%1$s" aria-label="%2$s">%3$s</a>', |
178 esc_url( $url ), |
179 esc_url( $url ), |
179 /* translators: %s: Importer name */ |
180 /* translators: %s: Importer name. */ |
180 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
181 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
181 __( 'Run Importer' ) |
182 __( 'Run Importer' ) |
182 ); |
183 ); |
183 |
184 |
184 $is_plugin_installed = true; |
185 $is_plugin_installed = true; |
220 </table> |
221 </table> |
221 <?php |
222 <?php |
222 } |
223 } |
223 |
224 |
224 if ( current_user_can( 'install_plugins' ) ) { |
225 if ( current_user_can( 'install_plugins' ) ) { |
225 echo '<p>' . sprintf( __( 'If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.' ), esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) ) . '</p>'; |
226 echo '<p>' . sprintf( |
|
227 /* translators: %s: URL to Add Plugins screen. */ |
|
228 __( 'If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.' ), |
|
229 esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) |
|
230 ) . '</p>'; |
226 } |
231 } |
227 ?> |
232 ?> |
228 |
233 |
229 </div> |
234 </div> |
230 |
235 |
231 <?php |
236 <?php |
232 wp_print_request_filesystem_credentials_modal(); |
237 wp_print_request_filesystem_credentials_modal(); |
233 wp_print_admin_notice_templates(); |
238 wp_print_admin_notice_templates(); |
234 |
239 |
235 include( ABSPATH . 'wp-admin/admin-footer.php' ); |
240 require_once ABSPATH . 'wp-admin/admin-footer.php'; |