[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * WordPress Export Administration API
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * Version number for the export format.
  11   *
  12   * Bump this when something changes that might affect compatibility.
  13   *
  14   * @since 2.5.0
  15   */
  16  define( 'WXR_VERSION', '1.2' );
  17  
  18  /**
  19   * Generates the WXR export file for download.
  20   *
  21   * Default behavior is to export all content, however, note that post content will only
  22   * be exported for post types with the `can_export` argument enabled. Any posts with the
  23   * 'auto-draft' status will be skipped.
  24   *
  25   * @since 2.1.0
  26   *
  27   * @global wpdb    $wpdb WordPress database abstraction object.
  28   * @global WP_Post $post Global `$post`.
  29   *
  30   * @param array $args {
  31   *     Optional. Arguments for generating the WXR export file for download. Default empty array.
  32   *
  33   *     @type string $content        Type of content to export. If set, only the post content of this post type
  34   *                                  will be exported. Accepts 'all', 'post', 'page', 'attachment', or a defined
  35   *                                  custom post. If an invalid custom post type is supplied, every post type for
  36   *                                  which `can_export` is enabled will be exported instead. If a valid custom post
  37   *                                  type is supplied but `can_export` is disabled, then 'posts' will be exported
  38   *                                  instead. When 'all' is supplied, only post types with `can_export` enabled will
  39   *                                  be exported. Default 'all'.
  40   *     @type string $author         Author to export content for. Only used when `$content` is 'post', 'page', or
  41   *                                  'attachment'. Accepts false (all) or a specific author ID. Default false (all).
  42   *     @type string $category       Category (slug) to export content for. Used only when `$content` is 'post'. If
  43   *                                  set, only post content assigned to `$category` will be exported. Accepts false
  44   *                                  or a specific category slug. Default is false (all categories).
  45   *     @type string $start_date     Start date to export content from. Expected date format is 'Y-m-d'. Used only
  46   *                                  when `$content` is 'post', 'page' or 'attachment'. Default false (since the
  47   *                                  beginning of time).
  48   *     @type string $end_date       End date to export content to. Expected date format is 'Y-m-d'. Used only when
  49   *                                  `$content` is 'post', 'page' or 'attachment'. Default false (latest publish date).
  50   *     @type string $status         Post status to export posts for. Used only when `$content` is 'post' or 'page'.
  51   *                                  Accepts false (all statuses except 'auto-draft'), or a specific status, i.e.
  52   *                                  'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', or
  53   *                                  'trash'. Default false (all statuses except 'auto-draft').
  54   * }
  55   */
  56  function export_wp( $args = array() ) {
  57      global $wpdb, $post;
  58  
  59      $defaults = array(
  60          'content'    => 'all',
  61          'author'     => false,
  62          'category'   => false,
  63          'start_date' => false,
  64          'end_date'   => false,
  65          'status'     => false,
  66      );
  67      $args     = wp_parse_args( $args, $defaults );
  68  
  69      /**
  70       * Fires at the beginning of an export, before any headers are sent.
  71       *
  72       * @since 2.3.0
  73       *
  74       * @param array $args An array of export arguments.
  75       */
  76      do_action( 'export_wp', $args );
  77  
  78      $sitename = sanitize_key( get_bloginfo( 'name' ) );
  79      if ( ! empty( $sitename ) ) {
  80          $sitename .= '.';
  81      }
  82      $date        = gmdate( 'Y-m-d' );
  83      $wp_filename = $sitename . 'WordPress.' . $date . '.xml';
  84      /**
  85       * Filters the export filename.
  86       *
  87       * @since 4.4.0
  88       *
  89       * @param string $wp_filename The name of the file for download.
  90       * @param string $sitename    The site name.
  91       * @param string $date        Today's date, formatted.
  92       */
  93      $filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date );
  94  
  95      header( 'Content-Description: File Transfer' );
  96      header( 'Content-Disposition: attachment; filename=' . $filename );
  97      header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
  98  
  99      if ( 'all' != $args['content'] && post_type_exists( $args['content'] ) ) {
 100          $ptype = get_post_type_object( $args['content'] );
 101          if ( ! $ptype->can_export ) {
 102              $args['content'] = 'post';
 103          }
 104  
 105          $where = $wpdb->prepare( "{$wpdb->posts}.post_type = %s", $args['content'] );
 106      } else {
 107          $post_types = get_post_types( array( 'can_export' => true ) );
 108          $esses      = array_fill( 0, count( $post_types ), '%s' );
 109  
 110          // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
 111          $where = $wpdb->prepare( "{$wpdb->posts}.post_type IN (" . implode( ',', $esses ) . ')', $post_types );
 112      }
 113  
 114      if ( $args['status'] && ( 'post' == $args['content'] || 'page' == $args['content'] ) ) {
 115          $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_status = %s", $args['status'] );
 116      } else {
 117          $where .= " AND {$wpdb->posts}.post_status != 'auto-draft'";
 118      }
 119  
 120      $join = '';
 121      if ( $args['category'] && 'post' == $args['content'] ) {
 122          $term = term_exists( $args['category'], 'category' );
 123          if ( $term ) {
 124              $join   = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
 125              $where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
 126          }
 127      }
 128  
 129      if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) {
 130          if ( $args['author'] ) {
 131              $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
 132          }
 133  
 134          if ( $args['start_date'] ) {
 135              $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", gmdate( 'Y-m-d', strtotime( $args['start_date'] ) ) );
 136          }
 137  
 138          if ( $args['end_date'] ) {
 139              $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", gmdate( 'Y-m-d', strtotime( '+1 month', strtotime( $args['end_date'] ) ) ) );
 140          }
 141      }
 142  
 143      // Grab a snapshot of post IDs, just in case it changes during the export.
 144      $post_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
 145  
 146      /*
 147       * Get the requested terms ready, empty unless posts filtered by category
 148       * or all content.
 149       */
 150      $cats  = array();
 151      $tags  = array();
 152      $terms = array();
 153      if ( isset( $term ) && $term ) {
 154          $cat  = get_term( $term['term_id'], 'category' );
 155          $cats = array( $cat->term_id => $cat );
 156          unset( $term, $cat );
 157      } elseif ( 'all' == $args['content'] ) {
 158          $categories = (array) get_categories( array( 'get' => 'all' ) );
 159          $tags       = (array) get_tags( array( 'get' => 'all' ) );
 160  
 161          $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
 162          $custom_terms      = (array) get_terms( $custom_taxonomies, array( 'get' => 'all' ) );
 163  
 164          // Put categories in order with no child going before its parent.
 165          while ( $cat = array_shift( $categories ) ) {
 166              if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {
 167                  $cats[ $cat->term_id ] = $cat;
 168              } else {
 169                  $categories[] = $cat;
 170              }
 171          }
 172  
 173          // Put terms in order with no child going before its parent.
 174          while ( $t = array_shift( $custom_terms ) ) {
 175              if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {
 176                  $terms[ $t->term_id ] = $t;
 177              } else {
 178                  $custom_terms[] = $t;
 179              }
 180          }
 181  
 182          unset( $categories, $custom_taxonomies, $custom_terms );
 183      }
 184  
 185      /**
 186       * Wrap given string in XML CDATA tag.
 187       *
 188       * @since 2.1.0
 189       *
 190       * @param string $str String to wrap in XML CDATA tag.
 191       * @return string
 192       */
 193  	function wxr_cdata( $str ) {
 194          if ( ! seems_utf8( $str ) ) {
 195              $str = utf8_encode( $str );
 196          }
 197          // $str = ent2ncr(esc_html($str));
 198          $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
 199  
 200          return $str;
 201      }
 202  
 203      /**
 204       * Return the URL of the site
 205       *
 206       * @since 2.5.0
 207       *
 208       * @return string Site URL.
 209       */
 210  	function wxr_site_url() {
 211          if ( is_multisite() ) {
 212              // Multisite: the base URL.
 213              return network_home_url();
 214          } else {
 215              // WordPress (single site): the blog URL.
 216              return get_bloginfo_rss( 'url' );
 217          }
 218      }
 219  
 220      /**
 221       * Output a cat_name XML tag from a given category object
 222       *
 223       * @since 2.1.0
 224       *
 225       * @param object $category Category Object
 226       */
 227  	function wxr_cat_name( $category ) {
 228          if ( empty( $category->name ) ) {
 229              return;
 230          }
 231  
 232          echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
 233      }
 234  
 235      /**
 236       * Output a category_description XML tag from a given category object
 237       *
 238       * @since 2.1.0
 239       *
 240       * @param object $category Category Object
 241       */
 242  	function wxr_category_description( $category ) {
 243          if ( empty( $category->description ) ) {
 244              return;
 245          }
 246  
 247          echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
 248      }
 249  
 250      /**
 251       * Output a tag_name XML tag from a given tag object
 252       *
 253       * @since 2.3.0
 254       *
 255       * @param object $tag Tag Object
 256       */
 257  	function wxr_tag_name( $tag ) {
 258          if ( empty( $tag->name ) ) {
 259              return;
 260          }
 261  
 262          echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
 263      }
 264  
 265      /**
 266       * Output a tag_description XML tag from a given tag object
 267       *
 268       * @since 2.3.0
 269       *
 270       * @param object $tag Tag Object
 271       */
 272  	function wxr_tag_description( $tag ) {
 273          if ( empty( $tag->description ) ) {
 274              return;
 275          }
 276  
 277          echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
 278      }
 279  
 280      /**
 281       * Output a term_name XML tag from a given term object
 282       *
 283       * @since 2.9.0
 284       *
 285       * @param object $term Term Object
 286       */
 287  	function wxr_term_name( $term ) {
 288          if ( empty( $term->name ) ) {
 289              return;
 290          }
 291  
 292          echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
 293      }
 294  
 295      /**
 296       * Output a term_description XML tag from a given term object
 297       *
 298       * @since 2.9.0
 299       *
 300       * @param object $term Term Object
 301       */
 302  	function wxr_term_description( $term ) {
 303          if ( empty( $term->description ) ) {
 304              return;
 305          }
 306  
 307          echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
 308      }
 309  
 310      /**
 311       * Output term meta XML tags for a given term object.
 312       *
 313       * @since 4.6.0
 314       *
 315       * @param WP_Term $term Term object.
 316       */
 317  	function wxr_term_meta( $term ) {
 318          global $wpdb;
 319  
 320          $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
 321  
 322          foreach ( $termmeta as $meta ) {
 323              /**
 324               * Filters whether to selectively skip term meta used for WXR exports.
 325               *
 326               * Returning a truthy value to the filter will skip the current meta
 327               * object from being exported.
 328               *
 329               * @since 4.6.0
 330               *
 331               * @param bool   $skip     Whether to skip the current piece of term meta. Default false.
 332               * @param string $meta_key Current meta key.
 333               * @param object $meta     Current meta object.
 334               */
 335              if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) {
 336                  printf( "\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>%s</wp:meta_key>\n\t\t\t<wp:meta_value>%s</wp:meta_value>\n\t\t</wp:termmeta>\n", wxr_cdata( $meta->meta_key ), wxr_cdata( $meta->meta_value ) );
 337              }
 338          }
 339      }
 340  
 341      /**
 342       * Output list of authors with posts
 343       *
 344       * @since 3.1.0
 345       *
 346       * @global wpdb $wpdb WordPress database abstraction object.
 347       *
 348       * @param int[] $post_ids Optional. Array of post IDs to filter the query by.
 349       */
 350  	function wxr_authors_list( array $post_ids = null ) {
 351          global $wpdb;
 352  
 353          if ( ! empty( $post_ids ) ) {
 354              $post_ids = array_map( 'absint', $post_ids );
 355              $and      = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
 356          } else {
 357              $and = '';
 358          }
 359  
 360          $authors = array();
 361          $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
 362          foreach ( (array) $results as $result ) {
 363              $authors[] = get_userdata( $result->post_author );
 364          }
 365  
 366          $authors = array_filter( $authors );
 367  
 368          foreach ( $authors as $author ) {
 369              echo "\t<wp:author>";
 370              echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
 371              echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
 372              echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
 373              echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
 374              echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
 375              echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
 376              echo "</wp:author>\n";
 377          }
 378      }
 379  
 380      /**
 381       * Output all navigation menu terms
 382       *
 383       * @since 3.1.0
 384       */
 385  	function wxr_nav_menu_terms() {
 386          $nav_menus = wp_get_nav_menus();
 387          if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) {
 388              return;
 389          }
 390  
 391          foreach ( $nav_menus as $menu ) {
 392              echo "\t<wp:term>";
 393              echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>';
 394              echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>';
 395              echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>';
 396              wxr_term_name( $menu );
 397              echo "</wp:term>\n";
 398          }
 399      }
 400  
 401      /**
 402       * Output list of taxonomy terms, in XML tag format, associated with a post
 403       *
 404       * @since 2.3.0
 405       */
 406  	function wxr_post_taxonomy() {
 407          $post = get_post();
 408  
 409          $taxonomies = get_object_taxonomies( $post->post_type );
 410          if ( empty( $taxonomies ) ) {
 411              return;
 412          }
 413          $terms = wp_get_object_terms( $post->ID, $taxonomies );
 414  
 415          foreach ( (array) $terms as $term ) {
 416              echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
 417          }
 418      }
 419  
 420      /**
 421       * @param bool   $return_me
 422       * @param string $meta_key
 423       * @return bool
 424       */
 425  	function wxr_filter_postmeta( $return_me, $meta_key ) {
 426          if ( '_edit_lock' == $meta_key ) {
 427              $return_me = true;
 428          }
 429          return $return_me;
 430      }
 431      add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 );
 432  
 433      echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n";
 434  
 435      ?>
 436  <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
 437  <!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
 438  <!-- You may use this file to transfer that content from one site to another. -->
 439  <!-- This file is not intended to serve as a complete backup of your site. -->
 440  
 441  <!-- To import this information into a WordPress site follow these steps: -->
 442  <!-- 1. Log in to that site as an administrator. -->
 443  <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
 444  <!-- 3. Install the "WordPress" importer from the list. -->
 445  <!-- 4. Activate & Run Importer. -->
 446  <!-- 5. Upload this file using the form provided on that page. -->
 447  <!-- 6. You will first be asked to map the authors in this export file to users -->
 448  <!--    on the site. For each author, you may choose to map to an -->
 449  <!--    existing user on the site or to create a new user. -->
 450  <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
 451  <!--    contained in this file into your site. -->
 452  
 453      <?php the_generator( 'export' ); ?>
 454  <rss version="2.0"
 455      xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
 456      xmlns:content="http://purl.org/rss/1.0/modules/content/"
 457      xmlns:wfw="http://wellformedweb.org/CommentAPI/"
 458      xmlns:dc="http://purl.org/dc/elements/1.1/"
 459      xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
 460  >
 461  
 462  <channel>
 463      <title><?php bloginfo_rss( 'name' ); ?></title>
 464      <link><?php bloginfo_rss( 'url' ); ?></link>
 465      <description><?php bloginfo_rss( 'description' ); ?></description>
 466      <pubDate><?php echo gmdate( 'D, d M Y H:i:s +0000' ); ?></pubDate>
 467      <language><?php bloginfo_rss( 'language' ); ?></language>
 468      <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
 469      <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
 470      <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
 471  
 472      <?php wxr_authors_list( $post_ids ); ?>
 473  
 474      <?php foreach ( $cats as $c ) : ?>
 475      <wp:category>
 476          <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
 477          <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
 478          <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent>
 479          <?php
 480          wxr_cat_name( $c );
 481          wxr_category_description( $c );
 482          wxr_term_meta( $c );
 483          ?>
 484      </wp:category>
 485      <?php endforeach; ?>
 486      <?php foreach ( $tags as $t ) : ?>
 487      <wp:tag>
 488          <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
 489          <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
 490          <?php
 491          wxr_tag_name( $t );
 492          wxr_tag_description( $t );
 493          wxr_term_meta( $t );
 494          ?>
 495      </wp:tag>
 496      <?php endforeach; ?>
 497      <?php foreach ( $terms as $t ) : ?>
 498      <wp:term>
 499          <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
 500          <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
 501          <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
 502          <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ); ?></wp:term_parent>
 503          <?php
 504          wxr_term_name( $t );
 505          wxr_term_description( $t );
 506          wxr_term_meta( $t );
 507          ?>
 508      </wp:term>
 509      <?php endforeach; ?>
 510      <?php
 511      if ( 'all' == $args['content'] ) {
 512          wxr_nav_menu_terms();}
 513      ?>
 514  
 515      <?php
 516      /** This action is documented in wp-includes/feed-rss2.php */
 517      do_action( 'rss2_head' );
 518      ?>
 519  
 520      <?php
 521      if ( $post_ids ) {
 522          /**
 523           * @global WP_Query $wp_query
 524           */
 525          global $wp_query;
 526  
 527          // Fake being in the loop.
 528          $wp_query->in_the_loop = true;
 529  
 530          // Fetch 20 posts at a time rather than loading the entire table into memory.
 531          while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
 532              $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
 533              $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
 534  
 535              // Begin Loop.
 536              foreach ( $posts as $post ) {
 537                  setup_postdata( $post );
 538  
 539                  /** This filter is documented in wp-includes/feed.php */
 540                  $title = apply_filters( 'the_title_rss', $post->post_title );
 541  
 542                  /**
 543                   * Filters the post content used for WXR exports.
 544                   *
 545                   * @since 2.5.0
 546                   *
 547                   * @param string $post_content Content of the current post.
 548                   */
 549                  $content = wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
 550  
 551                  /**
 552                   * Filters the post excerpt used for WXR exports.
 553                   *
 554                   * @since 2.6.0
 555                   *
 556                   * @param string $post_excerpt Excerpt for the current post.
 557                   */
 558                  $excerpt = wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
 559  
 560                  $is_sticky = is_sticky( $post->ID ) ? 1 : 0;
 561                  ?>
 562      <item>
 563          <title><?php echo $title; ?></title>
 564          <link><?php the_permalink_rss(); ?></link>
 565          <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
 566          <dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator>
 567          <guid isPermaLink="false"><?php the_guid(); ?></guid>
 568          <description></description>
 569          <content:encoded><?php echo $content; ?></content:encoded>
 570          <excerpt:encoded><?php echo $excerpt; ?></excerpt:encoded>
 571          <wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id>
 572          <wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date>
 573          <wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt>
 574          <wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status>
 575          <wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status>
 576          <wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name>
 577          <wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status>
 578          <wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent>
 579          <wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order>
 580          <wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type>
 581          <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password>
 582          <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky>
 583                  <?php    if ( $post->post_type == 'attachment' ) : ?>
 584          <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url>
 585      <?php endif; ?>
 586                  <?php wxr_post_taxonomy(); ?>
 587                  <?php
 588                  $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
 589                  foreach ( $postmeta as $meta ) :
 590                      /**
 591                       * Filters whether to selectively skip post meta used for WXR exports.
 592                       *
 593                       * Returning a truthy value to the filter will skip the current meta
 594                       * object from being exported.
 595                       *
 596                       * @since 3.3.0
 597                       *
 598                       * @param bool   $skip     Whether to skip the current post meta. Default false.
 599                       * @param string $meta_key Current meta key.
 600                       * @param object $meta     Current meta object.
 601                       */
 602                      if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
 603                          continue;
 604                      }
 605                      ?>
 606          <wp:postmeta>
 607          <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
 608          <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
 609          </wp:postmeta>
 610                      <?php
 611      endforeach;
 612  
 613                  $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
 614                  $comments  = array_map( 'get_comment', $_comments );
 615                  foreach ( $comments as $c ) :
 616                      ?>
 617          <wp:comment>
 618              <wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id>
 619              <wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
 620              <wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email>
 621              <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
 622              <wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP>
 623              <wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date>
 624              <wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt>
 625              <wp:comment_content><?php echo wxr_cdata( $c->comment_content ); ?></wp:comment_content>
 626              <wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved>
 627              <wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type>
 628              <wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent>
 629              <wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id>
 630                      <?php
 631                      $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
 632                      foreach ( $c_meta as $meta ) :
 633                          /**
 634                           * Filters whether to selectively skip comment meta used for WXR exports.
 635                           *
 636                           * Returning a truthy value to the filter will skip the current meta
 637                           * object from being exported.
 638                           *
 639                           * @since 4.0.0
 640                           *
 641                           * @param bool   $skip     Whether to skip the current comment meta. Default false.
 642                           * @param string $meta_key Current meta key.
 643                           * @param object $meta     Current meta object.
 644                           */
 645                          if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
 646                              continue;
 647                          }
 648                          ?>
 649      <wp:commentmeta>
 650      <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
 651              <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
 652              </wp:commentmeta>
 653                      <?php    endforeach; ?>
 654          </wp:comment>
 655              <?php    endforeach; ?>
 656          </item>
 657                  <?php
 658              }
 659          }
 660      }
 661      ?>
 662  </channel>
 663  </rss>
 664      <?php
 665  }


Generated: Wed Jul 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1