Opened 6 months ago
Last modified 4 months ago
#22413 new defect (bug)
get_the_excerpt() missing a check on $post->post_excerpt
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 3.6 |
| Component: | Warnings/Notices | Version: | |
| Severity: | minor | Keywords: | has-patch |
| Cc: | jeremy+wp@… |
Description
Functions like get_the_title() include isset() or !empty() checks on post object variables, but get_the_excerpt() is missing any such check. This missing check triggers PHP warnings if post_excerpt is not set.
has_excerpt() addresses this for template usage, but nothing addresses this inside get_the_excerpt() itself.
Attached patch adds an isset() check, and correctly passes an empty string if it doesn't.
(Possibly of note: other convenience functions have this same issue -- get_the_guid(), get_the_ID(), etc...)
Attachments (1)
Change History (6)
johnjamesjacoby — 6 months ago
comment:1
johnjamesjacoby — 6 months ago
That's an interesting inconsistency. Under what situation would we have a post object without post_excerpt? Is that still a valid post object? Are these notices we should actually be suppressing, or should developers see them?
With 3.5, any WP_Post object will automatically have post_excerpt = ''.
comment:3
in reply to:
↑ 2
johnjamesjacoby — 6 months ago
Replying to nacin:
Under what situation would we have a post object without post_excerpt?
Any situation where a plugin decides to unset it. Whether that's right or wrong is debatable, either way, it's possible.
Is that still a valid post object?
It could be? Or it could not be:
global $post; unset( $post->post_excerpt );
...and it's still a post object.
Are these notices we should actually be suppressing, or should developers see them?
We should suppress them where it makes sense to, and here is one of those places, since a post_excerpt isn't operation critical to loading a post (I.E. like a post ID.)
With 3.5, any WP_Post object will automatically have post_excerpt = ''.
Did it not with 3.4? If that's the case, it may already be somewhat of a non-issue specifically related to Jetpack/bbPress.
comment:4
wonderboymusic — 4 months ago
- Milestone changed from Awaiting Review to 3.6

See also: http://bbpress.trac.wordpress.org/ticket/2021 for how this became known.