/wp-admin/includes/export.php

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