Fail2ban Plugin Causing PHP Warnings in Logs

Issue - PHP errors in the debug logs after enabling fail2ban in WordPress. The error is present on all PHP versions above 8.0.

wp-content/plugins/wp-fail2ban/admin/admin.php:304
org\l\c\w\w\admin_menu_fix()
wp-includes/class-wp-hook.php:324
do_action('admin_menu')
wp-admin/includes/menu.php:161

Temporary fix by Adding isset() checks for every array level before accessing the $submenu elements to avoid “undefined array key” warnings. That is to replace: -

    if (isset($submenu['wp-fail2ban-menu']) && 'WP fail2ban' == @$submenu['wp-fail2ban-menu'][0][0]) {
        $submenu['wp-fail2ban-menu'][0][0] = __('Welcome', 'wp-fail2ban');
    }

using the below one in wp-content/plugins/wp-fail2ban/admin/admin.php:304

    // Check if the array key 'wp-fail2ban-menu' exists and has a valid structure
    if (
        isset($submenu['wp-fail2ban-menu']) && 
        isset($submenu['wp-fail2ban-menu'][0]) && 
        isset($submenu['wp-fail2ban-menu'][0][0]) &&
        'WP fail2ban' == $submenu['wp-fail2ban-menu'][0][0]
    ) {
        $submenu['wp-fail2ban-menu'][0][0] = __('Welcome', 'wp-fail2ban');
    }

I’d love to know more about what else you’ve got installed as I never managed to reproduce the problem the last time it came up (several years ago now).

Can you try this?

if ('WP fail2ban' == ($submenu['wp-fail2ban-menu'][0][0] ?? '')) {
    $submenu['wp-fail2ban-menu'][0][0] = __('Welcome', 'wp-fail2ban');
}

Hi,

This issue occurs on a default WordPress installation with no other active plugins. During testing, I noticed that the WP Fail2Ban plugin generates PHP errors specifically when interacting with the “Opt-In” option. If I skip the opt-in process, the plugin functions without any issues, but selecting “Opt-In” repeatedly triggers warnings. This indicates that there might be underlying problems with how the plugin handles the opt-in process.

Here are the observations:

  1. The “Opt-In” prompt appears right after installing the WP Fail2Ban plugin.
  2. Clicking “Opt-In” generates the following PHP errors:

Error Type: Undefined array key and access of a null value.
Location: admin.php file around line 304 in the plugin.

Screenshot is attached for reference.

  1. If I click “Skip,” no further errors occur.
  2. Once “Allow and Continue” is selected, the opt-in prompt disappears, and the PHP errors stop appearing.

Could you please advise if there is a known fix or if an update is planned to address this issue? Thank you!

Thanks for the detailed explanation!

I’ll roll the fix into 5.4 (it’ll be the same as what I posted before).

I know the warning is annoying, but it’s not harmful - everything will work as it should.