Make WordPress Core

Opened 4 weeks ago

Last modified 4 weeks ago

#62454 new enhancement

[ wp-includes/shortcodes.php - do_shortcode() ] - fallback in case content is not a string

Reported by: riccardodicurti's profile riccardodicurti Owned by:
Milestone: Awaiting Review Priority: normal
Severity: trivial Version:
Component: Shortcodes Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Good morning everyone, while working on a project on php 8, I found that a plugin was passing content to do_shortcode() that was not a string and this led to an error.

In my opinion, it would therefore be better to add a check, like

if(! is_string($content) ) { return $content; }

, in order to check what is then passed str_contains().

Thanks in advance.

Change History (5)

#2 @umeshsinghin
4 weeks ago

Hi,
As per the suggested changes, I have implemented the fixes. Please review and confirm.

#3 @riccardodicurti
4 weeks ago

Ciao @umeshsinghin, thanks for the pull request. I have tested it with a couple of shortcodes and see no problems.

#4 @riccardodicurti
4 weeks ago

  • Keywords dev-feedback added

#5 @SergeyBiryukov
4 weeks ago

Hi there, thanks for the ticket!

This looks similar to the discussions in #17299, #18927, #23767, and #27489 (those tickets are unrelated to this particular function, but they suggest a similar enhancement for other functions). The consensus was that we should not hide warnings caused by developer errors, unless there is a strong reason. It would just make debugging harder.

If a valid parameter generates a warning, we should certainly fix that. However, in case of an invalid parameter, I think the warning (or an error on PHP 8.0+) is to be expected.

Version 0, edited 4 weeks ago by SergeyBiryukov (next)
Note: See TracTickets for help on using tickets.