[ 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 object.
  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(
 163              array(
 164                  'taxonomy' => $custom_taxonomies,
 165                  'get'      => 'all',
 166              )
 167          );
 168  
 169          // Put categories in order with no child going before its parent.
 170          while ( $cat = array_shift( $categories ) ) {
 171              if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {
 172                  $cats[ $cat->term_id ] = $cat;
 173              } else {
 174                  $categories[] = $cat;
 175              }
 176          }
 177  
 178          // Put terms in order with no child going before its parent.
 179          while ( $t = array_shift( $custom_terms ) ) {
 180              if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {
 181                  $terms[ $t->term_id ] = $t;
 182              } else {
 183                  $custom_terms[] = $t;
 184              }
 185          }
 186  
 187          unset( $categories, $custom_taxonomies, $custom_terms );
 188      }
 189  
 190      /**
 191       * Wrap given string in XML CDATA tag.
 192       *
 193       * @since 2.1.0
 194       *
 195       * @param string $str String to wrap in XML CDATA tag.
 196       * @return string
 197       */
 198  	function wxr_cdata( $str ) {
 199          if ( ! seems_utf8( $str ) ) {
 200              $str = utf8_encode( $str );
 201          }
 202          // $str = ent2ncr(esc_html($str));
 203          $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
 204  
 205          return $str;
 206      }
 207  
 208      /**
 209       * Return the URL of the site
 210       *
 211       * @since 2.5.0
 212       *
 213       * @return string Site URL.
 214       */
 215  	function wxr_site_url() {
 216          if ( is_multisite() ) {
 217              // Multisite: the base URL.
 218              return network_home_url();
 219          } else {
 220              // WordPress (single site): the blog URL.
 221              return get_bloginfo_rss( 'url' );
 222          }
 223      }
 224  
 225      /**
 226       * Output a cat_name XML tag from a given category object
 227       *
 228       * @since 2.1.0
 229       *
 230       * @param object $category Category Object
 231       */
 232  	function wxr_cat_name( $category ) {
 233          if ( empty( $category->name ) ) {
 234              return;
 235          }
 236  
 237          echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
 238      }
 239  
 240      /**
 241       * Output a category_description XML tag from a given category object
 242       *
 243       * @since 2.1.0
 244       *
 245       * @param object $category Category Object
 246       */
 247  	function wxr_category_description( $category ) {
 248          if ( empty( $category->description ) ) {
 249              return;
 250          }
 251  
 252          echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
 253      }
 254  
 255      /**
 256       * Output a tag_name XML tag from a given tag object
 257       *
 258       * @since 2.3.0
 259       *
 260       * @param object $tag Tag Object
 261       */
 262  	function wxr_tag_name( $tag ) {
 263          if ( empty( $tag->name ) ) {
 264              return;
 265          }
 266  
 267          echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
 268      }
 269  
 270      /**
 271       * Output a tag_description XML tag from a given tag object
 272       *
 273       * @since 2.3.0
 274       *
 275       * @param object $tag Tag Object
 276       */
 277  	function wxr_tag_description( $tag ) {
 278          if ( empty( $tag->description ) ) {
 279              return;
 280          }
 281  
 282          echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
 283      }
 284  
 285      /**
 286       * Output a term_name XML tag from a given term object
 287       *
 288       * @since 2.9.0
 289       *
 290       * @param object $term Term Object
 291       */
 292  	function wxr_term_name( $term ) {
 293          if ( empty( $term->name ) ) {
 294              return;
 295          }
 296  
 297          echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
 298      }
 299  
 300      /**
 301       * Output a term_description XML tag from a given term object
 302       *
 303       * @since 2.9.0
 304       *
 305       * @param object $term Term Object
 306       */
 307  	function wxr_term_description( $term ) {
 308          if ( empty( $term->description ) ) {
 309              return;
 310          }
 311  
 312          echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
 313      }
 314  
 315      /**
 316       * Output term meta XML tags for a given term object.
 317       *
 318       * @since 4.6.0
 319       *
 320       * @param WP_Term $term Term object.
 321       */
 322  	function wxr_term_meta( $term ) {
 323          global $wpdb;
 324  
 325          $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
 326  
 327          foreach ( $termmeta as $meta ) {
 328              /**
 329               * Filters whether to selectively skip term meta used for WXR exports.
 330               *
 331               * Returning a truthy value to the filter will skip the current meta
 332               * object from being exported.
 333               *
 334               * @since 4.6.0
 335               *
 336               * @param bool   $skip     Whether to skip the current piece of term meta. Default false.
 337               * @param string $meta_key Current meta key.
 338               * @param object $meta     Current meta object.
 339               */
 340              if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) {
 341                  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 ) );
 342              }
 343          }
 344      }
 345  
 346      /**
 347       * Output list of authors with posts
 348       *
 349       * @since 3.1.0
 350       *
 351       * @global wpdb $wpdb WordPress database abstraction object.
 352       *
 353       * @param int[] $post_ids Optional. Array of post IDs to filter the query by.
 354       */
 355  	function wxr_authors_list( array $post_ids = null ) {
 356          global $wpdb;
 357  
 358          if ( ! empty( $post_ids ) ) {
 359              $post_ids = array_map( 'absint', $post_ids );
 360              $and      = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
 361          } else {
 362              $and = '';
 363          }
 364  
 365          $authors = array();
 366          $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
 367          foreach ( (array) $results as $result ) {
 368              $authors[] = get_userdata( $result->post_author );
 369          }
 370  
 371          $authors = array_filter( $authors );
 372  
 373          foreach ( $authors as $author ) {
 374              echo "\t<wp:author>";
 375              echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
 376              echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
 377              echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
 378              echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
 379              echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
 380              echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
 381              echo "</wp:author>\n";
 382          }
 383      }
 384  
 385      /**
 386       * Output all navigation menu terms
 387       *
 388       * @since 3.1.0
 389       */
 390  	function wxr_nav_menu_terms() {
 391          $nav_menus = wp_get_nav_menus();
 392          if ( empty( $nav_menus ) || ! is_array( $nav_menus ) ) {
 393              return;
 394          }
 395  
 396          foreach ( $nav_menus as $menu ) {
 397              echo "\t<wp:term>";
 398              echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>';
 399              echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>';
 400              echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>';
 401              wxr_term_name( $menu );
 402              echo "</wp:term>\n";
 403          }
 404      }
 405  
 406      /**
 407       * Output list of taxonomy terms, in XML tag format, associated with a post
 408       *
 409       * @since 2.3.0
 410       */
 411  	function wxr_post_taxonomy() {
 412          $post = get_post();
 413  
 414          $taxonomies = get_object_taxonomies( $post->post_type );
 415          if ( empty( $taxonomies ) ) {
 416              return;
 417          }
 418          $terms = wp_get_object_terms( $post->ID, $taxonomies );
 419  
 420          foreach ( (array) $terms as $term ) {
 421              echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
 422          }
 423      }
 424  
 425      /**
 426       * @param bool   $return_me
 427       * @param string $meta_key
 428       * @return bool
 429       */
 430  	function wxr_filter_postmeta( $return_me, $meta_key ) {
 431          if ( '_edit_lock' == $meta_key ) {
 432              $return_me = true;
 433          }
 434          return $return_me;
 435      }
 436      add_filter( 'wxr_export_skip_postmeta', 'wxr_filter_postmeta', 10, 2 );
 437  
 438      echo '<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n";
 439  
 440      ?>
 441  <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
 442  <!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
 443  <!-- You may use this file to transfer that content from one site to another. -->
 444  <!-- This file is not intended to serve as a complete backup of your site. -->
 445  
 446  <!-- To import this information into a WordPress site follow these steps: -->
 447  <!-- 1. Log in to that site as an administrator. -->
 448  <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
 449  <!-- 3. Install the "WordPress" importer from the list. -->
 450  <!-- 4. Activate & Run Importer. -->
 451  <!-- 5. Upload this file using the form provided on that page. -->
 452  <!-- 6. You will first be asked to map the authors in this export file to users -->
 453  <!--    on the site. For each author, you may choose to map to an -->
 454  <!--    existing user on the site or to create a new user. -->
 455  <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
 456  <!--    contained in this file into your site. -->
 457  
 458      <?php the_generator( 'export' ); ?>
 459  <rss version="2.0"
 460      xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
 461      xmlns:content="http://purl.org/rss/1.0/modules/content/"
 462      xmlns:wfw="http://wellformedweb.org/CommentAPI/"
 463      xmlns:dc="http://purl.org/dc/elements/1.1/"
 464      xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
 465  >
 466  
 467  <channel>
 468      <title><?php bloginfo_rss( 'name' ); ?></title>
 469      <link><?php bloginfo_rss( 'url' ); ?></link>
 470      <description><?php bloginfo_rss( 'description' ); ?></description>
 471      <pubDate><?php echo gmdate( 'D, d M Y H:i:s +0000' ); ?></pubDate>
 472      <language><?php bloginfo_rss( 'language' ); ?></language>
 473      <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
 474      <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
 475      <wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
 476  
 477      <?php wxr_authors_list( $post_ids ); ?>
 478  
 479      <?php foreach ( $cats as $c ) : ?>
 480      <wp:category>
 481          <wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
 482          <wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
 483          <wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent>
 484          <?php
 485          wxr_cat_name( $c );
 486          wxr_category_description( $c );
 487          wxr_term_meta( $c );
 488          ?>
 489      </wp:category>
 490      <?php endforeach; ?>
 491      <?php foreach ( $tags as $t ) : ?>
 492      <wp:tag>
 493          <wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
 494          <wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
 495          <?php
 496          wxr_tag_name( $t );
 497          wxr_tag_description( $t );
 498          wxr_term_meta( $t );
 499          ?>
 500      </wp:tag>
 501      <?php endforeach; ?>
 502      <?php foreach ( $terms as $t ) : ?>
 503      <wp:term>
 504          <wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
 505          <wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
 506          <wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
 507          <wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ); ?></wp:term_parent>
 508          <?php
 509          wxr_term_name( $t );
 510          wxr_term_description( $t );
 511          wxr_term_meta( $t );
 512          ?>
 513      </wp:term>
 514      <?php endforeach; ?>
 515      <?php
 516      if ( 'all' == $args['content'] ) {
 517          wxr_nav_menu_terms();}
 518      ?>
 519  
 520      <?php
 521      /** This action is documented in wp-includes/feed-rss2.php */
 522      do_action( 'rss2_head' );
 523      ?>
 524  
 525      <?php
 526      if ( $post_ids ) {
 527          /**
 528           * @global WP_Query $wp_query WordPress Query object.
 529           */
 530          global $wp_query;
 531  
 532          // Fake being in the loop.
 533          $wp_query->in_the_loop = true;
 534  
 535          // Fetch 20 posts at a time rather than loading the entire table into memory.
 536          while ( $next_posts = array_splice( $post_ids, 0, 20 ) ) {
 537              $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
 538              $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
 539  
 540              // Begin Loop.
 541              foreach ( $posts as $post ) {
 542                  setup_postdata( $post );
 543  
 544                  /** This filter is documented in wp-includes/feed.php */
 545                  $title = apply_filters( 'the_title_rss', $post->post_title );
 546  
 547                  /**
 548                   * Filters the post content used for WXR exports.
 549                   *
 550                   * @since 2.5.0
 551                   *
 552                   * @param string $post_content Content of the current post.
 553                   */
 554                  $content = wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
 555  
 556                  /**
 557                   * Filters the post excerpt used for WXR exports.
 558                   *
 559                   * @since 2.6.0
 560                   *
 561                   * @param string $post_excerpt Excerpt for the current post.
 562                   */
 563                  $excerpt = wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
 564  
 565                  $is_sticky = is_sticky( $post->ID ) ? 1 : 0;
 566                  ?>
 567      <item>
 568          <title><?php echo $title; ?></title>
 569          <link><?php the_permalink_rss(); ?></link>
 570          <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); ?></pubDate>
 571          <dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator>
 572          <guid isPermaLink="false"><?php the_guid(); ?></guid>
 573          <description></description>
 574          <content:encoded><?php echo $content; ?></content:encoded>
 575          <excerpt:encoded><?php echo $excerpt; ?></excerpt:encoded>
 576          <wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id>
 577          <wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date>
 578          <wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt>
 579          <wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status>
 580          <wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status>
 581          <wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name>
 582          <wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status>
 583          <wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent>
 584          <wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order>
 585          <wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type>
 586          <wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password>
 587          <wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky>
 588                  <?php    if ( $post->post_type == 'attachment' ) : ?>
 589          <wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url>
 590      <?php endif; ?>
 591                  <?php wxr_post_taxonomy(); ?>
 592                  <?php
 593                  $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
 594                  foreach ( $postmeta as $meta ) :
 595                      /**
 596                       * Filters whether to selectively skip post meta used for WXR exports.
 597                       *
 598                       * Returning a truthy value to the filter will skip the current meta
 599                       * object from being exported.
 600                       *
 601                       * @since 3.3.0
 602                       *
 603                       * @param bool   $skip     Whether to skip the current post meta. Default false.
 604                       * @param string $meta_key Current meta key.
 605                       * @param object $meta     Current meta object.
 606                       */
 607                      if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
 608                          continue;
 609                      }
 610                      ?>
 611          <wp:postmeta>
 612          <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
 613          <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
 614          </wp:postmeta>
 615                      <?php
 616      endforeach;
 617  
 618                  $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
 619                  $comments  = array_map( 'get_comment', $_comments );
 620                  foreach ( $comments as $c ) :
 621                      ?>
 622          <wp:comment>
 623              <wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id>
 624              <wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
 625              <wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email>
 626              <wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
 627              <wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP>
 628              <wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date>
 629              <wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt>
 630              <wp:comment_content><?php echo wxr_cdata( $c->comment_content ); ?></wp:comment_content>
 631              <wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved>
 632              <wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type>
 633              <wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent>
 634              <wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id>
 635                      <?php
 636                      $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
 637                      foreach ( $c_meta as $meta ) :
 638                          /**
 639                           * Filters whether to selectively skip comment meta used for WXR exports.
 640                           *
 641                           * Returning a truthy value to the filter will skip the current meta
 642                           * object from being exported.
 643                           *
 644                           * @since 4.0.0
 645                           *
 646                           * @param bool   $skip     Whether to skip the current comment meta. Default false.
 647                           * @param string $meta_key Current meta key.
 648                           * @param object $meta     Current meta object.
 649                           */
 650                          if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
 651                              continue;
 652                          }
 653                          ?>
 654      <wp:commentmeta>
 655      <wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
 656              <wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
 657              </wp:commentmeta>
 658                      <?php    endforeach; ?>
 659          </wp:comment>
 660              <?php    endforeach; ?>
 661          </item>
 662                  <?php
 663              }
 664          }
 665      }
 666      ?>
 667  </channel>
 668  </rss>
 669      <?php
 670  }


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1