WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 years ago

#35487 closed enhancement (wontfix)

Update has_excerpt()

Reported by: sebastian.pisula Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

I think that has_excerpt function should be return bool value from get_the_excerpt(). This is update after fix: [36319] where we can filter excerpt

Attachments (2)

35487.patch (745 bytes) - added by sebastian.pisula 4 years ago.
35487.2.patch (1.2 KB) - added by sebastian.pisula 4 years ago.

Download all attachments as: .zip

Change History (12)

#1 follow-up: @swissspidy
4 years ago

  • Component changed from General to Posts, Post Types

Hmm this could lead to false positives where the excerpt has been filtered or when it is a private post.

For example, get_the_excerpt() returns 'There is no excerpt because this is a protected post.' for private posts, but has_excerpt() returns false. With this patch, it would return true.

Sounds like a wontfix because of BC issues.

#2 @swissspidy
4 years ago

  • Keywords close added

#3 in reply to: ↑ 1 @sebastian.pisula
4 years ago

  • Keywords close removed

Replying to swissspidy:

Hmm this could lead to false positives where the excerpt has been filtered or when it is a private post.

For example, get_the_excerpt() returns 'There is no excerpt because this is a protected post.' for private posts, but has_excerpt() returns false. With this patch, it would return true.

Sounds like a wontfix because of BC issues.

I think that this work good. Because for private post the excerpt is 'There is no excerpt because this is a protected post.'. Maybe add new param - $private_excerpt = true and in has_exceprt function get_the_excerpt($post_id, false) ? Example in patch.

#4 follow-up: @swissspidy
4 years ago

That still changes the semantics of the function. get_the_excerpt() is almost never empty because wp_trim_excerpt() is hooked to the get_the_excerpt filter.

has_excerpt() checks if there's a custom excerpt, not if there's some generated excerpt.

#5 follow-up: @sebastian.pisula
4 years ago

current fuction work bad too because in $post->post_excerpt I will be have excerpt and in get_the_excerpt I use filter to remove excerpt so has_excerpt() return true and get_the_excerpt return empty string -> except not exists

#6 in reply to: ↑ 5 @swissspidy
4 years ago

  • Keywords close added

Replying to sebastian.pisula:

current fuction work bad too because in $post->post_excerpt I will be have excerpt and in get_the_excerpt I use filter to remove excerpt so has_excerpt() return true and get_the_excerpt return empty string -> except not exists

This sounds like an edge case. If you do that and you want to make sure get_the_excerpt() is not empty, just use if ( get_the_excerpt() { … } instead of has_excerpt().

The ticket really is a wontfix in my eyes because it breaks backwards-compatibility. Devs expect it to check $post->post_excerpt and not get_the_excerpt().

#7 @SergeyBiryukov
4 years ago

  • Description modified (diff)

#8 @swissspidy
2 years ago

  • Keywords 2nd-opinion added

#9 @SergeyBiryukov
2 years ago

In 40042:

Docs: Clarify that has_excerpt() checks if the post has a custom excerpt, not some generated excerpt.

See #35487.

#10 in reply to: ↑ 4 @SergeyBiryukov
2 years ago

  • Keywords close 2nd-opinion removed
  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

Replying to swissspidy:

has_excerpt() checks if there's a custom excerpt, not if there's some generated excerpt.

[40042] clarifies that in the function description.

I agree with comment:6, changing it now would break backwards compatibility.

Note: See TracTickets for help on using tickets.