WordPress.org

Make WordPress Core

Ticket #8828: wp-feed-category.diff

File wp-feed-category.diff, 2.1 KB (added by znarfor, 7 years ago)

i tried to not modify too much the function to improve the patch readability, but i think this function can be refactorised somehow after.

  • wp-includes/feed.php

     
    315315        $categories = get_the_category(); 
    316316        $tags = get_the_tags(); 
    317317        $the_list = ''; 
    318         $cat_names = array(); 
     318        $cats = array(); 
    319319 
    320320        $filter = 'rss'; 
    321321        if ( 'atom' == $type ) 
    322322                $filter = 'raw'; 
    323323 
    324324        if ( !empty($categories) ) foreach ( (array) $categories as $category ) { 
    325                 $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
     325                $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
     326                $cats[$cat_name] = $category; 
    326327        } 
    327328 
    328329        if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { 
    329                 $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
     330                $cat_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
     331                $cats[$cat_name] = $tag; 
    330332        } 
    331333 
    332         $cat_names = array_unique($cat_names); 
    333  
    334         foreach ( $cat_names as $cat_name ) { 
     334        foreach ( $cats as $cat_name => $category ) { 
    335335                if ( 'rdf' == $type ) 
    336336                        $the_list .= "\n\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; 
    337                 elseif ( 'atom' == $type ) 
    338                         $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', attribute_escape( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), attribute_escape( $cat_name ) ); 
    339                 else 
    340                         $the_list .= "\n\t\t<category><![CDATA[" . html_entity_decode( $cat_name ) . "]]></category>\n"; 
     337                elseif ( 'atom' == $type ) { 
     338                        $blog_url = apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ); 
     339                        $scheme = attribute_escape( $category->taxonomy =='post_tag' ? $blog_url . "/tag/" : $blog_url . "/category/" ); 
     340                        $label = attribute_escape( $cat_name ); 
     341                        $the_list .= "\n\t\t<category scheme=\"$scheme\" term=\"{$category->slug}\" label=\"$label\"/>\n"; 
     342                } else { 
     343                        $domain = $category->taxonomy =='post_tag' ? "tag" : "category"; 
     344                        $the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[" . html_entity_decode( $cat_name ) . "]]></category>\n"; 
     345                } 
    341346        } 
    342347 
    343348        return apply_filters('the_category_rss', $the_list, $type);