WordPress.org

Make WordPress Core

Ticket #8828: wp-feed-category-2.diff

File wp-feed-category-2.diff, 2.3 KB (added by znarfor, 5 years ago)

update of my previous patch

  • feed.php

     
    290290        $categories = get_the_category(); 
    291291        $tags = get_the_tags(); 
    292292        $the_list = ''; 
    293         $cat_names = array(); 
     293        $cats = array(); 
    294294 
    295295        $filter = 'rss'; 
    296296        if ( 'atom' == $type ) 
    297297                $filter = 'raw'; 
    298298 
    299         if ( !empty($categories) ) foreach ( (array) $categories as $category ) { 
    300                 $cat_names[] = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
     299        if ( !empty($categories) ) foreach ( (array) $categories as $category ) {          
     300                $cat_name = sanitize_term_field('name', $category->name, $category->term_id, 'category', $filter); 
     301                $cats[$cat_name] = $category; 
    301302        } 
    302303 
    303304        if ( !empty($tags) ) foreach ( (array) $tags as $tag ) { 
    304                 $cat_names[] = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
     305                $cat_name = sanitize_term_field('name', $tag->name, $tag->term_id, 'post_tag', $filter); 
     306                $cats[$cat_name] = $tag; 
    305307        } 
    306308 
    307         $cat_names = array_unique($cat_names); 
    308  
    309         foreach ( $cat_names as $cat_name ) { 
    310                 if ( 'rdf' == $type ) 
     309        foreach ( $cats as $cat_name => $category ) { 
     310                if ( 'rdf' == $type ) { 
    311311                        $the_list .= "\t\t<dc:subject><![CDATA[$cat_name]]></dc:subject>\n"; 
    312                 elseif ( 'atom' == $type ) 
    313                         $the_list .= sprintf( '<category scheme="%1$s" term="%2$s" />', esc_attr( apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ) ), esc_attr( $cat_name ) ); 
    314                 else 
    315                         $the_list .= "\t\t<category><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; 
     312                } elseif ( 'atom' == $type ) { 
     313                        $blog_url = apply_filters( 'get_bloginfo_rss', get_bloginfo( 'url' ) ); 
     314                        $scheme = attribute_escape( $category->taxonomy =='post_tag' ? $blog_url . "/tag/" : $blog_url . "/category/" );  
     315                        $label = attribute_escape( $cat_name );  
     316                        $the_list .= "\n\t\t<category scheme=\"$scheme\" term=\"{$category->slug}\" label=\"$label\"/>\n"; 
     317                } else { 
     318                        $domain = $category->taxonomy =='post_tag' ? "tag" : "category"; 
     319                        $the_list .= "\n\t\t<category domain=\"$domain\"><![CDATA[" . @html_entity_decode( $cat_name, ENT_COMPAT, get_option('blog_charset') ) . "]]></category>\n"; 
     320                } 
    316321        } 
    317322 
    318323        return apply_filters('the_category_rss', $the_list, $type);