WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 3 years ago

#10410 closed defect (bug) (worksforme)

Secondary RSS feeds use the wrong function to acquire post titles

Reported by: kingjeffrey Owned by: ryan
Milestone: Priority: normal
Severity: minor Version: 2.8.1
Component: Feeds Keywords: dev-feedback
Focuses: Cc:

Description

The bug occurs on line 1499 of wp-includes/general-template.php. It grabs the post title by calling esc_​html( get_​the_​title() ).

The problem occurs when a plugin injects HTML into the title using the the_title hook, secondary feeds may break and will definitely display incorrectly when selected from the browser's feed icon in the address bar.

Either this function should strip the HTML (not escape it) or call the the_title_attribute() function that returns the title pre filter (this is probably the wrong solution).

Change History (15)

comment:1 kingjeffrey5 years ago

As an example, click on the RSS icon in Firefox at this URL: http://kingdesk.com/projects/wp-typography/. The wp-Typography plugin wraps numbers in <span class="numbers">. It also tests for is_feed() before filtering at the the_title hook. By calling the get_the_title() function at line 1499 of wp-includes/general-template.php you return a false negative for is_feed(), and the HTML code is improperly injected.

comment:2 peaceablewhale5 years ago

  • Component changed from Feeds to Template
  • Keywords RSS HTML removed

I don't think plugins should insert HTML to the_title. the_title is intended to be the exact words of the post's title.

comment:3 kingjeffrey5 years ago

  • Cc jeff@… added

@peaceablewhale

Inline HTML tags are valid syntax inside <code>h1<\code> and <code>h2<\code> elements. It is nice that you don't think I should be able to have the typographic control that valid HTML and CSS allow, but I will have to respectfully disagree.

I understand there can be complications with HTML in the headings. Specifically, feed readers often choke on it. And that is why this bug report is filed; to allow for an <code>is_feed()<\code> test that actually works, so HTML can be selectively inserted. All I am asking for is that the secondary feeds are treated the same as primary feeds.

Right now, the application is HTML injection. But regardless of the application <code>is_feed()<\code> is broken for secondary feeds.

comment:4 peaceablewhale5 years ago

  • Keywords dev-feedback added

I believe that the_title is designed for plain text, not HTML. A valid WordPress post title can be something like "Common usage of <div> and <p>". As a result, HTML code must not be removed. See also #9993.

comment:5 kingjeffrey5 years ago

@dev-feedback

Regardless of HTML in the post title; is_feed() is broken for secondary feeds. If _any_ processing is done of the post title by a plugin, it is applied to secondary feed titles. Even if the filter is wrapped in if( !is_feed() ).

Regarding your observation that feed titles be something like "Common usage of <div> and <p>", that is what &lt; is for. I believe that in the HTML editor (not the WYSIWYG editor), people should reasonably be expected to know basic HTML, and HTML tags should be recognized as such in the title field (unless they are explicitly escaped). It currently is not... whatever. But that is a different issue entirely than is_feed() not working for secondary feeds.

comment:6 kingjeffrey5 years ago

I think I may have confused the issue by mentioning HTML tags at all. I apologize for that.

Let me clearly state the issue. is_feed() not working for secondary feed titles. I believe it has something to do with the use of the_title() on line 1499 of wp-includes/general-template.php

comment:7 Denis-de-Bernardy5 years ago

  • Component changed from Template to Query
  • Milestone set to 2.9
  • Owner set to ryan

I think you have me confused here. is_feed() is not working when and how?

comment:8 kingjeffrey5 years ago

Here is a specific example:

`

function append_foo_bar($theTitle) {

return $theTitle." foo bar";

}

if(!is_feed()) {

add_filter('the_title', 'append_foo_bar');

}

`

This will append " foo bar" to the title of a post, but not to the title for the main RSS feed. But if you go to the permalink for the post and click on the RSS icon in the location bar, you will see that " foo bar" _is_ appended to the title of the post in the comments feed, and on any category feeds.

comment:9 Denis-de-Bernardy5 years ago

  • Milestone 2.9 deleted
  • Resolution set to invalid
  • Status changed from new to closed

is_feed() will always return false when the plugin is loaded. the WP query occurs after the init hook.

comment:10 follow-up: kingjeffrey5 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

Perhaps this is a better example:

function append_foo_bar($theTitle) {

if(!is_feed()) {

return $theTitle." foo bar";

} else {

return $theTitle;

}

}
add_filter('the_title', 'append_foo_bar');

is_feed() correctly identifies the main RSS feed. But does not identify the secondary RSS feeds (comments and category feeds)

comment:11 kingjeffrey5 years ago

  • Milestone set to 2.9

comment:12 markjaquith4 years ago

  • Milestone changed from 2.9 to Future Release

Need to research the intention behind is_feed() do we need an is_a_feed() function if is_feed() is meant to be specific to the main feed?

comment:13 kingjeffrey4 years ago

@markjaquith

As a plugin developer, the ability to identify if a feed is being fed is important. Feed readers are so bad with character handling, it is often necessary to strip those characters out.

Semantically, perhaps is_feed() should return TRUE for any feed, and is_main_feed() for the primary feed. This would make clear semantic sense. [i.e. there is nothing in is_feed() that would indicate it is intended only to apply to one specific feed]

comment:14 KingdomGeek3 years ago

  • Component changed from Query to Feeds
  • Severity changed from normal to minor

I pulled up a secondary feed (specifically, a category feed) on my site, and my is_feed() conditional feed content showed up just fine; has this been fixed?

comment:15 in reply to: ↑ 10 SergeyBiryukov3 years ago

  • Milestone Future Release deleted
  • Resolution set to worksforme
  • Status changed from reopened to closed

Replying to kingjeffrey:

Perhaps this is a better example:

function append_foo_bar($theTitle) {
    if(!is_feed()) {
        return $theTitle." foo bar";
    } else {
        return $theTitle;
    } 
}
add_filter('the_title', 'append_foo_bar');

is_feed() correctly identifies the main RSS feed. But does not identify the secondary RSS feeds (comments and category feeds)

I've tested this example in 3.3-trunk and 2.8.1 (the original reported version) and it seems to work fine. "foo bar" is only added to post titles on the frontend, but not in any of the feeds.

Feel free to reopen with more information if there's still a problem.

Note: See TracTickets for help on using tickets.