PHP fatal error potentially related to ATF and picture tags
Before submitting an issue please check that you’ve completed the following steps:
- Made sure you’re on the latest version ✅
- Used the search feature to ensure that the bug hasn’t been reported before ✅
Describe the bug After upgrading to version 3.16, user reported site went down and the following error was logged:
"PHP Fatal error: Uncaught TypeError: ltrim(): Argument #1 ($string) must be of type string, null given in /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php:222 Stack trace: #0 /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media/AboveTheFold/Frontend/Controller.php(222): ltrim(NULL, '/') #1 [internal function]: WP_Rocket\Engine\Media\AboveTheFold\Frontend\Controller->WP_Rocket\Engine\Media\AboveTheFold\Frontend\{closure}(false) #2 /www/creatureartteacherlive_491/public/wp-content/plugins/wp-rocket/inc/Engine/Media"
In the Slack discussion, Remy said he thought it may be related to:
- how the <picture> tag is being handled.
- Safeguards related to handling exclusions
Expected behavior The error should not occur for all valid <picture> tag markup.
Additional context Ticket - https://secure.helpscout.net/conversation/2605875796/493242/ Website - https://creatureartteacher.com Slack - https://wp-media.slack.com/archives/C43T1AYMQ/p1716485105461249
Acceptance Criteria (for WP Media team use only) Clear instructions for developers, to be added before the grooming
Hello,
We have the same problem on our client's website, here is an example https://www.escoffier.edu/about/chef-instructors/albert-schmid/. Is it possible to get it fixed?
Related: https://secure.helpscout.net/conversation/2662969109/504678/
Scope a solution ✅
We need to safeguard exclusion for empty path or path that aren't valid.
Before the return here we can add a check for the $exclusion['path'] if it's set.
if ( isset( $exclusion['path'] ) && is_string( $exclusion['path'] ) ) {
return ltrim( $parsed_url['path'], '/' );
}
//Return empty string if not set.
return '';
Estimate the effort
Effort XS
Looks ok to me