Make WordPress Core

Opened 4 years ago

Last modified 7 weeks ago

#55523 assigned defect (bug)

Remove deprecation notice from get_the_excerpt

Reported by: jamesglendenning's profile jamesglendenning Owned by: sirlouen's profile SirLouen
Milestone: Future Release Priority: normal
Severity: normal Version: 3.8.1
Component: Posts, Post Types Keywords: has-patch needs-testing needs-unit-tests
Focuses: template 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 (9)

#1 @SergeyBiryukov
4 years ago

  • Description modified (diff)

#2 follow-up: @jrf
4 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
4 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
4 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.

This ticket was mentioned in Slack in #core by sirlouen. View the logs.


8 weeks ago

#6 @SirLouen
8 weeks ago

  • Focuses template added
  • Keywords has-patch needs-testing added; close removed
  • Milestone changed from Awaiting Review to Future Release
  • Owner set to SirLouen
  • Status changed from new to assigned
  • Type changed from enhancement to defect (bug)
  • Version changed from 5.9.2 to 3.8.1

This is a little old, so it's time to see if it's worth it to revive this corpse (or at least to tweak it).

@jrf it seems in [36319] we actually added a potential BC change. It was unfortunate to add the new parameter keeping the same structure which is causing this regression we must fix.

The 2.3 message was left coming from #4439 but the bool check is not enough (nor the deprecation message). It's signaling something incomplete.

We have to track the history of get_the_excerpt to understand that originally it was receiving a parameter that with time was removed, ending with a useless parameter that got deprecated. Receiving any parameter triggered the message like: "you should not add any parameters" (with a not empty check).

Now things are entirely different: Here there is an intersection of two elements: "The new parameter is only accepted, a WP_Post in any of its forms". The rest, falls into the original use-case (the $fakeit parameter), hence it's deprecated.

So as @jamesglendenning suggested, the bool check is limited, and an enhanced check can perfectly take place here, to cover all instances not being a WP_Post or equivalent. It will not cause any backwards compatibility issue and it will keep the original intention of this deprecation notice excluding just the new variable accepted scenarios while keeping the spirit of the deprecation.

Instead of bool I would opt for:

<?php
! is_null( $post ) && ! is_numeric( $post ) && ! ( $post instanceof WP_Post )

Sending a patch with this

Last edited 8 weeks ago by SirLouen (previous) (diff)

#7 @SirLouen
8 weeks ago

  • Keywords needs-unit-tests added

This ticket was mentioned in PR #10563 on WordPress/wordpress-develop by @SirLouen.


8 weeks ago
#8

All the information regarding this patch is provided in the Trac ticket comment: https://core.trac.wordpress.org/ticket/55523#comment:6

I might be expecting some additional unit tests for this patch.

Trac ticket: https://core.trac.wordpress.org/ticket/55523

@SirLouen commented on PR #10563:


7 weeks ago
#9

@westonruter something like that I had in mind, it's better to be more explicit in the message.

Note: See TracTickets for help on using tickets.