23 '<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 '<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 ) ); |
25 ) ); |
25 |
26 |
26 get_current_screen()->set_help_sidebar( |
27 get_current_screen()->set_help_sidebar( |
27 '<p><strong>' . __('For more information:') . '</strong></p>' . |
28 '<p><strong>' . __('For more information:') . '</strong></p>' . |
28 '<p>' . __('<a href="https://codex.wordpress.org/Tools_Import_Screen" target="_blank">Documentation on Import</a>') . '</p>' . |
29 '<p>' . __('<a href="https://codex.wordpress.org/Tools_Import_Screen">Documentation on Import</a>') . '</p>' . |
29 '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' |
30 '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
30 ); |
31 ); |
31 |
32 |
32 if ( current_user_can( 'install_plugins' ) ) |
33 if ( current_user_can( 'install_plugins' ) ) { |
|
34 // List of popular importer plugins from the WordPress.org API. |
33 $popular_importers = wp_get_popular_importers(); |
35 $popular_importers = wp_get_popular_importers(); |
34 else |
36 } else { |
35 $popular_importers = array(); |
37 $popular_importers = array(); |
|
38 } |
36 |
39 |
37 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' |
40 // Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' |
38 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
41 if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
39 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
42 $importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
40 if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops. |
43 if ( $importer_id != $_GET['invalid'] ) { // Prevent redirect loops. |
44 unset( $importer_id ); |
47 unset( $importer_id ); |
45 } |
48 } |
46 |
49 |
47 add_thickbox(); |
50 add_thickbox(); |
48 wp_enqueue_script( 'plugin-install' ); |
51 wp_enqueue_script( 'plugin-install' ); |
|
52 wp_enqueue_script( 'updates' ); |
49 |
53 |
50 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
54 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
51 $parent_file = 'tools.php'; |
55 $parent_file = 'tools.php'; |
52 ?> |
56 ?> |
53 |
57 |
54 <div class="wrap"> |
58 <div class="wrap"> |
55 <h2><?php echo esc_html( $title ); ?></h2> |
59 <h1><?php echo esc_html( $title ); ?></h1> |
56 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
60 <?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
57 <div class="error"><p><strong><?php _e('ERROR:')?></strong> <?php printf( __('The <strong>%s</strong> importer is invalid or is not installed.'), esc_html( $_GET['invalid'] ) ); ?></p></div> |
61 <div class="error"> |
|
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>' ); |
|
65 ?></p> |
|
66 </div> |
58 <?php endif; ?> |
67 <?php endif; ?> |
59 <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> |
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> |
60 |
69 |
61 <?php |
70 <?php |
62 |
71 // Registered (already installed) importers. They're stored in the global $wp_importers. |
63 $importers = get_importers(); |
72 $importers = get_importers(); |
64 |
73 |
65 // If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
74 // If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
66 foreach ( $popular_importers as $pop_importer => $pop_data ) { |
75 foreach ( $popular_importers as $pop_importer => $pop_data ) { |
67 if ( isset( $importers[ $pop_importer ] ) ) |
76 if ( isset( $importers[ $pop_importer ] ) ) |
68 continue; |
77 continue; |
69 if ( isset( $importers[ $pop_data['importer-id'] ] ) ) |
78 if ( isset( $importers[ $pop_data['importer-id'] ] ) ) |
70 continue; |
79 continue; |
|
80 |
|
81 // Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. |
71 $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] ); |
82 $importers[ $pop_data['importer-id'] ] = array( $pop_data['name'], $pop_data['description'], 'install' => $pop_data['plugin-slug'] ); |
72 } |
83 } |
73 |
84 |
74 if ( empty( $importers ) ) { |
85 if ( empty( $importers ) ) { |
75 echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful |
86 echo '<p>' . __('No importers are available.') . '</p>'; // TODO: make more helpful |
76 } else { |
87 } else { |
77 uasort( $importers, '_usort_by_first_member' ); |
88 uasort( $importers, '_usort_by_first_member' ); |
78 ?> |
89 ?> |
79 <table class="widefat importers striped"> |
90 <table class="widefat importers striped"> |
80 |
91 |
81 <?php |
92 <?php |
82 foreach ($importers as $importer_id => $data) { |
93 foreach ( $importers as $importer_id => $data ) { |
83 $action = ''; |
94 $plugin_slug = $action = ''; |
|
95 $is_plugin_installed = false; |
|
96 |
84 if ( isset( $data['install'] ) ) { |
97 if ( isset( $data['install'] ) ) { |
85 $plugin_slug = $data['install']; |
98 $plugin_slug = $data['install']; |
|
99 |
86 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
100 if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
87 // Looks like Importer is installed, But not active |
101 // Looks like an importer is installed, but not active. |
88 $plugins = get_plugins( '/' . $plugin_slug ); |
102 $plugins = get_plugins( '/' . $plugin_slug ); |
89 if ( !empty($plugins) ) { |
103 if ( ! empty( $plugins ) ) { |
90 $keys = array_keys($plugins); |
104 $keys = array_keys( $plugins ); |
91 $plugin_file = $plugin_slug . '/' . $keys[0]; |
105 $plugin_file = $plugin_slug . '/' . $keys[0]; |
92 $action = '<a href="' . esc_url(wp_nonce_url(admin_url('plugins.php?action=activate&plugin=' . $plugin_file . '&from=import'), 'activate-plugin_' . $plugin_file)) . |
106 $url = wp_nonce_url( add_query_arg( array( |
93 '"title="' . esc_attr__('Activate importer') . '"">' . $data[0] . '</a>'; |
107 'action' => 'activate', |
|
108 'plugin' => $plugin_file, |
|
109 'from' => 'import', |
|
110 ), admin_url( 'plugins.php' ) ), 'activate-plugin_' . $plugin_file ); |
|
111 $action = sprintf( |
|
112 '<a href="%s" aria-label="%s">%s</a>', |
|
113 esc_url( $url ), |
|
114 /* translators: %s: Importer name */ |
|
115 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
|
116 __( 'Run Importer' ) |
|
117 ); |
|
118 |
|
119 $is_plugin_installed = true; |
94 } |
120 } |
95 } |
121 } |
96 if ( empty($action) ) { |
122 |
|
123 if ( empty( $action ) ) { |
97 if ( is_main_site() ) { |
124 if ( is_main_site() ) { |
98 $action = '<a href="' . esc_url( network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . |
125 $url = wp_nonce_url( add_query_arg( array( |
99 '&from=import&TB_iframe=true&width=600&height=550' ) ) . '" class="thickbox" title="' . |
126 'action' => 'install-plugin', |
100 esc_attr__('Install importer') . '">' . $data[0] . '</a>'; |
127 'plugin' => $plugin_slug, |
|
128 'from' => 'import', |
|
129 ), self_admin_url( 'update.php' ) ), 'install-plugin_' . $plugin_slug ); |
|
130 $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>', |
|
132 esc_url( $url ), |
|
133 esc_attr( $plugin_slug ), |
|
134 esc_attr( $data[0] ), |
|
135 /* translators: %s: Importer name */ |
|
136 esc_attr( sprintf( __( 'Install %s' ), $data[0] ) ), |
|
137 __( 'Install Now' ) |
|
138 ); |
101 } else { |
139 } else { |
102 $action = $data[0]; |
140 $action = sprintf( |
103 $data[1] = sprintf( __( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), get_admin_url( $current_site->blog_id, 'import.php' ) ); |
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' ) |
|
144 ); |
104 } |
145 } |
105 } |
146 } |
106 } else { |
147 } else { |
107 $action = "<a href='" . esc_url( "admin.php?import=$importer_id" ) . "' title='" . esc_attr( wptexturize( strip_tags( $data[1] ) ) ) ."'>{$data[0]}</a>"; |
148 $url = add_query_arg( array( |
|
149 'import' => $importer_id, |
|
150 ), self_admin_url( 'admin.php' ) ); |
|
151 $action = sprintf( |
|
152 '<a href="%1$s" aria-label="%2$s">%3$s</a>', |
|
153 esc_url( $url ), |
|
154 /* translators: %s: Importer name */ |
|
155 esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
|
156 __( 'Run Importer' ) |
|
157 ); |
|
158 |
|
159 $is_plugin_installed = true; |
108 } |
160 } |
109 |
161 |
|
162 if ( ! $is_plugin_installed && is_main_site() ) { |
|
163 $url = add_query_arg( array( |
|
164 'tab' => 'plugin-information', |
|
165 'plugin' => $plugin_slug, |
|
166 'from' => 'import', |
|
167 'TB_iframe' => 'true', |
|
168 'width' => 600, |
|
169 'height' => 550, |
|
170 ), network_admin_url( 'plugin-install.php' ) ); |
|
171 $action .= sprintf( |
|
172 ' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>', |
|
173 esc_url( $url ), |
|
174 /* translators: %s: Importer name */ |
|
175 esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), |
|
176 __( 'Details' ) |
|
177 ); |
|
178 } |
|
179 |
110 echo " |
180 echo " |
111 <tr> |
181 <tr class='importer-item'> |
112 <td class='import-system row-title'>$action</td> |
182 <td class='import-system'> |
113 <td class='desc'>{$data[1]}</td> |
183 <span class='importer-title'>{$data[0]}</span> |
|
184 <span class='importer-action'>{$action}</span> |
|
185 </td> |
|
186 <td class='desc'> |
|
187 <span class='importer-desc'>{$data[1]}</span> |
|
188 </td> |
114 </tr>"; |
189 </tr>"; |
115 } |
190 } |
116 ?> |
191 ?> |
117 |
|
118 </table> |
192 </table> |
119 <?php |
193 <?php |
120 } |
194 } |
121 |
195 |
122 if ( current_user_can('install_plugins') ) |
196 if ( current_user_can('install_plugins') ) |