WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#16372 closed enhancement (fixed)

Abstract the word-trimming logic in wp_trim_excerpt

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

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 5 years ago.
Untested proof of concept.
16372.patch (1.6 KB) - added by SergeyBiryukov 5 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 @nacin5 years ago

  • Keywords needs-patch added

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

@nacin5 years ago

Untested proof of concept.

@SergeyBiryukov5 years ago

comment:3 @SergeyBiryukov5 years ago

  • Keywords has-patch added; needs-patch removed

comment:4 @SergeyBiryukov5 years ago

Ah, never mind my patch then.

comment:5 @nacin4 years ago

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

comment:7 @nacin4 years ago

  • Milestone changed from Future Release to 3.3

This needs to happen for #16799.

comment:8 @SergeyBiryukov4 years ago

Closed #17190 as a duplicate.

comment:9 @aaroncampbell4 years ago

  • Cc aaroncampbell added

comment:10 @duck_4 years ago

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

In [18732]:

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

comment:11 @duck_4 years ago

Some tests: [UT441]

Note: See TracTickets for help on using tickets.