3 * Import WordPress Administration Screen
6 * @subpackage Administration
9 define('WP_LOAD_IMPORTERS', true);
11 /** Load WordPress Bootstrap */
12 require_once( dirname( __FILE__ ) . '/admin.php' );
14 if ( ! current_user_can( 'import' ) ) {
15 wp_die( __( 'Sorry, you are not allowed to import content.' ) );
18 $title = __('Import');
20 get_current_screen()->add_help_tab( array(
22 'title' => __('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>' .
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>',
27 get_current_screen()->set_help_sidebar(
28 '<p><strong>' . __('For more information:') . '</strong></p>' .
29 '<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>'
33 if ( current_user_can( 'install_plugins' ) ) {
34 // List of popular importer plugins from the WordPress.org API.
35 $popular_importers = wp_get_popular_importers();
37 $popular_importers = array();
40 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'
41 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) {
42 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id'];
43 if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops.
44 wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) );
47 unset( $importer_id );
51 wp_enqueue_script( 'plugin-install' );
52 wp_enqueue_script( 'updates' );
54 require_once( ABSPATH . 'wp-admin/admin-header.php' );
55 $parent_file = 'tools.php';
59 <h1><?php echo esc_html( $title ); ?></h1>
60 <?php if ( ! empty( $_GET['invalid'] ) ) : ?>
62 <p><strong><?php _e( 'ERROR:' ); ?></strong> <?php
63 /* translators: %s: importer slug */
64 printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' );
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>
71 // Registered (already installed) importers. They're stored in the global $wp_importers.
72 $importers = get_importers();
74 // 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 ) {
76 if ( isset( $importers[ $pop_importer ] ) )
78 if ( isset( $importers[ $pop_data['importer-id'] ] ) )
81 // 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'] );
85 if ( empty( $importers ) ) {
86 echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful
88 uasort( $importers, '_usort_by_first_member' );
90 <table class="widefat importers striped">
93 foreach ( $importers as $importer_id => $data ) {
94 $plugin_slug = $action = '';
95 $is_plugin_installed = false;
97 if ( isset( $data['install'] ) ) {
98 $plugin_slug = $data['install'];
100 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
101 // Looks like an importer is installed, but not active.
102 $plugins = get_plugins( '/' . $plugin_slug );
103 if ( ! empty( $plugins ) ) {
104 $keys = array_keys( $plugins );
105 $plugin_file = $plugin_slug . '/' . $keys[0];
106 $url = wp_nonce_url( add_query_arg( array(
107 'action' => 'activate',
108 'plugin' => $plugin_file,
110 ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_file );
112 '<a href="%s" aria-label="%s">%s</a>',
114 /* translators: %s: Importer name */
115 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
119 $is_plugin_installed = true;
123 if ( empty( $action ) ) {
124 if ( is_main_site() ) {
125 $url = wp_nonce_url( add_query_arg( array(
126 'action' => 'install-plugin',
127 'plugin' => $plugin_slug,
129 ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug );
131 '<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>',
133 esc_attr( $plugin_slug ),
134 esc_attr( $data[0] ),
135 /* translators: %s: Importer name */
136 esc_attr( sprintf( __( 'Install %s' ), $data[0] ) ),
141 /* translators: URL to wp-admin/import.php */
142 __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ),
143 get_admin_url( get_current_network_id(), 'import.php' )
148 $url = add_query_arg( array(
149 'import' => $importer_id,
150 ), self_admin_url( 'admin.php' ) );
152 '<a href="%1$s" aria-label="%2$s">%3$s</a>',
154 /* translators: %s: Importer name */
155 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
159 $is_plugin_installed = true;
162 if ( ! $is_plugin_installed && is_main_site() ) {
163 $url = add_query_arg( array(
164 'tab' => 'plugin-information',
165 'plugin' => $plugin_slug,
167 'TB_iframe' => 'true',
170 ), network_admin_url( 'plugin-install.php' ) );
172 ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
174 /* translators: %s: Importer name */
175 esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ),
181 <tr class='importer-item'>
182 <td class='import-system'>
183 <span class='importer-title'>{$data[0]}</span>
184 <span class='importer-action'>{$action}</span>
187 <span class='importer-desc'>{$data[1]}</span>
196 if ( current_user_can('install_plugins') )
197 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>';
203 wp_print_request_filesystem_credentials_modal();
204 wp_print_admin_notice_templates();
206 include( ABSPATH . 'wp-admin/admin-footer.php' );