[wp-trac] [WordPress Trac] #52820: Possible logic error in wp_trim_excerpt()

WordPress Trac noreply at wordpress.org
Fri Apr 8 12:48:44 UTC 2022


#52820: Possible logic error in wp_trim_excerpt()
--------------------------------------+-----------------------------
 Reporter:  theMikeD                  |       Owner:  SergeyBiryukov
     Type:  defect (bug)              |      Status:  reviewing
 Priority:  normal                    |   Milestone:  6.0
Component:  Posts, Post Types         |     Version:
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------------

Comment (by jrf):

 Replying to [ticket:52820 theMikeD]:
 > https://core.trac.wordpress.org/browser/tags/5.7/src/wp-
 includes/formatting.php#L3845
 >
 > Reading this code, it looks like the `wp_trim_excerpt` filter's
 `$raw_excerpt` parameter will be empty if `$text` as supplied to the
 function is empty. This should be the value of `$text` at L3824 should it
 not? Or do I mis-understand?


 I do agree there may be a logic error in this function, but I don't
 necessarily think it's in the filter. Maybe we should have good look at
 what this function is supposed to do ?

 From the docblock:
 {{{
 3798     * Generates an excerpt from the content, if needed.
 3799     *
 3800     * Returns a maximum of 55 words with an ellipsis appended if
 necessary.
 ...
 3808     * @param string             $text Optional. The excerpt. If set
 to empty, an excerpt is generated.
 3809     * @param WP_Post|object|int $post Optional. WP_Post instance or
 Post ID/object. Default null.
 3810     * @return string The excerpt.
 }}}


 Looking at the code, the excerpt is only trimmed to 55 words when it has
 been auto-generated, not when it was provided via the `$text` parameter.

 Is this really the intended behaviour ?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52820#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list