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