Make WordPress Core

Changeset 13055


Ignore:
Timestamp:
02/11/2010 07:17:00 PM (14 years ago)
Author:
ryan
Message:

Export post <-> term relationships for all taxonomies. fixes #12180

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/export.php

    r12657 r13055  
    224224 */
    225225function wxr_post_taxonomy() {
    226     $categories = get_the_category();
    227     $tags = get_the_tags();
     226    global $post;
     227
    228228    $the_list = '';
    229229    $filter = 'rss';
    230230
    231     if ( !empty($categories) ) foreach ( (array) $categories as $category ) {
    232         $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter);
    233         // for backwards compatibility
    234         $the_list .= "\n\t\t<category><![CDATA[$cat_name]]></category>\n";
    235         // forwards compatibility: use a unique identifier for each cat to avoid clashes
    236         // http://trac.wordpress.org/ticket/5447
    237         $the_list .= "\n\t\t<category domain=\"category\" nicename=\"{$category->slug}\"><![CDATA[$cat_name]]></category>\n";
     231    $taxonomies = get_object_taxonomies('post');
     232    $terms = wp_get_post_terms($post->ID, $taxonomies);
     233    foreach ( (array) $terms as $term ) {
     234        $domain = ( 'post_tag' == $term->taxonomy ) ? 'tag' : $term->taxonomy;
     235        $term_name = sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, $filter);
     236        // Back compat.
     237        if ( 'category' == $term->taxonomy )
     238            $the_list .= "\n\t\t<category><![CDATA[$term_name]]></category>\n";
     239        elseif ( 'post_tag' == $term->taxonomy )
     240            $the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[$term_name]]></category>\n";
     241        // forwards compatibility as above
     242        $the_list .= "\n\t\t<category domain=\"$domain\" nicename=\"{$term->slug}\"><![CDATA[$term_name]]></category>\n";
    238243    }
    239 
    240     if ( !empty($tags) ) foreach ( (array) $tags as $tag ) {
    241         $tag_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter);
    242         $the_list .= "\n\t\t<category domain=\"tag\"><![CDATA[$tag_name]]></category>\n";
    243         // forwards compatibility as above
    244         $the_list .= "\n\t\t<category domain=\"tag\" nicename=\"{$tag->slug}\"><![CDATA[$tag_name]]></category>\n";
    245     }
    246 
    247244    echo $the_list;
    248245}
Note: See TracChangeset for help on using the changeset viewer.