Opened 6 years ago
Last modified 8 weeks ago
#52820 reviewing defect (bug)
Possible logic error in wp_trim_excerpt()
| Reported by: | theMikeD | Owned by: | SergeyBiryukov |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Formatting | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests 2nd-opinion |
| Cc: | Focuses: |
Description
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?
Change History (16)
This ticket was mentioned in PR #1126 on WordPress/wordpress-develop by donmhico.
6 years ago
#1
- Keywords has-patch has-unit-tests added
#2
@
6 years ago
Hello @theMikeD. Thanks for the ticket. Yes, I believe you're correct. $raw_excerpt passed to wp_trim_excerpt filter is empty if $text is empty. In my PR above, I placed $raw_excerpt = $text; below the apply_filter( 'the_content' ) because I still believe that $raw_excerpt should be processed by that filter. Others can chime in their thoughts regarding this.
#3
@
6 years ago
- Component General → Posts, Post Types
- Milestone Awaiting Review → 5.8
- Owner set to
- Status new → reviewing
#4
@
5 years ago
- Milestone 5.8 → 5.9
Today is 5.8 Beta 1. Ran out of time for this one to land. Punting to 5.9.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
5 years ago
#6
@
5 years ago
- Milestone 5.9 → 6.0
We have some conflicts to resolve in the above PR. As today is 5.9 beta 1, I think it's safer to move this ticket to 6.0 to ensure it's properly reviewed and fixed.
This ticket was mentioned in Slack in #core by mike. View the logs.
5 years ago
This ticket was mentioned in PR #2541 on WordPress/wordpress-develop by costdev.
5 years ago
#8
Trac ticket: https://core.trac.wordpress.org/ticket/52820
#9
in reply to: ↑ description
;
follow-up:
↓ 13
@
5 years ago
Replying to 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_excerptfilter's$raw_excerptparameter will be empty if$textas supplied to the function is empty. This should be the value of$textat 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 ?
#10
@
4 years ago
- Keywords reporter-feedback added
As this is still being discussed and we're approaching RC1, I'm going to move this ticket to Future Release.
This ticket was mentioned in Slack in #core by sirlouen. View the logs.
10 months ago
#13
in reply to: ↑ 9
@
10 months ago
Replying to jrf:
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
$textparameter.
Is this really the intended behaviour ?
It appears that this concern was not addressed. I'm adding 2nd-opinion for this as it seems it's not a reporter trouble.
#14
@
10 months ago
- Component Posts, Post Types → Formatting
- Keywords 2nd-opinion needs-refresh added; reporter-feedback removed
Also last patch in PR2541 needs refresh.
This ticket was mentioned in PR #12176 on WordPress/wordpress-develop by @sukhendu2002.
4 months ago
#15
- Keywords needs-refresh removed
Trac ticket: https://core.trac.wordpress.org/ticket/52820
#16
@
8 weeks ago
I've opened PR as a refresh of the previous patches against the current trunk: https://github.com/WordPress/wordpress-develop/pull/12176
The PR updates $raw_excerpt for automatically generated excerpts before the text is trimmed and adds focused regression tests for both generated and manually provided excerpts.
It intentionally preserves the existing behavior where manually provided excerpts are not trimmed, keeping the change scoped to the documented $raw_excerpt filter argument.
Reviews and feedback would be appreciated.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This PR assigns the correct value for
$raw_excerptif the passed$textis empty. Right now$raw_excerptis empty if$textis empty.Trac ticket: https://core.trac.wordpress.org/ticket/52820