WordPress.org

Make WordPress Core

Opened 18 months ago

Closed 11 months ago

Last modified 11 months ago

#22413 closed defect (bug) (invalid)

get_the_excerpt() missing a check on $post->post_excerpt

Reported by: johnjamesjacoby Owned by:
Milestone: 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)

22413.patch (417 bytes) - added by johnjamesjacoby 18 months ago.

Download all attachments as: .zip

Change History (9)

johnjamesjacoby18 months ago

comment:2 follow-up: nacin18 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 johnjamesjacoby17 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 wonderboymusic15 months ago

  • Milestone changed from Awaiting Review to 3.6

comment:5 jeherve15 months ago

  • Cc jeremy+wp@… added

comment:6 nacin11 months 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.

comment:7 aaroncampbell11 months 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.

Note: See TracTickets for help on using tickets.