1. <?php
  2. /*
  3. Plugin Name: Advanced Export for WordPress & WordPress MU
  4. Plugin URI: http://wpmututorials.com/plugins/advanced-export/
  5. Description: Adds an Advanced Export to the Tools menu which allows selective exporting of pages, posts, specific categories and/or post statuses by date.
  6. Version: 2.8.3
  7. Author: Ron Rennick
  8. Author URI: http://ronandandrea.com/
  9.  
  10. */
  11. /* Copyright:   (C) 2009 Ron Rennick, All rights reserved.  
  12.  
  13.     This program is free software; you can redistribute it and/or modify
  14.     it under the terms of the GNU General Public License as published by
  15.     the Free Software Foundation; either version 2 of the License, or
  16.     (at your option) any later version.
  17.  
  18.     This program is distributed in the hope that it will be useful,
  19.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.     GNU General Public License for more details.
  22.  
  23.     You should have received a copy of the GNU General Public License
  24.     along with this program; if not, write to the Free Software
  25.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  26. */
  27. /*mod jrc 300312 - modified to a) export attachments only, b) remove superfluous tag and cat post data when not exporting tags or cats - see mod marks: 'mod jrc 290312', 'mod jrc 300312' - (see also: http://wordpress.org/support/topic/plugin-advanced-export-for-wp-wpmu-how-to-export-attachments-only, http://wordpress.org/support/topic/plugin-advanced-export-for-wp-wpmu-eliminating-superfluous-cat-and-tag-records-from-posts-only-exports) - esp. useful for exporting and importing in multiple batches and for use with plugin http://wordpress.org/extend/plugins/wordpress-importer/ (modieid) (ess also: http://wordpress.org/support/topic/plugin-wordpress-importer-not-importing-any-images-at-all)*/
  28.  
  29. if(!defined('ABSPATH')) {
  30.     die("Don't call this file directly.");
  31. }
  32. if(isset($_GET['page']) && $_GET['page'] == 'ra_export' && isset( $_GET['download'] ) ) {
  33.     add_action('init', 'ra_do_export');
  34. }
  35. function ra_do_export() {
  36.     if(current_user_can('edit_files')) {
  37.         $author = isset($_GET['author']) ? $_GET['author'] : 'all';
  38.         $category = isset($_GET['category']) ? $_GET['category'] : 'all';
  39.         $post_type = isset($_GET['post_type']) ? wp_specialchars($_GET['post_type']) : 'all';
  40.         $status = isset($_GET['status']) ? wp_specialchars($_GET['status']) : 'all';
  41.         $mm_start = isset($_GET['mm_start']) ? $_GET['mm_start'] : 'all';
  42.         $mm_end = isset($_GET['mm_end']) ? $_GET['mm_end'] : 'all';
  43.         $aa_start = isset($_GET['aa_start']) ? intval($_GET['aa_start']) : 0;
  44.         $aa_end = isset($_GET['aa_end']) ? intval($_GET['aa_end']) : 0;
  45.         $terms = isset($_GET['terms']) ? wp_specialchars($_GET['terms']) : 'all';
  46.         if($mm_start != 'all' && $aa_start > 0) {
  47.             $start_date = sprintf( "%04d-%02d-%02d", $aa_start, $mm_start, 1 );
  48.         } else {
  49.             $start_date = 'all';
  50.         }
  51.         if($mm_end != 'all' && $aa_end > 0) {
  52.             if($mm_end == 12) {
  53.                 $mm_end = 1;
  54.                 $aa_end++;
  55.             } else {
  56.                 $mm_end++;
  57.             }
  58.             $end_date = sprintf( "%04d-%02d-%02d", $aa_end, $mm_end, 1 );
  59.         } else {
  60.             $end_date = 'all';
  61.         }
  62.         ra_export_setup();
  63.         ra_export_wp( $author, $category, $post_type, $status, $start_date, $end_date, $terms );
  64.         die();
  65.     }
  66. }  
  67. function ra_export_wp($author='', $category='', $post_type='', $status='', $start_date='', $end_date='', $terms = '') {
  68.     global $wpdb, $post_ids, $post;
  69.  
  70.     define('WXR_VERSION', '1.0');
  71.  
  72.     do_action('export_wp');
  73.  
  74.     if(strlen($start_date) > 4 && strlen($end_date) > 4) {
  75.         $filename = 'wordpress.' . $start_date . '.' . $end_date . '.xml';
  76.     } else {
  77.         $filename = 'wordpress.' . date('Y-m-d') . '.xml';
  78.     }
  79.     header('Content-Description: File Transfer');
  80.     header("Content-Disposition: attachment; filename=$filename");
  81.     header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
  82.  
  83.     if ( $post_type and $post_type != 'all' ) {
  84.         $where = $wpdb->prepare("WHERE post_type = %s ", $post_type);
  85.     } else {
  86.         $where = "WHERE post_type != 'revision' ";
  87.     }
  88.     if ( $author and $author != 'all' ) {
  89.         $author_id = (int) $author;
  90.         $where .= $wpdb->prepare("AND post_author = %d ", $author_id);
  91.     }
  92.     if ( $start_date and $start_date != 'all' ) {
  93.         $where .= $wpdb->prepare("AND post_date >= %s ", $start_date);
  94.     }
  95.     if ( $end_date and $end_date != 'all' ) {
  96.         $where .= $wpdb->prepare("AND post_date < %s ", $end_date);
  97.     }
  98.     if ( $category and $category != 'all' and version_compare($wpdb->db_version(), '4.1', 'ge')) {
  99.         $taxomony_id = (int) $category;
  100.         $where .= $wpdb->prepare("AND ID IN (SELECT object_id FROM {$wpdb->term_relationships} " .
  101.             "WHERE term_taxonomy_id = %d) ", $taxomony_id);
  102.     }
  103.     if ( $status and $status != 'all' ) {
  104.         $where .= $wpdb->prepare("AND post_status = %s ", $status);
  105.     }
  106.  
  107.     // grab a snapshot of post IDs, just in case it changes during the export
  108.     $post_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
  109.  
  110.     $categories = (array) get_categories('get=all');
  111.     $tags = (array) get_tags('get=all');
  112.  
  113.     while ( $parents = wxr_missing_parents($categories) ) {
  114.         $found_parents = get_categories("include=" . join(', ', $parents));
  115.         if ( is_array($found_parents) && count($found_parents) )
  116.             $categories = array_merge($categories, $found_parents);
  117.         else
  118.             break;
  119.     }
  120.  
  121.     // Put them in order to be inserted with no child going before its parent
  122.     $pass = 0;
  123.     $passes = 1000 + count($categories);
  124.     while ( ( $cat = array_shift($categories) ) && ++$pass < $passes ) {
  125.         if ( $cat->parent == 0 || isset($cats[$cat->parent]) ) {
  126.             $cats[$cat->term_id] = $cat;
  127.         } else {
  128.             $categories[] = $cat;
  129.         }
  130.     }
  131.     unset($categories);
  132.  
  133.     echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . '"?' . ">\n";
  134. ?>
  135. <!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your blog. -->
  136. <!-- It contains information about your blog's posts, comments, and categories. -->
  137. <!-- You may use this file to transfer that content from one site to another. -->
  138. <!-- This file is not intended to serve as a complete backup of your blog. -->
  139.  
  140. <!-- To import this information into a WordPress blog follow these steps. -->
  141. <!-- 1. Log into that blog as an administrator. -->
  142. <!-- 2. Go to Tools: Import in the blog's admin panels (or Manage: Import in older versions of WordPress). -->
  143. <!-- 3. Choose "WordPress" from the list. -->
  144. <!-- 4. Upload this file using the form provided on that page. -->
  145. <!-- 5. You will first be asked to map the authors in this export file to users -->
  146. <!--    on the blog.  For each author, you may choose to map to an -->
  147. <!--    existing user on the blog or to create a new user -->
  148. <!-- 6. WordPress will then import each of the posts, comments, and categories -->
  149. <!--    contained in this file into your blog -->
  150.  
  151. <?php the_generator('export');?>
  152. <rss version="2.0"
  153.     xmlns:excerpt="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/excerpt/"
  154.     xmlns:content="http://purl.org/rss/1.0/modules/content/"
  155.     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  156.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  157.     xmlns:wp="http://wordpress.org/export/<?php echo WXR_VERSION; ?>/"
  158. >
  159.  
  160. <channel>
  161.     <title><?php bloginfo_rss('name'); ?></title>
  162.     <link><?php bloginfo_rss('url') ?></link>
  163.     <description><?php bloginfo_rss("description") ?></description>
  164.     <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>
  165.     <generator>http://wordpress.org/?v=<?php bloginfo_rss('version'); ?></generator>
  166.     <language><?php echo get_option('rss_language'); ?></language>
  167.     <wp:wxr_version><?php echo WXR_VERSION; ?></wp:wxr_version>
  168.     <wp:base_site_url><?php echo wxr_site_url(); ?></wp:base_site_url>
  169.     <wp:base_blog_url><?php bloginfo_rss('url'); ?></wp:base_blog_url>
  170. <?php if ( $cats && ($terms == 'all' || $terms == 'cats')) : foreach ( $cats as $c ) : ?>
  171.     <wp:category><wp:category_nicename><?php echo $c->slug; ?></wp:category_nicename><wp:category_parent><?php echo $c->parent ? $cats[$c->parent]->name : ''; ?></wp:category_parent><?php wxr_cat_name($c); ?><?php wxr_category_description($c); ?></wp:category>
  172. <?php endforeach; endif; ?>
  173. <?php if ( $tags && ($terms == 'all' || $terms == 'tags')) : foreach ( $tags as $t ) : ?>
  174.     <wp:tag><wp:tag_slug><?php echo $t->slug; ?></wp:tag_slug><?php wxr_tag_name($t); ?><?php wxr_tag_description($t); ?></wp:tag>
  175. <?php endforeach; endif; ?>
  176.     <?php do_action('rss2_head'); ?>
  177.     <?php if ($post_ids) {
  178.         global $wp_query;
  179.         $wp_query->in_the_loop = true;  // Fake being in the loop.
  180.         // fetch 20 posts at a time rather than loading the entire table into memory
  181.         while ( $next_posts = array_splice($post_ids, 0, 20) ) {
  182.             $where = "WHERE ID IN (".join(',', $next_posts).")";
  183.             $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC");
  184.                 foreach ($posts as $post) {
  185.                     setup_postdata($post); ?>
  186. <item>
  187. <title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
  188. <link><?php the_permalink_rss() ?></link>
  189. <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
  190. <dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
  191. <?php /*mod jrc 290312 -  wxr_post_taxonomy() */?>
  192. <?php scl_wxr_post_taxonomy($terms); ?>
  193. <?php /*end mod jrc 290312*/ ?>
  194. <guid isPermaLink="false"><?php the_guid(); ?></guid>
  195. <description></description>
  196. <content:encoded><?php echo wxr_cdata( apply_filters('the_content_export', $post->post_content) ); ?></content:encoded>
  197. <excerpt:encoded><?php echo wxr_cdata( apply_filters('the_excerpt_export', $post->post_excerpt) ); ?></excerpt:encoded>
  198. <wp:post_id><?php echo $post->ID; ?></wp:post_id>
  199. <wp:post_date><?php echo $post->post_date; ?></wp:post_date>
  200. <wp:post_date_gmt><?php echo $post->post_date_gmt; ?></wp:post_date_gmt>
  201. <wp:comment_status><?php echo $post->comment_status; ?></wp:comment_status>
  202. <wp:ping_status><?php echo $post->ping_status; ?></wp:ping_status>
  203. <wp:post_name><?php echo $post->post_name; ?></wp:post_name>
  204. <wp:status><?php echo $post->post_status; ?></wp:status>
  205. <wp:post_parent><?php echo $post->post_parent; ?></wp:post_parent>
  206. <wp:menu_order><?php echo $post->menu_order; ?></wp:menu_order>
  207. <wp:post_type><?php echo $post->post_type; ?></wp:post_type>
  208. <wp:post_password><?php echo $post->post_password; ?></wp:post_password>
  209. <?php
  210. if ($post->post_type == 'attachment') { ?>
  211. <wp:attachment_url><?php echo wp_get_attachment_url($post->ID); ?></wp:attachment_url>
  212. <?php } ?>
  213. <?php
  214. $postmeta = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID) );
  215. if ( $postmeta ) {
  216. ?>
  217. <?php foreach( $postmeta as $meta ) { ?>
  218. <wp:postmeta>
  219. <wp:meta_key><?php echo $meta->meta_key; ?></wp:meta_key>
  220. <wp:meta_value><?Php echo $meta->meta_value; ?></wp:meta_value>
  221. </wp:postmeta>
  222. <?php } ?>
  223. <?php } ?>
  224. <?php
  225. $comments = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d", $post->ID) );
  226. if ( $comments ) { foreach ( $comments as $c ) { ?>
  227. <wp:comment>
  228. <wp:comment_id><?php echo $c->comment_ID; ?></wp:comment_id>
  229. <wp:comment_author><?php echo wxr_cdata($c->comment_author); ?></wp:comment_author>
  230. <wp:comment_author_email><?php echo $c->comment_author_email; ?></wp:comment_author_email>
  231. <wp:comment_author_url><?php echo $c->comment_author_url; ?></wp:comment_author_url>
  232. <wp:comment_author_IP><?php echo $c->comment_author_IP; ?></wp:comment_author_IP>
  233. <wp:comment_date><?php echo $c->comment_date; ?></wp:comment_date>
  234. <wp:comment_date_gmt><?php echo $c->comment_date_gmt; ?></wp:comment_date_gmt>
  235. <wp:comment_content><?php echo wxr_cdata($c->comment_content) ?></wp:comment_content>
  236. <wp:comment_approved><?php echo $c->comment_approved; ?></wp:comment_approved>
  237. <wp:comment_type><?php echo $c->comment_type; ?></wp:comment_type>
  238. <wp:comment_parent><?php echo $c->comment_parent; ?></wp:comment_parent>
  239. <wp:comment_user_id><?php echo $c->user_id; ?></wp:comment_user_id>
  240. </wp:comment>
  241. <?php } } ?>
  242.     </item>
  243. <?php } } } ?>
  244. </channel>
  245. </rss>
  246. <?php
  247. }
  248.  
  249. function ra_export_page() {
  250.     global $wpdb, $wp_locale;
  251.     if(!current_user_can('edit_files')) {
  252.         die( 'You don\'t have permissions to use this page.' );
  253.     }
  254.     $months = "";
  255.     for ( $i = 1; $i < 13; $i++ ) {
  256.         $months .= "\t\t\t<option value=\"" . zeroise($i, 2) . '">' .
  257.             $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ) . "</option>\n";
  258.     } ?>
  259. <div class="wrap">
  260. <?php screen_icon(); ?>
  261. <h2><?php echo wp_specialchars( $title ); ?></h2>
  262.  
  263. <p><?php _e('When you click the button below WordPress will create an XML file for you to save to your computer.'); ?></p>
  264. <p><?php _e('This format, which we call WordPress eXtended RSS or WXR, will contain your posts, pages, comments, custom fields, categories, and tags.'); ?></p>
  265. <p><?php _e('Once you&#8217;ve saved the download file, you can use the Import function on another WordPress blog to import this blog.'); ?></p>
  266. <form action="" method="get">
  267. <input type="hidden" name="page" value="ra_export" />
  268. <h3><?php _e('Options'); ?></h3>
  269.  
  270. <table class="form-table">
  271. <tr>
  272. <th><label for="mm_start"><?php _e('Restrict Date'); ?></label></th>
  273. <td><strong><?php _e('Start:'); ?></strong> <?php _e('Month'); ?>&nbsp;
  274. <select name="mm_start" id="mm_start">
  275. <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
  276. <?php echo $months; ?>
  277. </select>&nbsp;<?php _e('Year'); ?>&nbsp;
  278. <input type="text" id="aa_start" name="aa_start" value="" size="4" maxlength="5" />
  279. </td>
  280. <td><strong><?php _e('End:'); ?></strong> <?php _e('Month'); ?>&nbsp;
  281. <select name="mm_end" id="mm_end">
  282. <option value="all" selected="selected"><?php _e('All Dates'); ?></option>
  283. <?php echo $months; ?>
  284. </select>&nbsp;<?php _e('Year'); ?>&nbsp;
  285. <input type="text" id="aa_end" name="aa_end" value="" size="4" maxlength="5" />
  286. </td>
  287. </tr>
  288. <tr>
  289. <th><label for="author"><?php _e('Restrict Author'); ?></label></th>
  290. <td>
  291. <select name="author" id="author">
  292. <option value="all" selected="selected"><?php _e('All Authors'); ?></option>
  293. <?php
  294. $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );
  295. foreach ( $authors as $id ) {
  296.     $o = get_userdata( $id );
  297.     echo "<option value='{$o->ID}'>{$o->display_name}</option>\n";
  298. }
  299. ?>
  300. </select>
  301. </td>
  302. </tr>
  303. <?php if(version_compare($wpdb->db_version(), '4.1', 'ge')) { ?>
  304. <tr>
  305. <th><label for="category"><?php _e('Restrict Category'); ?></label></th>
  306. <td>
  307. <select name="category" id="category">
  308. <option value="all" selected="selected"><?php _e('All Categories'); ?></option>
  309. <?php
  310. $categories = (array) get_categories('get=all');
  311. if($categories) {
  312.     foreach ( $categories as $cat ) {
  313.         echo "<option value='{$cat->term_taxonomy_id}'>{$cat->name}</option>\n";
  314.     }
  315. }
  316. ?>
  317. </select>
  318. </td>
  319. </tr>
  320. <?php } ?>
  321. <tr>
  322. <th><label for="post_type"><?php _e('Restrict Content'); ?></label></th>
  323. <td>
  324. <select name="post_type" id="post_type">
  325. <option value="all" selected="selected"><?php _e('All Content'); ?></option>
  326. <option value="page"><?php _e('Pages'); ?></option>
  327. <option value="post"><?php _e('Posts'); ?></option>
  328. <?php /*mod jrc 300312 - allow attachments only*/ ?>
  329. <option value="attachment"><?php _e('Attachments'); ?></option>
  330. <?php /*mod jrc 300312*/ ?>
  331. </select>
  332. </td>
  333. </tr>
  334. <tr>
  335. <th><label for="status"><?php _e('Restrict Status'); ?></label></th>
  336. <td>
  337. <select name="status" id="status">
  338. <option value="all" selected="selected"><?php _e('All Statuses'); ?></option>
  339. <option value="draft"><?php _e('Draft'); ?></option>
  340. <option value="private"><?php _e('Privately published'); ?></option>
  341. <option value="publish"><?php _e('Published'); ?></option>
  342. <option value="future"><?php _e('Scheduled'); ?></option>
  343. </select>
  344. </td>
  345. </tr>
  346. <tr>
  347. <th><label for="terms"><?php _e('Include Blog Tag/Category Terms'); ?></label></th>
  348. <td>
  349. <select name="terms" id="terms">
  350. <option value="all" selected="selected"><?php _e('All Terms'); ?></option>
  351. <option value="cats"><?php _e('Categories'); ?></option>
  352. <option value="tags"><?php _e('Tags'); ?></option>
  353. <option value="none"><?php _e('None'); ?></option>
  354. </select>
  355. </td>
  356. </tr>
  357. </table>
  358. <p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Download Export File'); ?>" />
  359. <input type="hidden" name="download" value="true" />
  360. </p>
  361. </form>
  362. </div>
  363. <?php
  364. }
  365. function ra_add_export_page() {
  366.     add_management_page('Advanced Export', 'Advanced Export', 10, 'ra_export', 'ra_export_page');
  367. }
  368. add_action('admin_menu', 'ra_add_export_page');
  369.  
  370. function ra_export_setup() {
  371.     if(!function_exists('wxr_missing_parents')) {
  372.         function wxr_missing_parents($categories) {
  373.             if ( !is_array($categories) || empty($categories) )
  374.                 return array();
  375.  
  376.             foreach ( $categories as $category )
  377.                 $parents[$category->term_id] = $category->parent;
  378.  
  379.             $parents = array_unique(array_diff($parents, array_keys($parents)));
  380.  
  381.             if ( $zero = array_search('0', $parents) )
  382.                 unset($parents[$zero]);
  383.  
  384.             return $parents;
  385.         }
  386.     }
  387.     if(!function_exists('wxr_cdata')) {
  388.         function wxr_cdata($str) {
  389.             if ( seems_utf8($str) == false )
  390.                 $str = utf8_encode($str);
  391.  
  392.             // $str = ent2ncr(wp_specialchars($str));
  393.  
  394.             $str = "<![CDATA[$str" . ( ( substr($str, -1) == ']' ) ? ' ' : '') . "]]>";
  395.  
  396.             return $str;
  397.         }
  398.     }
  399.     if(!function_exists('wxr_site_url')) {
  400.         function wxr_site_url() {
  401.             global $current_site;
  402.  
  403.             // mu: the base url
  404.             if ( isset($current_site->domain) ) {
  405.                 return 'http://'.$current_site->domain.$current_site->path;
  406.             }
  407.             // wp: the blog url
  408.             else {
  409.                 return get_bloginfo_rss('url');
  410.             }
  411.         }
  412.     }
  413.     if(!function_exists('wxr_cat_name')) {
  414.         function wxr_cat_name($c) {
  415.             if ( empty($c->name) )
  416.                 return;
  417.  
  418.             echo '<wp:cat_name>' . wxr_cdata($c->name) . '</wp:cat_name>';
  419.         }
  420.     }
  421.     if(!function_exists('wxr_category_description')) {
  422.         function wxr_category_description($c) {
  423.             if ( empty($c->description) )
  424.                 return;
  425.  
  426.             echo '<wp:category_description>' . wxr_cdata($c->description) . '</wp:category_description>';
  427.         }
  428.     }
  429.     if(!function_exists('wxr_tag_name')) {
  430.         function wxr_tag_name($t) {
  431.             if ( empty($t->name) )
  432.                 return;
  433.  
  434.             echo '<wp:tag_name>' . wxr_cdata($t->name) . '</wp:tag_name>';
  435.         }
  436.     }
  437.     if(!function_exists('wxr_tag_description')) {
  438.         function wxr_tag_description($t) {
  439.             if ( empty($t->description) )
  440.                 return;
  441.  
  442.             echo '<wp:tag_description>' . wxr_cdata($t->description) . '</wp:tag_description>';
  443.         }
  444.     }
  445.     if(!function_exists('wxr_post_taxonomy')) {
  446.         function wxr_post_taxonomy() {
  447.             $categories = get_the_category();
  448.             $tags = get_the_tags();
  449.             $the_list = '';
  450.             $filter = 'rss';
  451.  
  452.             if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
  453.                 $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
  454.                 // for backwards compatibility
  455.                 $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
  456.                 // forwards compatibility: use a unique identifier for each cat to avoid clashes
  457.                 // http://trac.wordpress.org/ticket/5447
  458.                 $the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
  459.             }
  460.  
  461.             if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
  462.                 $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
  463.                 $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
  464.                 // forwards compatibility as above
  465.                 $the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
  466.             }
  467.  
  468.             echo $the_list;
  469.         }
  470.     }
  471. }
  472. /*mod jrc 290312 - new func to omit tags and cats for posts when unselected by terms option*/
  473.         function scl_wxr_post_taxonomy($terms = 'all') {
  474.  
  475.             if (empty($terms) || $terms =='none') return;
  476.  
  477.             $categories = get_the_category();
  478.             $tags = get_the_tags();
  479.             $the_list = '';
  480.             $filter = 'rss';
  481.  
  482.             if ( ($terms == 'cats' || $terms =='all' ) && !empty($categories) ) foreach ( (array) $categories as $category ) {
  483.                 $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
  484.                 // for backwards compatibility
  485.                 $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
  486.                 // forwards compatibility: use a unique identifier for each cat to avoid clashes
  487.                 // http://trac.wordpress.org/ticket/5447
  488.                 $the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
  489.             }
  490.  
  491.             if ( ($terms == 'tags' || $terms =='all' ) && !empty($tags) ) foreach ( (array) $tags as $tag ) {
  492.                 $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
  493.                 $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
  494.                 // forwards compatibility as above
  495.                 $the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
  496.             }
  497.  
  498.             echo $the_list;
  499.         }
  500.  
  501. /*end mod jrc 290312*/
  502. ?>