1

I have this snippet of code:

add_action('wp', 'check_for_special_user');
function check_for_special_user()
{
    // Short circuit if wp-admin
    if( is_admin() ) {
        return;
    }

    auto_login_special_user();
}

The concept is simple: I need to check the IP of the visitor, and if it's a certain IP, automatically log them into a special account. However, I never want this to trigger if the user is in the admin panel, so that administrators can browse the wp-admin from a computer on that special IP with their admin account.

This works fine, except for one scenario. When I'm in the wp-admin, and I update a page, my auto_login_special_user() function triggers and I automatically get logged into the special account, and therefore receive this error:

error

(Sorry for the French, it says "Are you sure you want to do that?")

So, at some point between updating the page, and when the content is saved in the db, the is_admin() fails. For the record, the updated content doesn't get saved.

So my question is, how do I prevent that function from ever firing in the wp-admin? Thanks

  • I try your code but I don't have the problem when I update a page. can you try to desactivate all other plugins to see if you have the same problem ? – mmm Oct 18 '17 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.