[Defender] Auto-whitelist current administrator

0

I’m logged-in to a site as an administrator with Firefox. I open Chrome to test a new NoCaptcha plugin. As I’m moving between login and registration pages, Defender blocks my IP address.

OK, so it’s doing what it should for someone who isn’t recognized. But I’m already logged in as an administrator. So I want my current IP to be whitelisted.

1) I will ask for an enhancement to auto-whitelist an IP that is used as a valid login to an administrator role. Or perhaps, whitelist whatever IP visits the Defender settings page.

2) To reduce the load on WPMU DEV staff, can someone just tell me what I can hook or what function I can call to perform this operation on my own? I can check is_admin of course, and get my own IP address. The next step would be to call the function in Defender that does whitelisting. I can add this into my own plugin.

Thanks.

  • Tony G
    • Mr. LetsFixTheWorld

    Note that my IP was blocked while I was already logged-in. Perhaps Defender can be made a little smarter? Check to see if the user is currently logged in before displaying the message “The administrator has blocked your IP from accessing this website.”

    Is there a use-case where someone who is already logged in would need to be blocked out? I don’t think so but perhaps this could be another option.

    This is especially true if the user is logged-in with the manage_options capability.

  • Nastia
    • Ex Staff

    Hello Tony G

    Hope you’re doing well!

    Thank you for your suggestion. It makes sense to auto-whitelist logged in admin’s IP address. Hopefully, more members will request this feature and our developers will consider developing it.

    As for plugin’s hook, I’ve flagged this to our second level support developers so they could provide you some feedback. Please note, our developers’ response time is longer-than-normal compared to support staff response times.

    Kind regards,

    Nastia

  • Ivan Svyrskyi
    • Developer

    Hi Tony G and Nathan !

    Until you wait when other members will request this feature and our developers will consider developing it – you could try adding the following snippet in a MU plugin ( more info about MU plugins is here )

    <?php
    function wpmu_defender_add_admin_to_whitelist( $user_login, $user ) {
    if ( !empty( $user->ID ) && user_can( $user->ID, 'manage_options' ) && class_exists( 'WP_Defender' ) ) {
    $ip = WP_DefenderBehaviorUtils::instance()->getUserIp();
    WP_DefenderModuleIP_LockoutModelSettings::instance()->addIpToList( $ip, 'whitelist' );
    }
    }
    add_action( 'wp_login', 'wpmu_defender_add_admin_to_whitelist', 10, 2 );

    Best,

    Ivan.