Няма описание

export.php 23KB

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