[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  <?php
   2  /**
   3   * WordPress Export Administration Screen
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** Load WordPress Bootstrap */
  10  require_once  __DIR__ . '/admin.php';
  11  
  12  if ( ! current_user_can( 'export' ) ) {
  13      wp_die( __( 'Sorry, you are not allowed to export the content of this site.' ) );
  14  }
  15  
  16  /** Load WordPress export API */
  17  require_once  ABSPATH . 'wp-admin/includes/export.php';
  18  
  19  // Used in the HTML title tag.
  20  $title = __( 'Export' );
  21  
  22  /**
  23   * Display JavaScript on the page.
  24   *
  25   * @since 3.5.0
  26   */
  27  function export_add_js() {
  28      ?>
  29  <script type="text/javascript">
  30      jQuery( function($) {
  31          var form = $('#export-filters'),
  32              filters = form.find('.export-filters');
  33          filters.hide();
  34          form.find('input:radio').on( 'change', function() {
  35              filters.slideUp('fast');
  36              switch ( $(this).val() ) {
  37                  case 'attachment': $('#attachment-filters').slideDown(); break;
  38                  case 'posts': $('#post-filters').slideDown(); break;
  39                  case 'pages': $('#page-filters').slideDown(); break;
  40              }
  41          });
  42      } );
  43  </script>
  44      <?php
  45  }
  46  add_action( 'admin_head', 'export_add_js' );
  47  
  48  get_current_screen()->add_help_tab(
  49      array(
  50          'id'      => 'overview',
  51          'title'   => __( 'Overview' ),
  52          'content' => '<p>' . __( 'You can export a file of your site&#8217;s content in order to import it into another installation or platform. The export file will be an XML file format called WXR. Posts, pages, comments, custom fields, categories, and tags can be included. You can choose for the WXR file to include only certain posts or pages by setting the dropdown filters to limit the export by category, author, date range by month, or publishing status.' ) . '</p>' .
  53              '<p>' . __( 'Once generated, your WXR file can be imported by another WordPress site or by another blogging platform able to access this format.' ) . '</p>',
  54      )
  55  );
  56  
  57  get_current_screen()->set_help_sidebar(
  58      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  59      '<p>' . __( '<a href="https://wordpress.org/documentation/article/tools-export-screen/">Documentation on Export</a>' ) . '</p>' .
  60      '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
  61  );
  62  
  63  // If the 'download' URL parameter is set, a WXR export file is baked and returned.
  64  if ( isset( $_GET['download'] ) ) {
  65      $args = array();
  66  
  67      if ( ! isset( $_GET['content'] ) || 'all' === $_GET['content'] ) {
  68          $args['content'] = 'all';
  69      } elseif ( 'posts' === $_GET['content'] ) {
  70          $args['content'] = 'post';
  71  
  72          if ( $_GET['cat'] ) {
  73              $args['category'] = (int) $_GET['cat'];
  74          }
  75  
  76          if ( $_GET['post_author'] ) {
  77              $args['author'] = (int) $_GET['post_author'];
  78          }
  79  
  80          if ( $_GET['post_start_date'] || $_GET['post_end_date'] ) {
  81              $args['start_date'] = $_GET['post_start_date'];
  82              $args['end_date']   = $_GET['post_end_date'];
  83          }
  84  
  85          if ( $_GET['post_status'] ) {
  86              $args['status'] = $_GET['post_status'];
  87          }
  88      } elseif ( 'pages' === $_GET['content'] ) {
  89          $args['content'] = 'page';
  90  
  91          if ( $_GET['page_author'] ) {
  92              $args['author'] = (int) $_GET['page_author'];
  93          }
  94  
  95          if ( $_GET['page_start_date'] || $_GET['page_end_date'] ) {
  96              $args['start_date'] = $_GET['page_start_date'];
  97              $args['end_date']   = $_GET['page_end_date'];
  98          }
  99  
 100          if ( $_GET['page_status'] ) {
 101              $args['status'] = $_GET['page_status'];
 102          }
 103      } elseif ( 'attachment' === $_GET['content'] ) {
 104          $args['content'] = 'attachment';
 105  
 106          if ( $_GET['attachment_start_date'] || $_GET['attachment_end_date'] ) {
 107              $args['start_date'] = $_GET['attachment_start_date'];
 108              $args['end_date']   = $_GET['attachment_end_date'];
 109          }
 110      } else {
 111          $args['content'] = $_GET['content'];
 112      }
 113  
 114      /**
 115       * Filters the export args.
 116       *
 117       * @since 3.5.0
 118       *
 119       * @param array $args The arguments to send to the exporter.
 120       */
 121      $args = apply_filters( 'export_args', $args );
 122  
 123      export_wp( $args );
 124      die();
 125  }
 126  
 127  require_once  ABSPATH . 'wp-admin/admin-header.php';
 128  
 129  /**
 130   * Creates the date options fields for exporting a given post type.
 131   *
 132   * @global wpdb      $wpdb      WordPress database abstraction object.
 133   * @global WP_Locale $wp_locale WordPress date and time locale object.
 134   *
 135   * @since 3.1.0
 136   *
 137   * @param string $post_type The post type. Default 'post'.
 138   */
 139  function export_date_options( $post_type = 'post' ) {
 140      global $wpdb, $wp_locale;
 141  
 142      $months = $wpdb->get_results(
 143          $wpdb->prepare(
 144              "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
 145              FROM $wpdb->posts
 146              WHERE post_type = %s AND post_status != 'auto-draft'
 147              ORDER BY post_date DESC",
 148              $post_type
 149          )
 150      );
 151  
 152      $month_count = count( $months );
 153      if ( ! $month_count || ( 1 === $month_count && 0 === (int) $months[0]->month ) ) {
 154          return;
 155      }
 156  
 157      foreach ( $months as $date ) {
 158          if ( 0 === (int) $date->year ) {
 159              continue;
 160          }
 161  
 162          $month = zeroise( $date->month, 2 );
 163  
 164          printf(
 165              '<option value="%1$s">%2$s</option>',
 166              esc_attr( $date->year . '-' . $month ),
 167              $wp_locale->get_month( $month ) . ' ' . $date->year
 168          );
 169      }
 170  }
 171  ?>
 172  
 173  <div class="wrap">
 174  <h1><?php echo esc_html( $title ); ?></h1>
 175  
 176  <p><?php _e( 'When you click the button below WordPress will create an XML file for you to save to your computer.' ); ?></p>
 177  <p><?php _e( 'This format, which is called WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.' ); ?></p>
 178  <p><?php _e( 'Once you&#8217;ve saved the download file, you can use the Import function in another WordPress installation to import the content from this site.' ); ?></p>
 179  
 180  <h2><?php _e( 'Choose what to export' ); ?></h2>
 181  <form method="get" id="export-filters">
 182  <fieldset>
 183  <legend class="screen-reader-text">
 184      <?php
 185      /* translators: Hidden accessibility text. */
 186      _e( 'Content to export' );
 187      ?>
 188  </legend>
 189  <input type="hidden" name="download" value="true" />
 190  <p><label><input type="radio" name="content" value="all" checked="checked" aria-describedby="all-content-desc" /> <?php _e( 'All content' ); ?></label></p>
 191  <p class="description" id="all-content-desc"><?php _e( 'This will contain all of your posts, pages, comments, custom fields, terms, navigation menus, and custom posts.' ); ?></p>
 192  
 193  <p><label><input type="radio" name="content" value="posts" /> <?php _ex( 'Posts', 'post type general name' ); ?></label></p>
 194  <ul id="post-filters" class="export-filters">
 195      <li>
 196          <label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span>
 197          <?php wp_dropdown_categories( array( 'show_option_all' => __( 'All' ) ) ); ?>
 198          </label>
 199      </li>
 200      <li>
 201          <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
 202          <?php
 203          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
 204          wp_dropdown_users(
 205              array(
 206                  'include'         => $authors,
 207                  'name'            => 'post_author',
 208                  'multi'           => true,
 209                  'show_option_all' => __( 'All' ),
 210                  'show'            => 'display_name_with_login',
 211              )
 212          );
 213          ?>
 214          </label>
 215      </li>
 216      <li>
 217          <fieldset>
 218          <legend class="screen-reader-text">
 219              <?php
 220              /* translators: Hidden accessibility text. */
 221              _e( 'Date range:' )
 222              ?>
 223          </legend>
 224          <label for="post-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 225          <select name="post_start_date" id="post-start-date">
 226              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 227              <?php export_date_options(); ?>
 228          </select>
 229          <label for="post-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 230          <select name="post_end_date" id="post-end-date">
 231              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 232              <?php export_date_options(); ?>
 233          </select>
 234          </fieldset>
 235      </li>
 236      <li>
 237          <label for="post-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
 238          <select name="post_status" id="post-status">
 239              <option value="0"><?php _e( 'All' ); ?></option>
 240              <?php
 241              $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
 242              foreach ( $post_stati as $status ) :
 243                  ?>
 244              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 245              <?php endforeach; ?>
 246          </select>
 247      </li>
 248  </ul>
 249  
 250  <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
 251  <ul id="page-filters" class="export-filters">
 252      <li>
 253          <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
 254          <?php
 255          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
 256          wp_dropdown_users(
 257              array(
 258                  'include'         => $authors,
 259                  'name'            => 'page_author',
 260                  'multi'           => true,
 261                  'show_option_all' => __( 'All' ),
 262                  'show'            => 'display_name_with_login',
 263              )
 264          );
 265          ?>
 266          </label>
 267      </li>
 268      <li>
 269          <fieldset>
 270          <legend class="screen-reader-text">
 271              <?php
 272              /* translators: Hidden accessibility text. */
 273              _e( 'Date range:' );
 274              ?>
 275          </legend>
 276          <label for="page-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 277          <select name="page_start_date" id="page-start-date">
 278              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 279              <?php export_date_options( 'page' ); ?>
 280          </select>
 281          <label for="page-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 282          <select name="page_end_date" id="page-end-date">
 283              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 284              <?php export_date_options( 'page' ); ?>
 285          </select>
 286          </fieldset>
 287      </li>
 288      <li>
 289          <label for="page-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
 290          <select name="page_status" id="page-status">
 291              <option value="0"><?php _e( 'All' ); ?></option>
 292              <?php foreach ( $post_stati as $status ) : ?>
 293              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 294              <?php endforeach; ?>
 295          </select>
 296      </li>
 297  </ul>
 298  
 299  <?php
 300  foreach ( get_post_types(
 301      array(
 302          '_builtin'   => false,
 303          'can_export' => true,
 304      ),
 305      'objects'
 306  ) as $post_type ) :
 307      ?>
 308  <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
 309  <?php endforeach; ?>
 310  
 311  <p><label><input type="radio" name="content" value="attachment" /> <?php _e( 'Media' ); ?></label></p>
 312  <ul id="attachment-filters" class="export-filters">
 313      <li>
 314          <fieldset>
 315          <legend class="screen-reader-text">
 316              <?php
 317              /* translators: Hidden accessibility text. */
 318              _e( 'Date range:' );
 319              ?>
 320          </legend>
 321          <label for="attachment-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 322          <select name="attachment_start_date" id="attachment-start-date">
 323              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 324              <?php export_date_options( 'attachment' ); ?>
 325          </select>
 326          <label for="attachment-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 327          <select name="attachment_end_date" id="attachment-end-date">
 328              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 329              <?php export_date_options( 'attachment' ); ?>
 330          </select>
 331          </fieldset>
 332      </li>
 333  </ul>
 334  
 335  </fieldset>
 336  <?php
 337  /**
 338   * Fires at the end of the export filters form.
 339   *
 340   * @since 3.5.0
 341   */
 342  do_action( 'export_filters' );
 343  ?>
 344  
 345  <?php submit_button( __( 'Download Export File' ) ); ?>
 346  </form>
 347  </div>
 348  
 349  <?php require_once  ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated : Fri Apr 26 08:20:02 2024 Cross-referenced by PHPXref