Constants WPF2B_EVENT_COMMENT_CLOSED (etc) undefined

PHP-fpm: 7.4
Wordpress (multisite): 5.4.2
WP-Fail2ban: 4.3…0.6

Following the setup docs (it got a tad confusing for this newbie when defining what LOGGING I wanted to be enabled (reference: https://docs.wp-fail2ban.com/en/4.3/configuration/logging.html)) - when coming to the COMMENTS_EXTRA define() instructions, some constants appear to be undefined (though I may have set things up wrongly).

Let me explain:-

Defining a constant as “true” within wp-config.php makes sense:-

define(‘WP_FAIL2BAN_LOG_SPAM’, true);

… and this enables SPAM logging successfully.

Further in the page we’re advised to “You should consider enabling Comment: Spam and Attempted Comment: Closed post” … and following the docs on that constant (https://docs.wp-fail2ban.com/en/4.3/defines/constants/WP_FAIL2BAN_LOG_COMMENTS_EXTRA.html#wp-fail2ban-log-comments-extra) we’re advised to OR constants together as follows:-

define(‘WP_FAIL2BAN_LOG_COMMENTS_EXTRA’, WPF2B_EVENT_COMMENT_CLOSED | WPF2B_EVENT_COMMENT_DRAFT);

Presumable in the same wp-config.php file as the other logging-enabling constants.

PROBLEM: PHP (7.4) raises a warning that the “or”'d constants are not defined (so it goes ahead to assume they’re strings). Here’s the error log:-

Got error 'PHP message: PHP Warning: Use of undefined constant WPF2B_EVENT_COMMENT_CLOSED - assumed ‘WPF2B_EVENT_COMMENT_CLOSED’ (this will throw an Error in a future version of PHP) in /home/sites/wordpress-mu/web/wp-config.php on line 103

PHP message: PHP Warning: Use of undefined constant WPF2B_EVENT_COMMENT_DRAFT - assumed ‘WPF2B_EVENT_COMMENT_DRAFT’ (this will throw an Error in a future version of PHP) in /home/sites/wordpress-mu/web/wp-config.php on line 103’

COMMENTARY: My setup is using wp-fai2ban as an mu-plugin (via symbolic link). It looks like these constants don’t get defined before the setting is reached in wp-config.php (wp-fail2ban isn’t loaded yet?) So, these constants aren’t defined before the define() statment is reached in wp-config.php. Documentation assumes they are. So … my implementation error … or a bug in the documentation? :thinking:

I’d say it’s more of an “implementation mismatch” :wink:

The docs accurately reflect how it should work, but for $reasons the necessary changes to the code didn’t make it to release.

This is fixed in 4.3.0.7, but I’m holding the release for a few days as I suspect that everyone has a bit of update-fatigue right now (I’m trying to keep it to once a week max).

1 Like

Whoohoo! I’m not crazy !! :rofl:

Y’know, as an aficionado of Fail2ban for nearly a decade I’ve come to develop so many regex filters to protect my Wordpress installation that I almost made WordFence redundant :joy: (albeit their worldwide data source is really handy for attacks)…

… but I’ve been incredibly impressed with how you’ve developed & implemented WPF2B. Elegant and a valuable link between Wordpress & Fail2ban :+1:

Thanks for replying - I’ll keep my eyes open for 4.3.0.7 in time.

1 Like

I’m very happy you like it - no small amount of work has gone into it!

Thanks again - the reviews on WordPress.org always need a little more love if you’re so inclined :wink:

1 Like