Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#55523 new enhancement

Remove deprecation notice from get_the_excerpt

Reported by: jamesglendenning's profile jamesglendenning Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9.2
Component: Posts, Post Types Keywords: close
Focuses: Cc:

Description (last modified by SergeyBiryukov)

The deprecation notice for is_bool inside get_the_excerpt has long been redundant, it's been well over a decade since this function took a bool value of $fakeit & the deprecation notice is now just making noise, as it will still pass this value through to get_post regardless of it it's a bool value or not.

The line for this notice is: https://github.com/WordPress/wordpress-develop/blob/5.9/src/wp-includes/post-template.php#L408

There was previously a Trac ticket that looked at removing the notice, but it looks like it never made it into core: #27246.

Change History (4)

#1 @SergeyBiryukov
3 years ago

  • Description modified (diff)

#2 follow-up: @jrf
3 years ago

  • Keywords close added

Thanks for opening this ticket and your suggestion.

the deprecation notice is now just making noise

The deprecation notice only makes "noise" when a boolean is passed to the function, which indicates a dev-error. I'd say keep the deprecation notice and fix the dev error instead.

#3 in reply to: ↑ 2 @jamesglendenning
3 years ago

Replying to jrf:

Thanks for opening this ticket and your suggestion.

the deprecation notice is now just making noise

The deprecation notice only makes "noise" when a boolean is passed to the function, which indicates a dev-error. I'd say keep the deprecation notice and fix the dev error instead.

On further investigation as to why this was being triggered, it looks like we may have passed true/false to the function via a data sync. Interestingly though, the following will still return the post excerpt of the post you're on.

<?php
get_the_excerpt(false)
get_the_excerpt(true)

On one hand it's telling you off & with the other it's handing you the output. This assumption based logic may have led the developer to believe the function was working as intended, if they had muted deprecation warnings on their local machine.

Could the check be improved by checking for all types & returning empty if an unexpected input is parsed?

<?php
if ( null !== $post && is_bool( $post ) && ! ($post instanceof WP_Post) ) {
   _deprecated_argument( __FUNCTION__, '2.3.0' );
   return '';
}

#4 @jrf
3 years ago

@jamesglendenning While I understand where you are coming from, changing the behaviour of the function would be a backward-compatibility break, so no, that would not be considered as a viable patch.

Note: See TracTickets for help on using tickets.