Highfivery / zero-spam-for-wordpress

The WordPress Zero Spam plugin makes blocking spam a cinch without all the bloated options. Just install, activate, and say goodbye to spam.
https://wordpress.org/plugins/zero-spam/
72 stars 32 forks source link

Conflict between Zero Spam and other plugins using GuzzleHttp #273

Closed EusebiuOprinoiu closed 3 years ago

EusebiuOprinoiu commented 3 years ago

Hello, Ben! The latest version of WordPress Zero Spam introduced a conflict between WordPress Zero Spam and other plugins that use GuzzleHttp.

PHP Fatal error: Uncaught Error: Call to undefined method GuzzleHttp\Utils::chooseHandler() in /wp-content/plugins/zero-spam/vendor/guzzlehttp/guzzle/src/functions.php:61

Pixel Caffeine had this exact problem when they updated the library a while back. They fixed the problem by scoping the library within a different namespace. WP Offload Media from Delicious Brains also uses GuzzleHttp and they also namespace the library bundled within their plugin. If it helps, they briefly mention how they do it in one of their blog posts: https://deliciousbrains.com/wordpress-http-api-requests

In my case, the conflict appears between WordPress Zero Spam and BackWPup when using Amazon S3 as backup destination. The fatal error appears both on the settings page for the Amazon S3 connection and while running a backup, which makes all backups fail.

bmarshall511 commented 3 years ago

@EusebiuOprinoiu Thanks for letting me know, strange one. Zero Spam doesn't use that library directly, instead is a dependency for the IPinfo library. As such, you'll need to contact IPinfo about a resolution. Once they get their library updated, I can update it on ZS which should hopefully fix the issue.

Understand that's a major pain with it being a fatal error. I will look into only including that library if IPinfo is enabled. That way you can disable it and avoid that error until there's a resolution from their side. I try to get that up in the next release.

bmarshall511 commented 3 years ago

@EusebiuOprinoiu Pushed an update to the master branch to only load the library if ipinfo is enabled. Can you download it (https://github.com/bmarshall511/wordpress-zero-spam/archive/refs/heads/master.zip) to see if it fixes your issue?

EusebiuOprinoiu commented 3 years ago

Since I am not using IPinfo, the problem goes away, but your solution is not really a fix. It's just a way to limit the number of websites impacted by this issue.

There is nothing wrong with the IPinfo library or the fact that they use GuzzleHttp. The underlying problem is that WordPress doesn’t have a way of dealing with third-party code in plugins or themes and, by default, does not play well with Composer. WordPress has a very specific order for loading plugins, and you never know if your plugin loads after another plugin that uses a different, incompatible version of the same dependency.

Delicious Brains uses this Impostor Plugin to namespace all their Composer dependencies. I haven't personally used this before, but as far as I can tell, all you have to do is add it as an extra dependency to Composer and define a unique namespace for your plugin in composer.json.

bmarshall511 commented 3 years ago

@EusebiuOprinoiu Right, not a fix, temporary solution as I mentioned. Wanted to get something up quick for you to get rid of the fatal error.

Again, zero spam doesn't load any libraries except for IPinfo. The fact you're getting that error is due to how IPinfo loads its dependencies, not zero spam since it has no required dependencies.

I'll look into that Impostor Plugin for loading the IPinfo library, hopefully, that'll resolve the core issue.

EusebiuOprinoiu commented 3 years ago

Thank you. I appreciate it! This temporary solution is good enough for me. All I wanted to say is that a proper fix is needed in the long run because it will cause issues with almost every plugin that uses this library for remote connections. And there are a lot of them. (some of them essential, like backup or SMTP plugins) I have seen this issue 6 or 7 times this year alone and every time it was fixed by namespacing the library.