author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
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 */ |
|
16 | 12 |
require_once __DIR__ . '/admin.php'; |
0 | 13 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
if ( ! current_user_can( 'import' ) ) { |
16 | 15 |
wp_die( __( 'Sorry, you are not allowed to import content into this site.' ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
} |
0 | 17 |
|
19 | 18 |
// Used in the HTML title tag. |
9 | 19 |
$title = __( 'Import' ); |
0 | 20 |
|
9 | 21 |
get_current_screen()->add_help_tab( |
22 |
array( |
|
23 |
'id' => 'overview', |
|
24 |
'title' => __( 'Overview' ), |
|
25 |
'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>' . |
|
26 |
'<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 |
) |
|
28 |
); |
|
0 | 29 |
|
30 |
get_current_screen()->set_help_sidebar( |
|
9 | 31 |
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
'<p>' . __( '<a href="https://wordpress.org/documentation/article/tools-import-screen/">Documentation on Import</a>' ) . '</p>' . |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
33 |
'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' |
0 | 34 |
); |
35 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
if ( current_user_can( 'install_plugins' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
// List of popular importer plugins from the WordPress.org API. |
0 | 38 |
$popular_importers = wp_get_popular_importers(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
} else { |
9 | 40 |
$popular_importers = array(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
41 |
} |
0 | 42 |
|
16 | 43 |
// Detect and redirect invalid importers like 'movabletype', which is registered as 'mt'. |
0 | 44 |
if ( ! empty( $_GET['invalid'] ) && isset( $popular_importers[ $_GET['invalid'] ] ) ) { |
45 |
$importer_id = $popular_importers[ $_GET['invalid'] ]['importer-id']; |
|
16 | 46 |
if ( $importer_id !== $_GET['invalid'] ) { // Prevent redirect loops. |
0 | 47 |
wp_redirect( admin_url( 'admin.php?import=' . $importer_id ) ); |
48 |
exit; |
|
49 |
} |
|
50 |
unset( $importer_id ); |
|
51 |
} |
|
52 |
||
53 |
add_thickbox(); |
|
54 |
wp_enqueue_script( 'plugin-install' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
55 |
wp_enqueue_script( 'updates' ); |
0 | 56 |
|
16 | 57 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 58 |
$parent_file = 'tools.php'; |
59 |
?> |
|
60 |
||
61 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
<h1><?php echo esc_html( $title ); ?></h1> |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
if ( ! empty( $_GET['invalid'] ) ) : |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
$importer_not_installed = '<strong>' . __( 'Error:' ) . '</strong> ' . sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
/* translators: %s: Importer slug. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
__( 'The %s importer is invalid or is not installed.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
68 |
'<strong>' . esc_html( $_GET['invalid'] ) . '</strong>' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
69 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
71 |
$importer_not_installed, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
72 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
'additional_classes' => array( 'error' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
75 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
endif; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
77 |
?> |
9 | 78 |
<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 | 79 |
|
80 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
// Registered (already installed) importers. They're stored in the global $wp_importers. |
0 | 82 |
$importers = get_importers(); |
83 |
||
84 |
// If a popular importer is not registered, create a dummy registration that links to the plugin installer. |
|
85 |
foreach ( $popular_importers as $pop_importer => $pop_data ) { |
|
9 | 86 |
if ( isset( $importers[ $pop_importer ] ) ) { |
0 | 87 |
continue; |
9 | 88 |
} |
89 |
if ( isset( $importers[ $pop_data['importer-id'] ] ) ) { |
|
0 | 90 |
continue; |
9 | 91 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
// Fill the array of registered (already installed) importers with data of the popular importers from the WordPress.org API. |
9 | 94 |
$importers[ $pop_data['importer-id'] ] = array( |
95 |
$pop_data['name'], |
|
96 |
$pop_data['description'], |
|
97 |
'install' => $pop_data['plugin-slug'], |
|
98 |
); |
|
0 | 99 |
} |
100 |
||
101 |
if ( empty( $importers ) ) { |
|
16 | 102 |
echo '<p>' . __( 'No importers are available.' ) . '</p>'; // TODO: Make more helpful. |
0 | 103 |
} else { |
5 | 104 |
uasort( $importers, '_usort_by_first_member' ); |
9 | 105 |
?> |
5 | 106 |
<table class="widefat importers striped"> |
0 | 107 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
foreach ( $importers as $importer_id => $data ) { |
16 | 110 |
$plugin_slug = ''; |
111 |
$action = ''; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
$is_plugin_installed = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
|
0 | 114 |
if ( isset( $data['install'] ) ) { |
115 |
$plugin_slug = $data['install']; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
116 |
|
0 | 117 |
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
118 |
// Looks like an importer is installed, but not active. |
0 | 119 |
$plugins = get_plugins( '/' . $plugin_slug ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
120 |
if ( ! empty( $plugins ) ) { |
9 | 121 |
$keys = array_keys( $plugins ); |
0 | 122 |
$plugin_file = $plugin_slug . '/' . $keys[0]; |
9 | 123 |
$url = wp_nonce_url( |
124 |
add_query_arg( |
|
125 |
array( |
|
126 |
'action' => 'activate', |
|
127 |
'plugin' => $plugin_file, |
|
128 |
'from' => 'import', |
|
129 |
), |
|
130 |
admin_url( 'plugins.php' ) |
|
131 |
), |
|
132 |
'activate-plugin_' . $plugin_file |
|
133 |
); |
|
134 |
$action = sprintf( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
'<a href="%s" aria-label="%s">%s</a>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
esc_url( $url ), |
16 | 137 |
/* translators: %s: Importer name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
139 |
__( 'Run Importer' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
$is_plugin_installed = true; |
0 | 143 |
} |
144 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
if ( empty( $action ) ) { |
0 | 147 |
if ( is_main_site() ) { |
9 | 148 |
$url = wp_nonce_url( |
149 |
add_query_arg( |
|
150 |
array( |
|
151 |
'action' => 'install-plugin', |
|
152 |
'plugin' => $plugin_slug, |
|
153 |
'from' => 'import', |
|
154 |
), |
|
155 |
self_admin_url( 'update.php' ) |
|
156 |
), |
|
157 |
'install-plugin_' . $plugin_slug |
|
158 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
$action = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
'<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
|
161 |
esc_url( $url ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
esc_attr( $plugin_slug ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
esc_attr( $data[0] ), |
16 | 164 |
/* translators: %s: Importer name. */ |
165 |
esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $data[0] ) ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
_x( 'Install Now', 'plugin' ) |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
); |
0 | 168 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
169 |
$action = sprintf( |
16 | 170 |
/* translators: %s: URL to Import screen on the main site. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
171 |
__( '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
|
172 |
get_admin_url( get_current_network_id(), 'import.php' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
); |
0 | 174 |
} |
175 |
} |
|
176 |
} else { |
|
9 | 177 |
$url = add_query_arg( |
178 |
array( |
|
179 |
'import' => $importer_id, |
|
180 |
), |
|
181 |
self_admin_url( 'admin.php' ) |
|
182 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
183 |
$action = sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
184 |
'<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
|
185 |
esc_url( $url ), |
16 | 186 |
/* translators: %s: Importer name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
187 |
esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
188 |
__( 'Run Importer' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
$is_plugin_installed = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
192 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
if ( ! $is_plugin_installed && is_main_site() ) { |
9 | 195 |
$url = add_query_arg( |
196 |
array( |
|
197 |
'tab' => 'plugin-information', |
|
198 |
'plugin' => $plugin_slug, |
|
199 |
'from' => 'import', |
|
200 |
'TB_iframe' => 'true', |
|
201 |
'width' => 600, |
|
202 |
'height' => 550, |
|
203 |
), |
|
204 |
network_admin_url( 'plugin-install.php' ) |
|
205 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
206 |
$action .= sprintf( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
' | <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
|
208 |
esc_url( $url ), |
16 | 209 |
/* translators: %s: Importer name. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
211 |
__( 'Details' ) |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
); |
0 | 213 |
} |
214 |
||
215 |
echo " |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
<tr class='importer-item'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
<td class='import-system'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
<span class='importer-title'>{$data[0]}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
<span class='importer-action'>{$action}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
</td> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
<td class='desc'> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
<span class='importer-desc'>{$data[1]}</span> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
</td> |
0 | 224 |
</tr>"; |
225 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
?> |
0 | 227 |
</table> |
9 | 228 |
<?php |
0 | 229 |
} |
230 |
||
9 | 231 |
if ( current_user_can( 'install_plugins' ) ) { |
16 | 232 |
echo '<p>' . sprintf( |
233 |
/* translators: %s: URL to Add Plugins screen. */ |
|
234 |
__( 'If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.' ), |
|
235 |
esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) ) |
|
236 |
) . '</p>'; |
|
9 | 237 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
238 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
239 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
240 |
* Fires at the end of the Import screen. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
241 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
242 |
* @since 6.8.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
243 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
244 |
do_action( 'import_filters' ); |
0 | 245 |
?> |
246 |
||
247 |
</div> |
|
248 |
||
249 |
<?php |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
wp_print_request_filesystem_credentials_modal(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
wp_print_admin_notice_templates(); |
0 | 252 |
|
16 | 253 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |