Make WordPress Core

Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#16372 closed enhancement (fixed)

Abstract the word-trimming logic in wp_trim_excerpt

Reported by: nacin Owned by: duck_
Priority: normal Milestone: 3.3
Component: Formatting Version:
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Currently, wp_trim_excerpt() takes a $text value, but if it exists, then all it does is apply the wp_trim_except filter. If it's empty, then $text becomes get_the_content(). All of the logic for actually splitting up words are trapped in this conditional.

I suggest a new function that wp_trim_excerpt can call. Here's the suggested function definition:

function wp_trim_words( $text, $length = 55, $more = '[...]' )

The length and more default values are what gets passed to the excerpt_length and excerpt_more filters. But I'd expect the filters themselves to remain in wp_trim_excerpt.

Attachments (2)

16372.diff (1.7 KB ) - added by nacin 16 years ago.
Untested proof of concept.
16372.patch (1.6 KB ) - added by SergeyBiryukov 16 years ago.

Download all attachments as: .zip

Change History (13)

#1 @nacin
16 years ago

  • Keywords needs-patch added

This also prevents the function from being used outside the loop. Kinda lame.

@nacin
16 years ago

Untested proof of concept.

#3 @SergeyBiryukov
16 years ago

  • Keywords has-patch added; needs-patch removed

#4 @SergeyBiryukov
16 years ago

Ah, never mind my patch then.

#5 @nacin
15 years ago

Either this or #12858 should be closed as a duplicate. #17030 was closed as a duplicate.

#7 @nacin
15 years ago

  • Milestone Future Release3.3

This needs to happen for #16799.

#8 @SergeyBiryukov
15 years ago

Closed #17190 as a duplicate.

#9 @aaroncampbell
15 years ago

  • Cc aaroncampbell added

#10 @duck_
15 years ago

  • Owner set to duck_
  • Resolutionfixed
  • Status newclosed

In [18732]:

Abstract word-trimming from wp_trim_excerpt() into wp_trim_words(). Props nacin. Fixes #16372.

#11 @duck_
15 years ago

Some tests: [UT441]

Note: See TracTickets for help on using tickets.