author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Import WordPress Administration Screen |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
9 | 9 |
define( 'WP_LOAD_IMPORTERS', true ); |
0 | 10 |
|
11 |
/** Load WordPress Bootstrap */ |
|
12 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
13 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
if ( ! current_user_can( 'import' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
wp_die( __( 'Sorry, you are not allowed to import content.' ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
} |
0 | 17 |
|
9 | 18 |
$title = __( 'Import' ); |
0 | 19 |
|
9 | 20 |
get_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 |
); |
|
0 | 28 |
|
29 |
get_current_screen()->set_help_sidebar( |
|
9 | 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</a>' ) . '</p>' |
|
0 | 33 |
); |
34 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
if ( current_user_can( 'install_plugins' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
// List of popular importer plugins from the WordPress.org API. |
0 | 37 |
$popular_importers = wp_get_popular_importers(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
} else { |
9 | 39 |
$popular_importers = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
} |
0 | 41 |
|
42 |
// Detect and redirect invalid importers like 'movabletype', which is registered as 'mt' |
|
43 |
if ( ! 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 |
||
52 |
add_thickbox(); |
|
53 |
wp_enqueue_script( 'plugin-install' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
wp_enqueue_script( 'updates' ); |
0 | 55 |
|
56 |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
|
57 |
$parent_file = 'tools.php'; |
|
58 |
?> |
|
59 |
||
60 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
<h1><?php echo esc_html( $title ); ?></h1> |
0 | 62 |
<?php if ( ! empty( $_GET['invalid'] ) ) : ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
<div class="error"> |
9 | 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> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
</div> |
0 | 71 |
<?php endif; ?> |
9 | 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> |
0 | 73 |
|
74 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
// Registered (already installed) importers. They're stored in the global $wp_importers. |
0 | 76 |
$importers = get_importers(); |
77 |
||
78 |
// If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
|
79 |
foreach ( $popular_importers as $pop_importer => $pop_data ) { |
|
9 | 80 |
if ( isset( $importers[ $pop_importer ] ) ) { |
0 | 81 |
continue; |
9 | 82 |
} |
83 |
if ( isset( $importers[ $pop_data['importer-id'] ] ) ) { |
|
0 | 84 |
continue; |
9 | 85 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
87 |
// Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. |
9 | 88 |
$importers[ $pop_data['importer-id'] ] = array( |
89 |
$pop_data['name'], |
|
90 |
$pop_data['description'], |
|
91 |
'install' => $pop_data['plugin-slug'], |
|
92 |
); |
|
0 | 93 |
} |
94 |
||
95 |
if ( empty( $importers ) ) { |
|
9 | 96 |
echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: make more helpful |
0 | 97 |
} else { |
5 | 98 |
uasort( $importers, '_usort_by_first_member' ); |
9 | 99 |
?> |
5 | 100 |
<table class="widefat importers striped"> |
0 | 101 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
102 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
foreach ( $importers as $importer_id => $data ) { |
9 | 104 |
$plugin_slug = $action = ''; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
$is_plugin_installed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
|
0 | 107 |
if ( isset( $data['install'] ) ) { |
108 |
$plugin_slug = $data['install']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
|
0 | 110 |
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
// Looks like an importer is installed, but not active. |
0 | 112 |
$plugins = get_plugins( '/' . $plugin_slug ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
if ( ! empty( $plugins ) ) { |
9 | 114 |
$keys = array_keys( $plugins ); |
0 | 115 |
$plugin_file = $plugin_slug . '/' . $keys[0]; |
9 | 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( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
129 |
esc_url( $url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
/* translators: %s: Importer name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
__( 'Run Importer' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
$is_plugin_installed = true; |
0 | 136 |
} |
137 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
if ( empty( $action ) ) { |
0 | 140 |
if ( is_main_site() ) { |
9 | 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 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
152 |
$action = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
153 |
'<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
154 |
esc_url( $url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
155 |
esc_attr( $plugin_slug ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
esc_attr( $data[0] ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
157 |
/* translators: %s: Importer name */ |
9 | 158 |
esc_attr( sprintf( __( 'Install %s now' ), $data[0] ) ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
__( 'Install Now' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
); |
0 | 161 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
$action = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
/* translators: URL to wp-admin/import.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
__( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
165 |
get_admin_url( get_current_network_id(), 'import.php' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
166 |
); |
0 | 167 |
} |
168 |
} |
|
169 |
} else { |
|
9 | 170 |
$url = add_query_arg( |
171 |
array( |
|
172 |
'import' => $importer_id, |
|
173 |
), |
|
174 |
self_admin_url( 'admin.php' ) |
|
175 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
176 |
$action = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
'<a href="%1$s" aria-label="%2$s">%3$s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
178 |
esc_url( $url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
179 |
/* translators: %s: Importer name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
__( 'Run Importer' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
$is_plugin_installed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
185 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
if ( ! $is_plugin_installed && is_main_site() ) { |
9 | 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 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
199 |
$action .= sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
200 |
' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
201 |
esc_url( $url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
202 |
/* translators: %s: Importer name */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
204 |
__( 'Details' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
205 |
); |
0 | 206 |
} |
207 |
||
208 |
echo " |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
209 |
<tr class='importer-item'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
<td class='import-system'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
<span class='importer-title'>{$data[0]}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
<span class='importer-action'>{$action}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
</td> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
<td class='desc'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
<span class='importer-desc'>{$data[1]}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
</td> |
0 | 217 |
</tr>"; |
218 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
?> |
0 | 220 |
</table> |
9 | 221 |
<?php |
0 | 222 |
} |
223 |
||
9 | 224 |
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 |
} |
|
0 | 227 |
?> |
228 |
||
229 |
</div> |
|
230 |
||
231 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
wp_print_request_filesystem_credentials_modal(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
wp_print_admin_notice_templates(); |
0 | 234 |
|
235 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |