wp/wp-admin/includes/export.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    16 define( 'WXR_VERSION', '1.2' );
    16 define( 'WXR_VERSION', '1.2' );
    17 
    17 
    18 /**
    18 /**
    19  * Generates the WXR export file for download.
    19  * Generates the WXR export file for download.
    20  *
    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  *
    21  * @since 2.1.0
    25  * @since 2.1.0
    22  *
    26  *
    23  * @param array $args Filters defining what should be included in the export.
    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  * }
    24  */
    55  */
    25 function export_wp( $args = array() ) {
    56 function export_wp( $args = array() ) {
    26 	global $wpdb, $post;
    57 	global $wpdb, $post;
    27 
    58 
    28 	$defaults = array( 'content' => 'all', 'author' => false, 'category' => false,
    59 	$defaults = array( 'content' => 'all', 'author' => false, 'category' => false,
    38 	 * @param array $args An array of export arguments.
    69 	 * @param array $args An array of export arguments.
    39 	 */
    70 	 */
    40 	do_action( 'export_wp', $args );
    71 	do_action( 'export_wp', $args );
    41 
    72 
    42 	$sitename = sanitize_key( get_bloginfo( 'name' ) );
    73 	$sitename = sanitize_key( get_bloginfo( 'name' ) );
    43 	if ( ! empty($sitename) ) $sitename .= '.';
    74 	if ( ! empty( $sitename ) ) {
    44 	$filename = $sitename . 'wordpress.' . date( 'Y-m-d' ) . '.xml';
    75 		$sitename .= '.';
       
    76 	}
       
    77 	$date = date( 'Y-m-d' );
       
    78 	$wp_filename = $sitename . 'wordpress.' . $date . '.xml';
       
    79 	/**
       
    80 	 * Filters the export filename.
       
    81 	 *
       
    82 	 * @since 4.4.0
       
    83 	 *
       
    84 	 * @param string $wp_filename The name of the file for download.
       
    85 	 * @param string $sitename    The site name.
       
    86 	 * @param string $date        Today's date, formatted.
       
    87 	 */
       
    88 	$filename = apply_filters( 'export_wp_filename', $wp_filename, $sitename, $date );
    45 
    89 
    46 	header( 'Content-Description: File Transfer' );
    90 	header( 'Content-Description: File Transfer' );
    47 	header( 'Content-Disposition: attachment; filename=' . $filename );
    91 	header( 'Content-Disposition: attachment; filename=' . $filename );
    48 	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
    92 	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
    49 
    93 
    70 			$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
   114 			$join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
    71 			$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
   115 			$where .= $wpdb->prepare( " AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id'] );
    72 		}
   116 		}
    73 	}
   117 	}
    74 
   118 
    75 	if ( 'post' == $args['content'] || 'page' == $args['content'] ) {
   119 	if ( 'post' == $args['content'] || 'page' == $args['content'] || 'attachment' == $args['content'] ) {
    76 		if ( $args['author'] )
   120 		if ( $args['author'] )
    77 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
   121 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $args['author'] );
    78 
   122 
    79 		if ( $args['start_date'] )
   123 		if ( $args['start_date'] )
    80 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
   124 			$where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime($args['start_date']) ) );
   128 	 *
   172 	 *
   129 	 * @param string $str String to wrap in XML CDATA tag.
   173 	 * @param string $str String to wrap in XML CDATA tag.
   130 	 * @return string
   174 	 * @return string
   131 	 */
   175 	 */
   132 	function wxr_cdata( $str ) {
   176 	function wxr_cdata( $str ) {
   133 		if ( seems_utf8( $str ) == false )
   177 		if ( ! seems_utf8( $str ) ) {
   134 			$str = utf8_encode( $str );
   178 			$str = utf8_encode( $str );
   135 
   179 		}
   136 		// $str = ent2ncr(esc_html($str));
   180 		// $str = ent2ncr(esc_html($str));
   137 		$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
   181 		$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
   138 
   182 
   139 		return $str;
   183 		return $str;
   140 	}
   184 	}
   164 	 */
   208 	 */
   165 	function wxr_cat_name( $category ) {
   209 	function wxr_cat_name( $category ) {
   166 		if ( empty( $category->name ) )
   210 		if ( empty( $category->name ) )
   167 			return;
   211 			return;
   168 
   212 
   169 		echo '<wp:cat_name>' . wxr_cdata( $category->name ) . '</wp:cat_name>';
   213 		echo '<wp:cat_name>' . wxr_cdata( $category->name ) . "</wp:cat_name>\n";
   170 	}
   214 	}
   171 
   215 
   172 	/**
   216 	/**
   173 	 * Output a category_description XML tag from a given category object
   217 	 * Output a category_description XML tag from a given category object
   174 	 *
   218 	 *
   178 	 */
   222 	 */
   179 	function wxr_category_description( $category ) {
   223 	function wxr_category_description( $category ) {
   180 		if ( empty( $category->description ) )
   224 		if ( empty( $category->description ) )
   181 			return;
   225 			return;
   182 
   226 
   183 		echo '<wp:category_description>' . wxr_cdata( $category->description ) . '</wp:category_description>';
   227 		echo '<wp:category_description>' . wxr_cdata( $category->description ) . "</wp:category_description>\n";
   184 	}
   228 	}
   185 
   229 
   186 	/**
   230 	/**
   187 	 * Output a tag_name XML tag from a given tag object
   231 	 * Output a tag_name XML tag from a given tag object
   188 	 *
   232 	 *
   192 	 */
   236 	 */
   193 	function wxr_tag_name( $tag ) {
   237 	function wxr_tag_name( $tag ) {
   194 		if ( empty( $tag->name ) )
   238 		if ( empty( $tag->name ) )
   195 			return;
   239 			return;
   196 
   240 
   197 		echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . '</wp:tag_name>';
   241 		echo '<wp:tag_name>' . wxr_cdata( $tag->name ) . "</wp:tag_name>\n";
   198 	}
   242 	}
   199 
   243 
   200 	/**
   244 	/**
   201 	 * Output a tag_description XML tag from a given tag object
   245 	 * Output a tag_description XML tag from a given tag object
   202 	 *
   246 	 *
   206 	 */
   250 	 */
   207 	function wxr_tag_description( $tag ) {
   251 	function wxr_tag_description( $tag ) {
   208 		if ( empty( $tag->description ) )
   252 		if ( empty( $tag->description ) )
   209 			return;
   253 			return;
   210 
   254 
   211 		echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . '</wp:tag_description>';
   255 		echo '<wp:tag_description>' . wxr_cdata( $tag->description ) . "</wp:tag_description>\n";
   212 	}
   256 	}
   213 
   257 
   214 	/**
   258 	/**
   215 	 * Output a term_name XML tag from a given term object
   259 	 * Output a term_name XML tag from a given term object
   216 	 *
   260 	 *
   220 	 */
   264 	 */
   221 	function wxr_term_name( $term ) {
   265 	function wxr_term_name( $term ) {
   222 		if ( empty( $term->name ) )
   266 		if ( empty( $term->name ) )
   223 			return;
   267 			return;
   224 
   268 
   225 		echo '<wp:term_name>' . wxr_cdata( $term->name ) . '</wp:term_name>';
   269 		echo '<wp:term_name>' . wxr_cdata( $term->name ) . "</wp:term_name>\n";
   226 	}
   270 	}
   227 
   271 
   228 	/**
   272 	/**
   229 	 * Output a term_description XML tag from a given term object
   273 	 * Output a term_description XML tag from a given term object
   230 	 *
   274 	 *
   234 	 */
   278 	 */
   235 	function wxr_term_description( $term ) {
   279 	function wxr_term_description( $term ) {
   236 		if ( empty( $term->description ) )
   280 		if ( empty( $term->description ) )
   237 			return;
   281 			return;
   238 
   282 
   239 		echo '<wp:term_description>' . wxr_cdata( $term->description ) . '</wp:term_description>';
   283 		echo "\t\t<wp:term_description>" . wxr_cdata( $term->description ) . "</wp:term_description>\n";
       
   284 	}
       
   285 
       
   286 	/**
       
   287 	 * Output term meta XML tags for a given term object.
       
   288 	 *
       
   289 	 * @since 4.6.0
       
   290 	 *
       
   291 	 * @param WP_Term $term Term object.
       
   292 	 */
       
   293 	function wxr_term_meta( $term ) {
       
   294 		global $wpdb;
       
   295 
       
   296 		$termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
       
   297 
       
   298 		foreach ( $termmeta as $meta ) {
       
   299 			/**
       
   300 			 * Filters whether to selectively skip term meta used for WXR exports.
       
   301 			 *
       
   302 			 * Returning a truthy value to the filter will skip the current meta
       
   303 			 * object from being exported.
       
   304 			 *
       
   305 			 * @since 4.6.0
       
   306 			 *
       
   307 			 * @param bool   $skip     Whether to skip the current piece of term meta. Default false.
       
   308 			 * @param string $meta_key Current meta key.
       
   309 			 * @param object $meta     Current meta object.
       
   310 			 */
       
   311 			if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) ) {
       
   312 				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 ) );
       
   313 			}
       
   314 		}
   240 	}
   315 	}
   241 
   316 
   242 	/**
   317 	/**
   243 	 * Output list of authors with posts
   318 	 * Output list of authors with posts
   244 	 *
   319 	 *
   245 	 * @since 3.1.0
   320 	 * @since 3.1.0
       
   321 	 *
       
   322 	 * @global wpdb $wpdb WordPress database abstraction object.
   246 	 *
   323 	 *
   247 	 * @param array $post_ids Array of post IDs to filter the query by. Optional.
   324 	 * @param array $post_ids Array of post IDs to filter the query by. Optional.
   248 	 */
   325 	 */
   249 	function wxr_authors_list( array $post_ids = null ) {
   326 	function wxr_authors_list( array $post_ids = null ) {
   250 		global $wpdb;
   327 		global $wpdb;
   263 
   340 
   264 		$authors = array_filter( $authors );
   341 		$authors = array_filter( $authors );
   265 
   342 
   266 		foreach ( $authors as $author ) {
   343 		foreach ( $authors as $author ) {
   267 			echo "\t<wp:author>";
   344 			echo "\t<wp:author>";
   268 			echo '<wp:author_id>' . $author->ID . '</wp:author_id>';
   345 			echo '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
   269 			echo '<wp:author_login>' . $author->user_login . '</wp:author_login>';
   346 			echo '<wp:author_login>' . wxr_cdata( $author->user_login ) . '</wp:author_login>';
   270 			echo '<wp:author_email>' . $author->user_email . '</wp:author_email>';
   347 			echo '<wp:author_email>' . wxr_cdata( $author->user_email ) . '</wp:author_email>';
   271 			echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
   348 			echo '<wp:author_display_name>' . wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
   272 			echo '<wp:author_first_name>' . wxr_cdata( $author->user_firstname ) . '</wp:author_first_name>';
   349 			echo '<wp:author_first_name>' . wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
   273 			echo '<wp:author_last_name>' . wxr_cdata( $author->user_lastname ) . '</wp:author_last_name>';
   350 			echo '<wp:author_last_name>' . wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
   274 			echo "</wp:author>\n";
   351 			echo "</wp:author>\n";
   275 		}
   352 		}
   276 	}
   353 	}
   277 
   354 
   278 	/**
   355 	/**
   279 	 * Ouput all navigation menu terms
   356 	 * Output all navigation menu terms
   280 	 *
   357 	 *
   281 	 * @since 3.1.0
   358 	 * @since 3.1.0
   282 	 */
   359 	 */
   283 	function wxr_nav_menu_terms() {
   360 	function wxr_nav_menu_terms() {
   284 		$nav_menus = wp_get_nav_menus();
   361 		$nav_menus = wp_get_nav_menus();
   285 		if ( empty( $nav_menus ) || ! is_array( $nav_menus ) )
   362 		if ( empty( $nav_menus ) || ! is_array( $nav_menus ) )
   286 			return;
   363 			return;
   287 
   364 
   288 		foreach ( $nav_menus as $menu ) {
   365 		foreach ( $nav_menus as $menu ) {
   289 			echo "\t<wp:term><wp:term_id>{$menu->term_id}</wp:term_id><wp:term_taxonomy>nav_menu</wp:term_taxonomy><wp:term_slug>{$menu->slug}</wp:term_slug>";
   366 			echo "\t<wp:term>";
       
   367 			echo '<wp:term_id>' . intval( $menu->term_id ) . '</wp:term_id>';
       
   368 			echo '<wp:term_taxonomy>nav_menu</wp:term_taxonomy>';
       
   369 			echo '<wp:term_slug>' . wxr_cdata( $menu->slug ) . '</wp:term_slug>';
   290 			wxr_term_name( $menu );
   370 			wxr_term_name( $menu );
   291 			echo "</wp:term>\n";
   371 			echo "</wp:term>\n";
   292 		}
   372 		}
   293 	}
   373 	}
   294 
   374 
   308 		foreach ( (array) $terms as $term ) {
   388 		foreach ( (array) $terms as $term ) {
   309 			echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
   389 			echo "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . wxr_cdata( $term->name ) . "</category>\n";
   310 		}
   390 		}
   311 	}
   391 	}
   312 
   392 
       
   393 	/**
       
   394 	 *
       
   395 	 * @param bool   $return_me
       
   396 	 * @param string $meta_key
       
   397 	 * @return bool
       
   398 	 */
   313 	function wxr_filter_postmeta( $return_me, $meta_key ) {
   399 	function wxr_filter_postmeta( $return_me, $meta_key ) {
   314 		if ( '_edit_lock' == $meta_key )
   400 		if ( '_edit_lock' == $meta_key )
   315 			$return_me = true;
   401 			$return_me = true;
   316 		return $return_me;
   402 		return $return_me;
   317 	}
   403 	}
   357 	<wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
   443 	<wp:base_blog_url><?php bloginfo_rss( 'url' ); ?></wp:base_blog_url>
   358 
   444 
   359 <?php wxr_authors_list( $post_ids ); ?>
   445 <?php wxr_authors_list( $post_ids ); ?>
   360 
   446 
   361 <?php foreach ( $cats as $c ) : ?>
   447 <?php foreach ( $cats as $c ) : ?>
   362 	<wp:category><wp:term_id><?php echo $c->term_id ?></wp:term_id><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->slug : ''; ?></wp:category_parent><?php wxr_cat_name( $c ); ?><?php wxr_category_description( $c ); ?></wp:category>
   448 	<wp:category>
       
   449 		<wp:term_id><?php echo intval( $c->term_id ); ?></wp:term_id>
       
   450 		<wp:category_nicename><?php echo wxr_cdata( $c->slug ); ?></wp:category_nicename>
       
   451 		<wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[$c->parent]->slug : '' ); ?></wp:category_parent>
       
   452 		<?php wxr_cat_name( $c );
       
   453 		wxr_category_description( $c );
       
   454 		wxr_term_meta( $c ); ?>
       
   455 	</wp:category>
   363 <?php endforeach; ?>
   456 <?php endforeach; ?>
   364 <?php foreach ( $tags as $t ) : ?>
   457 <?php foreach ( $tags as $t ) : ?>
   365 	<wp:tag><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name( $t ); ?><?php wxr_tag_description( $t ); ?></wp:tag>
   458 	<wp:tag>
       
   459 		<wp:term_id><?php echo intval( $t->term_id ); ?></wp:term_id>
       
   460 		<wp:tag_slug><?php echo wxr_cdata( $t->slug ); ?></wp:tag_slug>
       
   461 		<?php wxr_tag_name( $t );
       
   462 		wxr_tag_description( $t );
       
   463 		wxr_term_meta( $t ); ?>
       
   464 	</wp:tag>
   366 <?php endforeach; ?>
   465 <?php endforeach; ?>
   367 <?php foreach ( $terms as $t ) : ?>
   466 <?php foreach ( $terms as $t ) : ?>
   368 	<wp:term><wp:term_id><?php echo $t->term_id ?></wp:term_id><wp:term_taxonomy><?php echo $t->taxonomy; ?></wp:term_taxonomy><wp:term_slug><?php echo $t->slug; ?></wp:term_slug><wp:term_parent><?php echo $t->parent ? $terms[$t->parent]->slug : ''; ?></wp:term_parent><?php wxr_term_name( $t ); ?><?php wxr_term_description( $t ); ?></wp:term>
   467 	<wp:term>
       
   468 		<wp:term_id><?php echo wxr_cdata( $t->term_id ); ?></wp:term_id>
       
   469 		<wp:term_taxonomy><?php echo wxr_cdata( $t->taxonomy ); ?></wp:term_taxonomy>
       
   470 		<wp:term_slug><?php echo wxr_cdata( $t->slug ); ?></wp:term_slug>
       
   471 		<wp:term_parent><?php echo wxr_cdata( $t->parent ? $terms[$t->parent]->slug : '' ); ?></wp:term_parent>
       
   472 		<?php wxr_term_name( $t );
       
   473 		wxr_term_description( $t );
       
   474 		wxr_term_meta( $t ); ?>
       
   475 	</wp:term>
   369 <?php endforeach; ?>
   476 <?php endforeach; ?>
   370 <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
   477 <?php if ( 'all' == $args['content'] ) wxr_nav_menu_terms(); ?>
   371 
   478 
   372 	<?php
   479 	<?php
   373 	/** This action is documented in wp-includes/feed-rss2.php */
   480 	/** This action is documented in wp-includes/feed-rss2.php */
   374 	do_action( 'rss2_head' );
   481 	do_action( 'rss2_head' );
   375 	?>
   482 	?>
   376 
   483 
   377 <?php if ( $post_ids ) {
   484 <?php if ( $post_ids ) {
       
   485 	/**
       
   486 	 * @global WP_Query $wp_query
       
   487 	 */
   378 	global $wp_query;
   488 	global $wp_query;
   379 
   489 
   380 	// Fake being in the loop.
   490 	// Fake being in the loop.
   381 	$wp_query->in_the_loop = true;
   491 	$wp_query->in_the_loop = true;
   382 
   492 
   400 		<dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator>
   510 		<dc:creator><?php echo wxr_cdata( get_the_author_meta( 'login' ) ); ?></dc:creator>
   401 		<guid isPermaLink="false"><?php the_guid(); ?></guid>
   511 		<guid isPermaLink="false"><?php the_guid(); ?></guid>
   402 		<description></description>
   512 		<description></description>
   403 		<content:encoded><?php
   513 		<content:encoded><?php
   404 			/**
   514 			/**
   405 			 * Filter the post content used for WXR exports.
   515 			 * Filters the post content used for WXR exports.
   406 			 *
   516 			 *
   407 			 * @since 2.5.0
   517 			 * @since 2.5.0
   408 			 *
   518 			 *
   409 			 * @param string $post_content Content of the current post.
   519 			 * @param string $post_content Content of the current post.
   410 			 */
   520 			 */
   411 			echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
   521 			echo wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) );
   412 		?></content:encoded>
   522 		?></content:encoded>
   413 		<excerpt:encoded><?php
   523 		<excerpt:encoded><?php
   414 			/**
   524 			/**
   415 			 * Filter the post excerpt used for WXR exports.
   525 			 * Filters the post excerpt used for WXR exports.
   416 			 *
   526 			 *
   417 			 * @since 2.6.0
   527 			 * @since 2.6.0
   418 			 *
   528 			 *
   419 			 * @param string $post_excerpt Excerpt for the current post.
   529 			 * @param string $post_excerpt Excerpt for the current post.
   420 			 */
   530 			 */
   421 			echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
   531 			echo wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) );
   422 		?></excerpt:encoded>
   532 		?></excerpt:encoded>
   423 		<wp:post_id><?php echo $post->ID; ?></wp:post_id>
   533 		<wp:post_id><?php echo intval( $post->ID ); ?></wp:post_id>
   424 		<wp:post_date><?php echo $post->post_date; ?></wp:post_date>
   534 		<wp:post_date><?php echo wxr_cdata( $post->post_date ); ?></wp:post_date>
   425 		<wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
   535 		<wp:post_date_gmt><?php echo wxr_cdata( $post->post_date_gmt ); ?></wp:post_date_gmt>
   426 		<wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
   536 		<wp:comment_status><?php echo wxr_cdata( $post->comment_status ); ?></wp:comment_status>
   427 		<wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
   537 		<wp:ping_status><?php echo wxr_cdata( $post->ping_status ); ?></wp:ping_status>
   428 		<wp:post_name><?php echo $post->post_name; ?></wp:post_name>
   538 		<wp:post_name><?php echo wxr_cdata( $post->post_name ); ?></wp:post_name>
   429 		<wp:status><?php echo $post->post_status; ?></wp:status>
   539 		<wp:status><?php echo wxr_cdata( $post->post_status ); ?></wp:status>
   430 		<wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
   540 		<wp:post_parent><?php echo intval( $post->post_parent ); ?></wp:post_parent>
   431 		<wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
   541 		<wp:menu_order><?php echo intval( $post->menu_order ); ?></wp:menu_order>
   432 		<wp:post_type><?php echo $post->post_type; ?></wp:post_type>
   542 		<wp:post_type><?php echo wxr_cdata( $post->post_type ); ?></wp:post_type>
   433 		<wp:post_password><?php echo $post->post_password; ?></wp:post_password>
   543 		<wp:post_password><?php echo wxr_cdata( $post->post_password ); ?></wp:post_password>
   434 		<wp:is_sticky><?php echo $is_sticky; ?></wp:is_sticky>
   544 		<wp:is_sticky><?php echo intval( $is_sticky ); ?></wp:is_sticky>
   435 <?php	if ( $post->post_type == 'attachment' ) : ?>
   545 <?php	if ( $post->post_type == 'attachment' ) : ?>
   436 		<wp:attachment_url><?php echo wp_get_attachment_url( $post->ID ); ?></wp:attachment_url>
   546 		<wp:attachment_url><?php echo wxr_cdata( wp_get_attachment_url( $post->ID ) ); ?></wp:attachment_url>
   437 <?php 	endif; ?>
   547 <?php 	endif; ?>
   438 <?php 	wxr_post_taxonomy(); ?>
   548 <?php 	wxr_post_taxonomy(); ?>
   439 <?php	$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
   549 <?php	$postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
   440 		foreach ( $postmeta as $meta ) :
   550 		foreach ( $postmeta as $meta ) :
   441 			/**
   551 			/**
   442 			 * Filter whether to selectively skip post meta used for WXR exports.
   552 			 * Filters whether to selectively skip post meta used for WXR exports.
   443 			 *
   553 			 *
   444 			 * Returning a truthy value to the filter will skip the current meta
   554 			 * Returning a truthy value to the filter will skip the current meta
   445 			 * object from being exported.
   555 			 * object from being exported.
   446 			 *
   556 			 *
   447 			 * @since 3.3.0
   557 			 * @since 3.3.0
   452 			 */
   562 			 */
   453 			if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) )
   563 			if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) )
   454 				continue;
   564 				continue;
   455 		?>
   565 		?>
   456 		<wp:postmeta>
   566 		<wp:postmeta>
   457 			<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
   567 			<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
   458 			<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   568 			<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   459 		</wp:postmeta>
   569 		</wp:postmeta>
   460 <?php	endforeach;
   570 <?php	endforeach;
   461 
   571 
   462 		$comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
   572 		$_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
       
   573 		$comments = array_map( 'get_comment', $_comments );
   463 		foreach ( $comments as $c ) : ?>
   574 		foreach ( $comments as $c ) : ?>
   464 		<wp:comment>
   575 		<wp:comment>
   465 			<wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
   576 			<wp:comment_id><?php echo intval( $c->comment_ID ); ?></wp:comment_id>
   466 			<wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
   577 			<wp:comment_author><?php echo wxr_cdata( $c->comment_author ); ?></wp:comment_author>
   467 			<wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
   578 			<wp:comment_author_email><?php echo wxr_cdata( $c->comment_author_email ); ?></wp:comment_author_email>
   468 			<wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
   579 			<wp:comment_author_url><?php echo esc_url_raw( $c->comment_author_url ); ?></wp:comment_author_url>
   469 			<wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
   580 			<wp:comment_author_IP><?php echo wxr_cdata( $c->comment_author_IP ); ?></wp:comment_author_IP>
   470 			<wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
   581 			<wp:comment_date><?php echo wxr_cdata( $c->comment_date ); ?></wp:comment_date>
   471 			<wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
   582 			<wp:comment_date_gmt><?php echo wxr_cdata( $c->comment_date_gmt ); ?></wp:comment_date_gmt>
   472 			<wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content>
   583 			<wp:comment_content><?php echo wxr_cdata( $c->comment_content ) ?></wp:comment_content>
   473 			<wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
   584 			<wp:comment_approved><?php echo wxr_cdata( $c->comment_approved ); ?></wp:comment_approved>
   474 			<wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
   585 			<wp:comment_type><?php echo wxr_cdata( $c->comment_type ); ?></wp:comment_type>
   475 			<wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
   586 			<wp:comment_parent><?php echo intval( $c->comment_parent ); ?></wp:comment_parent>
   476 			<wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
   587 			<wp:comment_user_id><?php echo intval( $c->user_id ); ?></wp:comment_user_id>
   477 <?php		$c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
   588 <?php		$c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
   478 			foreach ( $c_meta as $meta ) :
   589 			foreach ( $c_meta as $meta ) :
   479 				/**
   590 				/**
   480 				 * Filter whether to selectively skip comment meta used for WXR exports.
   591 				 * Filters whether to selectively skip comment meta used for WXR exports.
   481 				 *
   592 				 *
   482 				 * Returning a truthy value to the filter will skip the current meta
   593 				 * Returning a truthy value to the filter will skip the current meta
   483 				 * object from being exported.
   594 				 * object from being exported.
   484 				 *
   595 				 *
   485 				 * @since 4.0.0
   596 				 * @since 4.0.0
   491 				if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
   602 				if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) ) {
   492 					continue;
   603 					continue;
   493 				}
   604 				}
   494 			?>
   605 			?>
   495 			<wp:commentmeta>
   606 			<wp:commentmeta>
   496 				<wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
   607 				<wp:meta_key><?php echo wxr_cdata( $meta->meta_key ); ?></wp:meta_key>
   497 				<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   608 				<wp:meta_value><?php echo wxr_cdata( $meta->meta_value ); ?></wp:meta_value>
   498 			</wp:commentmeta>
   609 			</wp:commentmeta>
   499 <?php		endforeach; ?>
   610 <?php		endforeach; ?>
   500 		</wp:comment>
   611 		</wp:comment>
   501 <?php	endforeach; ?>
   612 <?php	endforeach; ?>