Opened 12 years ago
Closed 11 years ago
#22413 closed defect (bug) (fixed)
get_the_excerpt() missing a check on $post->post_excerpt
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.0 | Priority: | low |
Severity: | minor | Version: | |
Component: | Warnings/Notices | Keywords: | has-patch |
Focuses: | Cc: |
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 (12)
#2
follow-up:
↓ 3
@
12 years 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 = ''
.
#3
in reply to:
↑ 2
@
12 years 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.
#6
@
12 years ago
I think that if post_excerpt is unset, a notice is deserved. That's exactly a situation where a developer should be notified that they did something wrong, rather than suppressing it.
#7
@
12 years ago
- Milestone 3.6 deleted
- Resolution set to invalid
- Status changed from new to closed
All WP_Post objects should have a post_excerpt. If a plugin goes out of it's way to unset this, they should get the notice when they try to access it.
#9
@
11 years ago
- Milestone set to 4.0
- Resolution invalid deleted
- Status changed from closed to reopened
Reopening this, as it's akin to #17034.
See also: http://bbpress.trac.wordpress.org/ticket/2021 for how this became known.