[ Index ]

PHP Cross Reference of WordPress

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


Generated: Tue Sep 21 01:00:05 2021 Cross-referenced by PHPXref 0.7.1