Make WordPress Core

source: trunk/src/wp-admin/import.php @ 44417

Last change on this file since 44417 was 44417, checked in by SergeyBiryukov, 6 years ago

Importers: Use correct l10n variable in wp.updates.installImporterError and filesystem credentials dialog.

Missed in [40034].

Props afercia, abhayvishwakarma.
Fixes #45765.

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1<?php
2/**
3 * Import WordPress Administration Screen
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9define( 'WP_LOAD_IMPORTERS', true );
10
11/** Load WordPress Bootstrap */
12require_once( dirname( __FILE__ ) . '/admin.php' );
13
14if ( ! current_user_can( 'import' ) ) {
15        wp_die( __( 'Sorry, you are not allowed to import content.' ) );
16}
17
18$title = __( 'Import' );
19
20get_current_screen()->add_help_tab(
21        array(
22                'id'      => 'overview',
23                'title'   => __( 'Overview' ),
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                        '<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);
28
29get_current_screen()->set_help_sidebar(
30        '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
31        '<p>' . __( '<a href="https://codex.wordpress.org/Tools_Import_Screen">Documentation on Import</a>' ) . '</p>' .
32        '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>'
33);
34
35if ( current_user_can( 'install_plugins' ) ) {
36        // List of popular importer plugins from the WordPress.org API.
37        $popular_importers = wp_get_popular_importers();
38} else {
39        $popular_importers = array();
40}
41
42// Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'
43if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) {
44        $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id'];
45        if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops.
46                wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) );
47                exit;
48        }
49        unset( $importer_id );
50}
51
52add_thickbox();
53wp_enqueue_script( 'plugin-install' );
54wp_enqueue_script( 'updates' );
55
56require_once( ABSPATH . 'wp-admin/admin-header.php' );
57$parent_file = 'tools.php';
58?>
59
60<div class="wrap">
61<h1><?php echo esc_html( $title ); ?></h1>
62<?php if ( ! empty( $_GET['invalid'] ) ) : ?>
63        <div class="error">
64                <p><strong><?php _e( 'ERROR:' ); ?></strong>
65                                                                <?php
66                                                                /* translators: %s: importer slug */
67                                                                printf( __( 'The %s importer is invalid or is not installed.' ), '<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' );
68                                                                ?>
69                </p>
70        </div>
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>
73
74<?php
75// Registered (already installed) importers. They're stored in the global $wp_importers.
76$importers = get_importers();
77
78// If a popular importer is not registered, create a dummy registration that links to the plugin installer.
79foreach ( $popular_importers as $pop_importer => $pop_data ) {
80        if ( isset( $importers[ $pop_importer ] ) ) {
81                continue;
82        }
83        if ( isset( $importers[ $pop_data['importer-id'] ] ) ) {
84                continue;
85        }
86
87        // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API.
88        $importers[ $pop_data['importer-id'] ] = array(
89                $pop_data['name'],
90                $pop_data['description'],
91                'install' => $pop_data['plugin-slug'],
92        );
93}
94
95if ( empty( $importers ) ) {
96        echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: make more helpful
97} else {
98        uasort( $importers, '_usort_by_first_member' );
99        ?>
100<table class="widefat importers striped">
101
102        <?php
103        foreach ( $importers as $importer_id => $data ) {
104                $plugin_slug         = $action = '';
105                $is_plugin_installed = false;
106
107                if ( isset( $data['install'] ) ) {
108                        $plugin_slug = $data['install'];
109
110                        if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
111                                // Looks like an importer is installed, but not active.
112                                $plugins = get_plugins( '/' . $plugin_slug );
113                                if ( ! empty( $plugins ) ) {
114                                        $keys        = array_keys( $plugins );
115                                        $plugin_file = $plugin_slug . '/' . $keys[0];
116                                        $url         = wp_nonce_url(
117                                                add_query_arg(
118                                                        array(
119                                                                'action' => 'activate',
120                                                                'plugin' => $plugin_file,
121                                                                'from'   => 'import',
122                                                        ),
123                                                        admin_url( 'plugins.php' )
124                                                ),
125                                                'activate-plugin_' . $plugin_file
126                                        );
127                                        $action      = sprintf(
128                                                '<a href="%s" aria-label="%s">%s</a>',
129                                                esc_url( $url ),
130                                                /* translators: %s: Importer name */
131                                                esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
132                                                __( 'Run Importer' )
133                                        );
134
135                                        $is_plugin_installed = true;
136                                }
137                        }
138
139                        if ( empty( $action ) ) {
140                                if ( is_main_site() ) {
141                                        $url    = wp_nonce_url(
142                                                add_query_arg(
143                                                        array(
144                                                                'action' => 'install-plugin',
145                                                                'plugin' => $plugin_slug,
146                                                                'from'   => 'import',
147                                                        ),
148                                                        self_admin_url( 'update.php' )
149                                                ),
150                                                'install-plugin_' . $plugin_slug
151                                        );
152                                        $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                                                esc_url( $url ),
155                                                esc_attr( $plugin_slug ),
156                                                esc_attr( $data[0] ),
157                                                /* translators: %s: Importer name */
158                                                esc_attr( sprintf( __( 'Install %s now' ), $data[0] ) ),
159                                                __( 'Install Now' )
160                                        );
161                                } else {
162                                        $action = sprintf(
163                                                /* translators: URL to wp-admin/import.php */
164                                                __( '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                                        );
167                                }
168                        }
169                } else {
170                        $url    = add_query_arg(
171                                array(
172                                        'import' => $importer_id,
173                                ),
174                                self_admin_url( 'admin.php' )
175                        );
176                        $action = sprintf(
177                                '<a href="%1$s" aria-label="%2$s">%3$s</a>',
178                                esc_url( $url ),
179                                /* translators: %s: Importer name */
180                                esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
181                                __( 'Run Importer' )
182                        );
183
184                        $is_plugin_installed = true;
185                }
186
187                if ( ! $is_plugin_installed && is_main_site() ) {
188                        $url     = add_query_arg(
189                                array(
190                                        'tab'       => 'plugin-information',
191                                        'plugin'    => $plugin_slug,
192                                        'from'      => 'import',
193                                        'TB_iframe' => 'true',
194                                        'width'     => 600,
195                                        'height'    => 550,
196                                ),
197                                network_admin_url( 'plugin-install.php' )
198                        );
199                        $action .= sprintf(
200                                ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
201                                esc_url( $url ),
202                                /* translators: %s: Importer name */
203                                esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ),
204                                __( 'Details' )
205                        );
206                }
207
208                echo "
209                        <tr class='importer-item'>
210                                <td class='import-system'>
211                                        <span class='importer-title'>{$data[0]}</span>
212                                        <span class='importer-action'>{$action}</span>
213                                </td>
214                                <td class='desc'>
215                                        <span class='importer-desc'>{$data[1]}</span>
216                                </td>
217                        </tr>";
218        }
219        ?>
220</table>
221        <?php
222}
223
224if ( 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}
227?>
228
229</div>
230
231<?php
232wp_print_request_filesystem_credentials_modal();
233wp_print_admin_notice_templates();
234
235include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracBrowser for help on using the repository browser.