WordPress Trac: Ticket #3884: Refactor the_content_rss() to the_content_feed()https://core.trac.wordpress.org/ticket/3884
<p>
Plugins using the filter "the_content_rss" are never applied in the RSS2 and Atom feeds, and still not working in the &lt;content:encoded&gt; tag of the RDF feed.
</p>
<p>
Line 45 in wp-rss2.php should be:
</p>
<pre class="wiki">&lt;content:encoded&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',, 2) ?&gt;]]&gt;
&lt;/content:encoded&gt;
</pre><p>
Line 39 in wp-atom.php should be:
</p>
<pre class="wiki">&lt;content type="&lt;?php bloginfo('html_type'); ?&gt;" mode="escaped"
xml:base="&lt;?php permalink_single_rss() ?&gt;"&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',, 2) ?&gt;]]&gt;
&lt;/content&gt;
</pre><p>
Line 52 in wp-rdf.php should be:
</p>
<pre class="wiki">&lt;content:encoded&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',, 2) ?&gt;]]&gt;
&lt;/content:encoded&gt;
</pre><p>
or something like that...
</p>
en-usWordPress Trachttps://core.trac.wordpress.org/chrome/site/your_project_logo.pnghttps://core.trac.wordpress.org/ticket/3884
Trac 1.0.1westiTue, 27 Feb 2007 17:40:14 GMTsummary, description changed; milestone sethttps://core.trac.wordpress.org/ticket/3884#comment:1
https://core.trac.wordpress.org/ticket/3884#comment:1
<ul>
<li><strong>summary</strong>
changed from <em>the_content_rss() is used correctly in wp-rdf.php, wp-rss2.php and wp-atom.php</em> to <em>the_content_rss() is used incorrectly in wp-rdf.php, wp-rss2.php and wp-atom.php</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/3884?action=diff&amp;version=1">diff</a>)
</li>
<li><strong>milestone</strong>
set to <em>2.2</em>
</li>
</ul>
TicketjeroyangFri, 02 Mar 2007 03:26:03 GMThttps://core.trac.wordpress.org/ticket/3884#comment:2
https://core.trac.wordpress.org/ticket/3884#comment:2
<blockquote class="citation">
<p>
Line 45 in wp-rss2.php should be:
</p>
</blockquote>
<pre class="wiki">&lt;content:encoded&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',0 , 3) ?&gt;]]&gt;
&lt;/content:encoded&gt;
</pre><blockquote class="citation">
<p>
Line 39 in wp-atom.php should be:
</p>
</blockquote>
<pre class="wiki">&lt;content type="&lt;?php bloginfo('html_type'); ?&gt;" mode="escaped"
xml:base="&lt;?php permalink_single_rss() ?&gt;"&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',0 , 3) ?&gt;]]&gt;
&lt;/content&gt;
</pre><blockquote class="citation">
<p>
Line 52 in wp-rdf.php should be:
</p>
</blockquote>
<pre class="wiki">&lt;content:encoded&gt;
&lt;![CDATA[&lt;?php the_content_rss('', 0, '',0 , 3) ?&gt;]]&gt;
&lt;/content:encoded&gt;
</pre><p>
by the way, the_content_rss() should always apply "the_content" filter first and then "the_content_rss" filter to keep almost all plugins involving content filter works on feeds.
</p>
<p>
On the other hand, to apply "the_content_rss" filter only in the_content_rss() is logically correct but we have to fix hundred of plugins to make wanted output.
</p>
TicketOtto42Tue, 06 Mar 2007 19:34:05 GMThttps://core.trac.wordpress.org/ticket/3884#comment:3
https://core.trac.wordpress.org/ticket/3884#comment:3
<p>
the_content_rss() is doing some weird things that should probably be fixed before making this change. It seems to change links into references, while putting those links at the bottom of the post. It's just unusual and I don't think we should switch to using it until we know why it's doing that.
</p>
TicketjhodgdonWed, 07 Mar 2007 05:34:41 GMThttps://core.trac.wordpress.org/ticket/3884#comment:4
https://core.trac.wordpress.org/ticket/3884#comment:4
<p>
Note that the "weird things" are only happening in the_content_rss under some circumstances. The latest suggested fix sets the last ($encode_html) input argument to 3, and the 4th ($cut) argument to 0, which basically circumvents all the weirdness.
</p>
<p>
With those inputs, the_content_rss function is basically just doing get_the_content (which is unfiltered), then filtering using "the_content_rss" filter, then making sure any ]]&gt; strings are escaped with entities.
</p>
<p>
The above note about not filtering with "the_content" seems on the mark to me. But my concern would be that adding "the_content" as a filter to the_content_rss might break something else. I suppose it could be added only if $encode_html had the value of 3 (previously unused).
</p>
<p>
One other note: the suggested fixes above will need to be added to different files on different lines. As of trunk SVN 4984, all the content of the 3 files mentioned above has been moved into corresponding files in wp-includes:
</p>
<p>
wp-includes/feed-rss2.php wp-includes/feed-atom.php wp-includes/feed-rdf.php
</p>
<p>
Thoughts?
</p>
TicketfoolswisdomTue, 27 Mar 2007 23:35:31 GMTmilestone changedhttps://core.trac.wordpress.org/ticket/3884#comment:5
https://core.trac.wordpress.org/ticket/3884#comment:5
<ul>
<li><strong>milestone</strong>
changed from <em>2.2</em> to <em>2.4</em>
</li>
</ul>
TicketjoostdevalkSun, 23 Sep 2007 19:37:43 GMTowner, summary changed; cc sethttps://core.trac.wordpress.org/ticket/3884#comment:6
https://core.trac.wordpress.org/ticket/3884#comment:6
<ul>
<li><strong>cc</strong>
<em>joostdevalk</em> added
</li>
<li><strong>owner</strong>
changed from <em>anonymous</em> to <em>joostdevalk</em>
</li>
<li><strong>summary</strong>
changed from <em>the_content_rss() is used incorrectly in wp-rdf.php, wp-rss2.php and wp-atom.php</em> to <em>the_content_rss() is used incorrectly in non RSS feeds.</em>
</li>
</ul>
<p>
This fix is heavily needed as there is no way to change the content of an rss2 feed at the moment other than hacking the source...
</p>
TicketjoostdevalkSun, 23 Sep 2007 19:43:06 GMTattachment sethttps://core.trac.wordpress.org/ticket/3884
https://core.trac.wordpress.org/ticket/3884
<ul>
<li><strong>attachment</strong>
set to <em>patch.diff</em>
</li>
</ul>
<p>
Patch.
</p>
TicketjoostdevalkSun, 23 Sep 2007 19:44:10 GMTkeywords sethttps://core.trac.wordpress.org/ticket/3884#comment:7
https://core.trac.wordpress.org/ticket/3884#comment:7
<ul>
<li><strong>keywords</strong>
<em>needs-testing</em> <em>has-patch</em> added
</li>
</ul>
TicketOtto42Mon, 24 Sep 2007 15:15:02 GMThttps://core.trac.wordpress.org/ticket/3884#comment:8
https://core.trac.wordpress.org/ticket/3884#comment:8
<p>
Replying to <a class="closed" href="https://core.trac.wordpress.org/ticket/3884#comment:6" title="Comment 6 for Ticket #3884">joostdevalk</a>:
</p>
<blockquote class="citation">
<p>
This fix is heavily needed as there is no way to change the content of an rss2 feed at the moment other than hacking the source...
</p>
</blockquote>
<p>
Wha? Sure there is. Add a filter to the_content and use an if (is_feed()) type of statement.
</p>
TicketjoostdevalkMon, 24 Sep 2007 15:16:51 GMThttps://core.trac.wordpress.org/ticket/3884#comment:9
https://core.trac.wordpress.org/ticket/3884#comment:9
<p>
Yeah found that out too, not the way you'd want it though...
</p>
TicketjeroyangMon, 24 Sep 2007 15:50:23 GMThttps://core.trac.wordpress.org/ticket/3884#comment:10
https://core.trac.wordpress.org/ticket/3884#comment:10
<p>
To Qtto42
</p>
<p>
Wow! That is really a simple way!!
</p>
<p>
I have solved this problem in my plugin "<a class="ext-link" href="http://jerome.zh-tw.org/archives/151#english"><span class="icon">​</span>sataytube</a>",
I tried to overwrite the wp-rdf.php, wp-rss2.php and wp-atom.php by adding actions through the hooks of atom_head, rss2_head, and rdf_head. It's too fat.
</p>
TicketsantosjThu, 27 Dec 2007 22:13:23 GMTcomponent changedhttps://core.trac.wordpress.org/ticket/3884#comment:11
https://core.trac.wordpress.org/ticket/3884#comment:11
<ul>
<li><strong>component</strong>
changed from <em>General</em> to <em>Template</em>
</li>
</ul>
TicketfuggiSun, 30 Dec 2007 22:28:32 GMThttps://core.trac.wordpress.org/ticket/3884#comment:12
https://core.trac.wordpress.org/ticket/3884#comment:12
<p>
I also thing that the rss2 feed should use the_content_rss function and not the_content, the attatched diff looks fine for me!
</p>
<p>
the_content filters should not be applied to the the_content_rss function, that does not make sense and the is_feed() check is only a workarround for that. Plugin developers should have possibility to add filters to get_the_content if they want to have their filter applied all the time or they have to add their filter twice. This ticket goes into the same direction (filter with the excerpt and post): <a class="ext-link" href="http://trac.wordpress.org/ticket/4679"><span class="icon">​</span>http://trac.wordpress.org/ticket/4679</a>
</p>
Ticketthee17Wed, 26 Mar 2008 10:31:15 GMTmilestone changedhttps://core.trac.wordpress.org/ticket/3884#comment:13
https://core.trac.wordpress.org/ticket/3884#comment:13
<ul>
<li><strong>milestone</strong>
changed from <em>2.5</em> to <em>2.6</em>
</li>
</ul>
TicketscribuSat, 19 Jul 2008 22:18:41 GMTmilestone changedhttps://core.trac.wordpress.org/ticket/3884#comment:14
https://core.trac.wordpress.org/ticket/3884#comment:14
<ul>
<li><strong>milestone</strong>
changed from <em>2.9</em> to <em>2.6.1</em>
</li>
</ul>
TicketwestiSat, 16 Aug 2008 21:02:42 GMTmilestone changedhttps://core.trac.wordpress.org/ticket/3884#comment:15
https://core.trac.wordpress.org/ticket/3884#comment:15
<ul>
<li><strong>milestone</strong>
changed from <em>2.6.1</em> to <em>2.9</em>
</li>
</ul>
<p>
Setting back to 2.9
</p>
TicketdougalFri, 17 Oct 2008 22:01:18 GMTcc changedhttps://core.trac.wordpress.org/ticket/3884#comment:16
https://core.trac.wordpress.org/ticket/3884#comment:16
<ul>
<li><strong>cc</strong>
<em>dougal</em> <em>westi</em> added
</li>
</ul>
<p>
So, is there any reasoning behind the inconsistent usage of the_content_rss()? It's used in some feed types (rdf and rss) but not others (rss2 and atom). What's up with that?
</p>
<p>
I ran across this today when I needed a plugin to modify feed content differently than regular page views. Ended up using is_feed() in my the_content filter but that just seems clunky to me.
</p>
<p>
Either we can rely on the_content_rss, or we can't. Which is it? The function doesn't need to do anything fancy. Just get_the_content(), and apply any 'the_content_rss' filters to it. All those parameters seem like overkill to me. Refactor those into their own filter functions. It would break backwards compatibility, but I figure this function is broken already anyways.
</p>
<p>
Oh, and it should probably be deprecated in favor of renaming it to 'the_content_feed', anyways, right? That could fix the backwards compatibility issue.
</p>
<p>
get_the_content_feed()
the_content_feed()
the_content_rss() -- deprecate
</p>
TicketDenis-de-BernardyTue, 28 Apr 2009 11:11:22 GMThttps://core.trac.wordpress.org/ticket/3884#comment:17
https://core.trac.wordpress.org/ticket/3884#comment:17
<p>
Cross-referencing: <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/8706" title="defect (bug): Inconsistent use of the_content() and the_content_rss() (closed: invalid)">#8706</a>, <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/4967" title="defect (bug): Obsolete the RSS 0.92 feed (closed: fixed)">#4967</a>
</p>
TicketDenis-de-BernardySun, 10 May 2009 13:18:39 GMThttps://core.trac.wordpress.org/ticket/3884#comment:18
https://core.trac.wordpress.org/ticket/3884#comment:18
<p>
Also: <a class="closed ticket" href="https://core.trac.wordpress.org/ticket/4968" title="defect (bug): make_url_footnote() function not used (closed: fixed)">#4968</a>
</p>
TicketDenis-de-BernardySun, 10 May 2009 13:19:25 GMTcomponent changedhttps://core.trac.wordpress.org/ticket/3884#comment:19
https://core.trac.wordpress.org/ticket/3884#comment:19
<ul>
<li><strong>component</strong>
changed from <em>Template</em> to <em>Feeds</em>
</li>
</ul>
TicketryanFri, 28 Aug 2009 14:48:13 GMThttps://core.trac.wordpress.org/ticket/3884#comment:20
https://core.trac.wordpress.org/ticket/3884#comment:20
<p>
dougal's suggestion of moving to the_content_feed sounds good.
</p>
TicketscribuFri, 28 Aug 2009 15:05:53 GMTkeywords, summary changedhttps://core.trac.wordpress.org/ticket/3884#comment:21
https://core.trac.wordpress.org/ticket/3884#comment:21
<ul>
<li><strong>keywords</strong>
<em>needs-patch</em> added; <em>needs-testing</em> <em>has-patch</em> removed
</li>
<li><strong>summary</strong>
changed from <em>the_content_rss() is used incorrectly in non RSS feeds.</em> to <em>Refactor the_content_rss() to the_content_feed()</em>
</li>
</ul>
TicketwestiSat, 29 Aug 2009 18:09:48 GMThttps://core.trac.wordpress.org/ticket/3884#comment:22
https://core.trac.wordpress.org/ticket/3884#comment:22
<p>
Replying to <a class="closed" href="https://core.trac.wordpress.org/ticket/3884#comment:20" title="Comment 20 for Ticket #3884">ryan</a>:
</p>
<blockquote class="citation">
<p>
dougal's suggestion of moving to the_content_feed sounds good.
</p>
</blockquote>
<p>
+1
</p>
TickethakreWed, 09 Sep 2009 14:52:41 GMThttps://core.trac.wordpress.org/ticket/3884#comment:23
https://core.trac.wordpress.org/ticket/3884#comment:23
<p>
Related: <a class="new ticket" href="https://core.trac.wordpress.org/ticket/3260" title="defect (bug): XML output (rss, atom, rdf ...) should always use UTF-8 or CDATA for user ... (new)">#3260</a>
</p>
TicketryanMon, 21 Sep 2009 15:06:43 GMTowner, status changedhttps://core.trac.wordpress.org/ticket/3884#comment:24
https://core.trac.wordpress.org/ticket/3884#comment:24
<ul>
<li><strong>owner</strong>
changed from <em>joostdevalk</em> to <em>ryan</em>
</li>
<li><strong>status</strong>
changed from <em>new</em> to <em>assigned</em>
</li>
</ul>
TicketViper007BondFri, 25 Sep 2009 09:08:41 GMTowner changedhttps://core.trac.wordpress.org/ticket/3884#comment:25
https://core.trac.wordpress.org/ticket/3884#comment:25
<ul>
<li><strong>owner</strong>
changed from <em>ryan</em> to <em>Viper007Bond</em>
</li>
</ul>
<p>
Patch is in the works per lloyd's request.
</p>
TicketViper007BondFri, 25 Sep 2009 10:15:14 GMTattachment sethttps://core.trac.wordpress.org/ticket/3884
https://core.trac.wordpress.org/ticket/3884
<ul>
<li><strong>attachment</strong>
set to <em>3884.patch</em>
</li>
</ul>
TicketViper007BondFri, 25 Sep 2009 10:17:29 GMThttps://core.trac.wordpress.org/ticket/3884#comment:26
https://core.trac.wordpress.org/ticket/3884#comment:26
<p>
Attached patch <em>should</em> output identical content compared to pre-patch, except for two differences:
</p>
<ol><li><tt>the_content_feed</tt> filter is run on the content before it's outputted (all feeds).
</li><li>Shortcodes are now stripped from the RSS1 and RDF feeds (previously they were left raw and that's just ugly).
</li></ol>
TicketViper007BondFri, 25 Sep 2009 10:24:33 GMTkeywords changedhttps://core.trac.wordpress.org/ticket/3884#comment:27
https://core.trac.wordpress.org/ticket/3884#comment:27
<ul>
<li><strong>keywords</strong>
<em>has-patch</em> added; <em>needs-patch</em> removed
</li>
</ul>
<p>
I tested this patch by saving the before and after HTML of each feed and doing a diff on them BTW, so I'm pretty confident this patch is good to go.
</p>
TicketryanFri, 25 Sep 2009 17:19:39 GMTattachment sethttps://core.trac.wordpress.org/ticket/3884
https://core.trac.wordpress.org/ticket/3884
<ul>
<li><strong>attachment</strong>
set to <em>3884.diff</em>
</li>
</ul>
TicketryanFri, 25 Sep 2009 17:23:10 GMThttps://core.trac.wordpress.org/ticket/3884#comment:28
https://core.trac.wordpress.org/ticket/3884#comment:28
<p>
Looks like we both worked on the same thing. FWIW, here's my patch.
</p>
<ul><li>Deprecates the_content_rss()
</li><li>Introduces the_content_feed() and get_the_content_feed() which are just wrappers around get_the_content() that call an extra filter
</li><li>Converts places that called the_content_rss() with an excerpt length to the_excerpt_rss()
</li><li>Gets rid of the rss_use_excerpt conditional in the RSS feed. Both conditions were doing pretty much the same thing except one used CDATA and the excerpt lengths were slightly different
</li><li>Removes the rss_excerpt_length option
</li><li>Uses the_content_feed() where the_content() was previously used
</li></ul>
TicketryanFri, 25 Sep 2009 20:40:28 GMThttps://core.trac.wordpress.org/ticket/3884#comment:29
https://core.trac.wordpress.org/ticket/3884#comment:29
<p>
I don't think we need to bother with having "short" support in the_content_feed(). the_excerpt_rss() seems like the right thing to use for that scenario. Plus, it's only done in rdf and rss, which people want to rip out anyway.
</p>
<p>
I don't think your patch does the replace for ']]&gt;'. I kept it since the_content() does it. We're calling get_the_content(), which doesn't do it for some reason, so we have to add the filter on the_content and the replace on ']]&gt;' back in.
</p>
TicketViper007BondFri, 25 Sep 2009 22:29:44 GMThttps://core.trac.wordpress.org/ticket/3884#comment:30
https://core.trac.wordpress.org/ticket/3884#comment:30
<p>
I considered using <tt>the_excerpt_rss()</tt>, but didn't want to change current behavior. If one were to define a custom excerpt, that would display with your patch (up to any length) and it wouldn't in mine or the current. I'm not familiar enough with the RSS1/RDF spec to know if that's okay or not (i.e. why it was length limited in the first place). Then again (as you said), should we really care about RSS1/RDF?
</p>
<p>
<tt>]]&gt;</tt> was an oversight on my part. I always forget that <tt>the_content()</tt> does extra things over <tt>get_the_content()</tt>.
</p>
<p>
I do like what feed it is being passed to the filter.
</p>
TicketViper007BondFri, 25 Sep 2009 22:31:50 GMThttps://core.trac.wordpress.org/ticket/3884#comment:31
https://core.trac.wordpress.org/ticket/3884#comment:31
<p>
Oh, one other thing:
</p>
<p>
You left out the first parameter on <tt>the_content_feed()</tt> for the RSS2 feed. It shouldn't be assumed that the RSS2 feed is the default feed.
</p>
TicketryanMon, 28 Sep 2009 14:37:20 GMTstatus changed; resolution sethttps://core.trac.wordpress.org/ticket/3884#comment:32
https://core.trac.wordpress.org/ticket/3884#comment:32
<ul>
<li><strong>status</strong>
changed from <em>assigned</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
<p>
<a class="changeset" href="https://core.trac.wordpress.org/changeset/11980" title="Deprecates the_content_rss(). Add the_content_feed() and ...">[11980]</a>
</p>
Ticket