ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

import.php (7530B)


      1 <?php
      2 /**
      3  * Import WordPress Administration Screen
      4  *
      5  * @package WordPress
      6  * @subpackage Administration
      7  */
      8 
      9 define( 'WP_LOAD_IMPORTERS', true );
     10 
     11 /** Load WordPress Bootstrap */
     12 require_once __DIR__ . '/admin.php';
     13 
     14 if ( ! current_user_can( 'import' ) ) {
     15 	wp_die( __( 'Sorry, you are not allowed to import content into this site.' ) );
     16 }
     17 
     18 $title = __( 'Import' );
     19 
     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 );
     28 
     29 get_current_screen()->set_help_sidebar(
     30 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
     31 	'<p>' . __( '<a href="https://wordpress.org/support/article/tools-import-screen/">Documentation on Import</a>' ) . '</p>' .
     32 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
     33 );
     34 
     35 if ( 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'.
     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' );
     54 wp_enqueue_script( 'updates' );
     55 
     56 require_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.
     79 foreach ( $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 
     95 if ( 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         = '';
    105 		$action              = '';
    106 		$is_plugin_installed = false;
    107 
    108 		if ( isset( $data['install'] ) ) {
    109 			$plugin_slug = $data['install'];
    110 
    111 			if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug ) ) {
    112 				// Looks like an importer is installed, but not active.
    113 				$plugins = get_plugins( '/' . $plugin_slug );
    114 				if ( ! empty( $plugins ) ) {
    115 					$keys        = array_keys( $plugins );
    116 					$plugin_file = $plugin_slug . '/' . $keys[0];
    117 					$url         = wp_nonce_url(
    118 						add_query_arg(
    119 							array(
    120 								'action' => 'activate',
    121 								'plugin' => $plugin_file,
    122 								'from'   => 'import',
    123 							),
    124 							admin_url( 'plugins.php' )
    125 						),
    126 						'activate-plugin_' . $plugin_file
    127 					);
    128 					$action      = sprintf(
    129 						'<a href="%s" aria-label="%s">%s</a>',
    130 						esc_url( $url ),
    131 						/* translators: %s: Importer name. */
    132 						esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
    133 						__( 'Run Importer' )
    134 					);
    135 
    136 					$is_plugin_installed = true;
    137 				}
    138 			}
    139 
    140 			if ( empty( $action ) ) {
    141 				if ( is_main_site() ) {
    142 					$url    = wp_nonce_url(
    143 						add_query_arg(
    144 							array(
    145 								'action' => 'install-plugin',
    146 								'plugin' => $plugin_slug,
    147 								'from'   => 'import',
    148 							),
    149 							self_admin_url( 'update.php' )
    150 						),
    151 						'install-plugin_' . $plugin_slug
    152 					);
    153 					$action = sprintf(
    154 						'<a href="%1$s" class="install-now" data-slug="%2$s" data-name="%3$s" aria-label="%4$s">%5$s</a>',
    155 						esc_url( $url ),
    156 						esc_attr( $plugin_slug ),
    157 						esc_attr( $data[0] ),
    158 						/* translators: %s: Importer name. */
    159 						esc_attr( sprintf( _x( 'Install %s now', 'plugin' ), $data[0] ) ),
    160 						__( 'Install Now' )
    161 					);
    162 				} else {
    163 					$action = sprintf(
    164 						/* translators: %s: URL to Import screen on the main site. */
    165 						__( 'This importer is not installed. Please install importers from <a href="%s">the main site</a>.' ),
    166 						get_admin_url( get_current_network_id(), 'import.php' )
    167 					);
    168 				}
    169 			}
    170 		} else {
    171 			$url    = add_query_arg(
    172 				array(
    173 					'import' => $importer_id,
    174 				),
    175 				self_admin_url( 'admin.php' )
    176 			);
    177 			$action = sprintf(
    178 				'<a href="%1$s" aria-label="%2$s">%3$s</a>',
    179 				esc_url( $url ),
    180 				/* translators: %s: Importer name. */
    181 				esc_attr( sprintf( __( 'Run %s' ), $data[0] ) ),
    182 				__( 'Run Importer' )
    183 			);
    184 
    185 			$is_plugin_installed = true;
    186 		}
    187 
    188 		if ( ! $is_plugin_installed && is_main_site() ) {
    189 			$url     = add_query_arg(
    190 				array(
    191 					'tab'       => 'plugin-information',
    192 					'plugin'    => $plugin_slug,
    193 					'from'      => 'import',
    194 					'TB_iframe' => 'true',
    195 					'width'     => 600,
    196 					'height'    => 550,
    197 				),
    198 				network_admin_url( 'plugin-install.php' )
    199 			);
    200 			$action .= sprintf(
    201 				' | <a href="%1$s" class="thickbox open-plugin-details-modal" aria-label="%2$s">%3$s</a>',
    202 				esc_url( $url ),
    203 				/* translators: %s: Importer name. */
    204 				esc_attr( sprintf( __( 'More information about %s' ), $data[0] ) ),
    205 				__( 'Details' )
    206 			);
    207 		}
    208 
    209 		echo "
    210 			<tr class='importer-item'>
    211 				<td class='import-system'>
    212 					<span class='importer-title'>{$data[0]}</span>
    213 					<span class='importer-action'>{$action}</span>
    214 				</td>
    215 				<td class='desc'>
    216 					<span class='importer-desc'>{$data[1]}</span>
    217 				</td>
    218 			</tr>";
    219 	}
    220 	?>
    221 </table>
    222 	<?php
    223 }
    224 
    225 if ( current_user_can( 'install_plugins' ) ) {
    226 	echo '<p>' . sprintf(
    227 		/* translators: %s: URL to Add Plugins screen. */
    228 		__( 'If the importer you need is not listed, <a href="%s">search the plugin directory</a> to see if an importer is available.' ),
    229 		esc_url( network_admin_url( 'plugin-install.php?tab=search&type=tag&s=importer' ) )
    230 	) . '</p>';
    231 }
    232 ?>
    233 
    234 </div>
    235 
    236 <?php
    237 wp_print_request_filesystem_credentials_modal();
    238 wp_print_admin_notice_templates();
    239 
    240 require_once ABSPATH . 'wp-admin/admin-footer.php';