[ Index ]

PHP Cross Reference of WordPress

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/support/article/tools-export-screen/">Documentation on Export</a>' ) . '</p>' .
  60      '<p>' . __( '<a href="https://wordpress.org/support/">Support</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   * Create 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              "
 145          SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
 146          FROM $wpdb->posts
 147          WHERE post_type = %s AND post_status != 'auto-draft'
 148          ORDER BY post_date DESC
 149              ",
 150              $post_type
 151          )
 152      );
 153  
 154      $month_count = count( $months );
 155      if ( ! $month_count || ( 1 === $month_count && 0 === (int) $months[0]->month ) ) {
 156          return;
 157      }
 158  
 159      foreach ( $months as $date ) {
 160          if ( 0 === (int) $date->year ) {
 161              continue;
 162          }
 163  
 164          $month = zeroise( $date->month, 2 );
 165          echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
 166      }
 167  }
 168  ?>
 169  
 170  <div class="wrap">
 171  <h1><?php echo esc_html( $title ); ?></h1>
 172  
 173  <p><?php _e( 'When you click the button below WordPress will create an XML file for you to save to your computer.' ); ?></p>
 174  <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>
 175  <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>
 176  
 177  <h2><?php _e( 'Choose what to export' ); ?></h2>
 178  <form method="get" id="export-filters">
 179  <fieldset>
 180  <legend class="screen-reader-text"><?php _e( 'Content to export' ); ?></legend>
 181  <input type="hidden" name="download" value="true" />
 182  <p><label><input type="radio" name="content" value="all" checked="checked" aria-describedby="all-content-desc" /> <?php _e( 'All content' ); ?></label></p>
 183  <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>
 184  
 185  <p><label><input type="radio" name="content" value="posts" /> <?php _ex( 'Posts', 'post type general name' ); ?></label></p>
 186  <ul id="post-filters" class="export-filters">
 187      <li>
 188          <label><span class="label-responsive"><?php _e( 'Categories:' ); ?></span>
 189          <?php wp_dropdown_categories( array( 'show_option_all' => __( 'All' ) ) ); ?>
 190          </label>
 191      </li>
 192      <li>
 193          <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
 194          <?php
 195          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'post'" );
 196          wp_dropdown_users(
 197              array(
 198                  'include'         => $authors,
 199                  'name'            => 'post_author',
 200                  'multi'           => true,
 201                  'show_option_all' => __( 'All' ),
 202                  'show'            => 'display_name_with_login',
 203              )
 204          );
 205          ?>
 206          </label>
 207      </li>
 208      <li>
 209          <fieldset>
 210          <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
 211          <label for="post-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 212          <select name="post_start_date" id="post-start-date">
 213              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 214              <?php export_date_options(); ?>
 215          </select>
 216          <label for="post-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 217          <select name="post_end_date" id="post-end-date">
 218              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 219              <?php export_date_options(); ?>
 220          </select>
 221          </fieldset>
 222      </li>
 223      <li>
 224          <label for="post-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
 225          <select name="post_status" id="post-status">
 226              <option value="0"><?php _e( 'All' ); ?></option>
 227              <?php
 228              $post_stati = get_post_stati( array( 'internal' => false ), 'objects' );
 229              foreach ( $post_stati as $status ) :
 230                  ?>
 231              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 232              <?php endforeach; ?>
 233          </select>
 234      </li>
 235  </ul>
 236  
 237  <p><label><input type="radio" name="content" value="pages" /> <?php _e( 'Pages' ); ?></label></p>
 238  <ul id="page-filters" class="export-filters">
 239      <li>
 240          <label><span class="label-responsive"><?php _e( 'Authors:' ); ?></span>
 241          <?php
 242          $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = 'page'" );
 243          wp_dropdown_users(
 244              array(
 245                  'include'         => $authors,
 246                  'name'            => 'page_author',
 247                  'multi'           => true,
 248                  'show_option_all' => __( 'All' ),
 249                  'show'            => 'display_name_with_login',
 250              )
 251          );
 252          ?>
 253          </label>
 254      </li>
 255      <li>
 256          <fieldset>
 257          <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
 258          <label for="page-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 259          <select name="page_start_date" id="page-start-date">
 260              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 261              <?php export_date_options( 'page' ); ?>
 262          </select>
 263          <label for="page-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 264          <select name="page_end_date" id="page-end-date">
 265              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 266              <?php export_date_options( 'page' ); ?>
 267          </select>
 268          </fieldset>
 269      </li>
 270      <li>
 271          <label for="page-status" class="label-responsive"><?php _e( 'Status:' ); ?></label>
 272          <select name="page_status" id="page-status">
 273              <option value="0"><?php _e( 'All' ); ?></option>
 274              <?php foreach ( $post_stati as $status ) : ?>
 275              <option value="<?php echo esc_attr( $status->name ); ?>"><?php echo esc_html( $status->label ); ?></option>
 276              <?php endforeach; ?>
 277          </select>
 278      </li>
 279  </ul>
 280  
 281  <?php
 282  foreach ( get_post_types(
 283      array(
 284          '_builtin'   => false,
 285          'can_export' => true,
 286      ),
 287      'objects'
 288  ) as $post_type ) :
 289      ?>
 290  <p><label><input type="radio" name="content" value="<?php echo esc_attr( $post_type->name ); ?>" /> <?php echo esc_html( $post_type->label ); ?></label></p>
 291  <?php endforeach; ?>
 292  
 293  <p><label><input type="radio" name="content" value="attachment" /> <?php _e( 'Media' ); ?></label></p>
 294  <ul id="attachment-filters" class="export-filters">
 295      <li>
 296          <fieldset>
 297          <legend class="screen-reader-text"><?php _e( 'Date range:' ); ?></legend>
 298          <label for="attachment-start-date" class="label-responsive"><?php _e( 'Start date:' ); ?></label>
 299          <select name="attachment_start_date" id="attachment-start-date">
 300              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 301              <?php export_date_options( 'attachment' ); ?>
 302          </select>
 303          <label for="attachment-end-date" class="label-responsive"><?php _e( 'End date:' ); ?></label>
 304          <select name="attachment_end_date" id="attachment-end-date">
 305              <option value="0"><?php _e( '&mdash; Select &mdash;' ); ?></option>
 306              <?php export_date_options( 'attachment' ); ?>
 307          </select>
 308          </fieldset>
 309      </li>
 310  </ul>
 311  
 312  </fieldset>
 313  <?php
 314  /**
 315   * Fires at the end of the export filters form.
 316   *
 317   * @since 3.5.0
 318   */
 319  do_action( 'export_filters' );
 320  ?>
 321  
 322  <?php submit_button( __( 'Download Export File' ) ); ?>
 323  </form>
 324  </div>
 325  
 326  <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1