Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

622 wiersze
22 KiB

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