WordPress.org

Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#4477 closed defect (bug) (fixed)

Unfiltered post titles in Recent Comments widget

Reported by: jhodgdon Owned by:
Milestone: 2.2.2 Priority: normal
Severity: normal Version: 2.2
Component: General Keywords: widget, filter, has_patch
Focuses: Cc:

Description

The Recent Comments widget puts its post titles on the screen without filtering them with the standard 'the_title' filter. Post titles should always be filtered.

Verified filter missing in [5708] in trunk. Would be nice to patch the 2.2 branch as well as trunk, if it's not too much trouble. I will attach a patch...

Attachments (2)

widgets-php.diff (1.0 KB) - added by jhodgdon 11 years ago.
Patch to add filter to post titles for Recent Comments widget
get-the-title.diff (4.1 KB) - added by jhodgdon 11 years ago.
Alternative patch that puts the filtering into get_the_title. Also removes filtering from the users of get_the_title, since they won't need fitlering now.

Download all attachments as: .zip

Change History (8)

@jhodgdon
11 years ago

Patch to add filter to post titles for Recent Comments widget

#1 @ryan
11 years ago

We should just apply it in get_the_title instead of the_title.

#2 @jhodgdon
11 years ago

I'm not sure what you're suggesting, Ryan.

All over WordPress, the get_the_xyz functions are unfiltered, and the the_xyz functions call get_the_xyz, filter, and echo. So I don't think adding the filter to get_the_title is probably a good idea, if that is what you're suggesting. get_the_title is used in 22 places in the code base...

Or maybe you are saying to use the_title() instead of get_the_title()? Unfortunately, the_title does not take the post ID as an argument, so that won't work either.

#3 @ryan
11 years ago

I'm saying not filtering in the get functions is silly. We could do it in one place instead of applying these patches everywhere. If someone wants the field unfiltered, grab it from the post object.

#4 @jhodgdon
11 years ago

Ah. That would certainly make my life easier, if all of the get_the_xyz functions had the filters built into them, or at least get_the_title. But I'm also wondering if it's a little dangerous to change the behavior of all the get_xyz functions at this point, given that plugins/themes could conceivably be using them for something. They've been unfiltered for quite a while.

I checked on the get_the_title() function in [5718] and it looks like putting the filters in it would help all but one of the 22 uses of the function in the core, rather than hurting anything. The one place I wasn't sure about was in the_title, which puts $before and $after onto the title text before filtering. I suppose a $filter=true argument could be added to get_the_title to take care of that.

So, I've made a patch for get_the_title... will leave it to you to decide whether it would break plugins to change the behavior of get_the_title to filtered by default. I did apply it in my own test blog, and it didn't appear to break anything. Also it fixed the reported bug with the Recent Comments widget. Again, tested in [5718].

@jhodgdon
11 years ago

Alternative patch that puts the filtering into get_the_title. Also removes filtering from the users of get_the_title, since they won't need fitlering now.

#5 @ryan
11 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5752]) Move the_title filter to get_the_title. Props jhodgdon. fixes #4477

#6 @ryan
11 years ago

That changes the behavior of the_title. I looked over a bunch of plugins to see how the_title was being used, and I think the change should be low impact.

Note: See TracTickets for help on using tickets.