crowdsecurity / cs-wordpress-bouncer

CrowdSec is an open-source cyber security tool. This plugin blocks detected attackers or display them a captcha to check they are not bots.
https://wordpress.org/plugins/crowdsec/
MIT License
34 stars 6 forks source link

Unable to activate plugin (Conflicting class name) #148

Closed kimdre closed 5 months ago

kimdre commented 5 months ago

I cannot acivate the plugin in one of my Wordpress docker containers running with the bitnami/wordpress image. When I try to activate it, I get an "fatal error" message and an error in the logs:

[24-Mar-2024 16:17:58 UTC] PHP Fatal error:  Cannot declare class AdminNotice, because the name is already in use in /bitnami/wordpress/wp-content/plugins/crowdsec/inc/admin/notice.php on line 3
<ip redacted> - - [24/Mar/2024:17:17:57 +0100] "GET /wp-admin/plugins.php?action=activate&plugin=crowdsec%2Fcrowdsec.php&plugin_status=all&paged=1&s&_wpnonce=6632a1c26b HTTP/1.1" 302 -
<ip redacted> - - [24/Mar/2024:17:17:59 +0100] "GET /wp-admin/plugins.php?error=true&plugin=crowdsec%2Fcrowdsec.php&_error_nonce=c4019a46df HTTP/1.1" 200 33475

I was able to activate the plugin on other wordpress sites of mine, which also use the same docker image and the same wordpress version, so maybe this is caused by some other Plugin?
I checked if the class name is already used by any other plugin, but this does not seem the case. At least I was not able to grep for that name in any other plugin directory.

The wordpress version is 6.4.3

Edit: I just tried to activate the plugin while the others where deactivated. This however did not work. Maybe the error is then not caused by any of my plugins?

Edit 2: I was able to find a class with the same name in my theme's directory.

I have no name!@6d6b073227a8:/bitnami/wordpress/wp-content/themes$ grep -R AdminNotice *
newsphere/admin-dashboard/rest-api/class-admin-notice.php:if(!class_exists('AdminNotice')){ 
newsphere/admin-dashboard/rest-api/class-admin-notice.php:class AdminNotice {
newsphere/admin-dashboard/rest-api/class-admin-notice.php:$data = new AdminNotice();
julienloizelet commented 5 months ago

Hi @kimdre,

thanks for your message.

As you've found, it seems that the newsphere theme conflicts with the CrowdSec Bouncer plugin because they both have an "AdminNotice" class.

I guess we could rename our class to something like "CrowdSecAdminNotice" to avoid such conflict.

Will try to do it in a next release.

Thanks again.

julienloizelet commented 5 months ago

Hi @kimdre,

I've just released a new 2.6.2 version of the CrowdSec bouncer plugin.

With this version, there should be no more conflicts.

Please let me know if it works for you.

Thanks

kimdre commented 5 months ago

Thanks, works now! 👍