[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/ -> import.php (source)

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


Generated : Tue Sep 15 08:20:32 2026 Cross-referenced by PHPXref