wp-media / wp-rocket

Performance optimization plugin for WordPress
https://wp-rocket.me
GNU General Public License v2.0
701 stars 218 forks source link

Guard our code when the rocket_defer_inline_exclusions filter used by 3rd parties #3576

Closed NataliaDrause closed 3 years ago

NataliaDrause commented 3 years ago

Before submitting an issue please check that you’ve completed the following steps:

Describe the bug 3rd party plugins use our filter rocket_defer_inline_exclusions and pass a string instead of an array. This leads to a PHP warning in the debug.log: PHP Warning: Invalid argument supplied for foreach() in /home4/nataliad/testsite.nataliadrause.com/wp-content/plugins/wp-rocket/inc/Engine/Optimization/DeferJS/DeferJS.php on line 140

Such errors were caused by compatibility codes in ShortPixel AI and Smart Slider 3 plugins so far.

To Reproduce Steps to reproduce the behavior:

  1. Install and activate ShortPixel AI plugin https://wordpress.org/plugins/shortpixel-adaptive-images/
  2. Enable Load JavaScript Deferred option (with jQuery not being excluded from deferring)
  3. Clear and preload cache.
  4. The following error will be logged in debug.log:
    09-Feb-2021 11:22:23 UTC] PHP Notice: Array to string conversion in .../wp-content/plugins/shortpixel-adaptive-images/includes/controllers/short-pixel-ai.class.php on line 1186
    [09-Feb-2021 11:22:23 UTC] PHP Warning: Invalid argument supplied for foreach() in .../wp-content/plugins/wp-rocket/inc/Engine/Optimization/DeferJS/DeferJS.php on line 140

Expected behavior There should be no errors.

Additional context Code in ShortPixel AI:

public function wp_rocket_no_defer_spai_settings($regex) {
return $regex . '|spai_settings';
}

Comment by @engahmeds3ed:

I think we need to guard it and make it backward compatible so we will detect if it's string we will change it to array by exploding using | needle

Slack convo: https://wp-media.slack.com/archives/C43T1AYMQ/p1612871496110000 Ticket: https://secure.helpscout.net/conversation/1412614288/235953/

Related issue with Smart Slider 3: Slack: https://wp-media.slack.com/archives/C60QX4FC1/p1612456408103600 Ticket: https://secure.helpscout.net/conversation/1414913336/236541/

Backlog Grooming (for WP Media dev team use only)

engahmeds3ed commented 3 years ago

Grooming