0

I want to disable temporarily site visiting and user logins to a multisite blog for the site maintenance time, excepting for super-admins and for a specific user. I found this function (thanks @joshc) and it works very well, but I don't know how to add the specific username to it so it can visit the site too. Please help!

This is what I tried, but without success, the user test_user is not allowed to login:

function site_maintenance() {
    global $user_login;
    get_currentuserinfo();
    if ( !is_super_admin() || $user_login != 'test_user' ) {
        $logout_url = wp_login_url().'?mode=maintainance';
        wp_logout();
        wp_redirect( $logout_url, 302 );
        die();
    }     
}
add_action('get_header', 'site_maintenance');
1

Your if case matches any user who is not both a super admin and test_user.

For example, given a user test_user who is not superadmin, the result would be

if (true || false) redirect

Since one condition is true, the redirect would be triggered. Using the && operator, you'd get

if (true && false) redirect.

Since both are not true, it doesn't trigger the redirect.

2
  • But && will mean that test_user must be a super admin, or not? Anyway, I will try what you suggest, thank you! – Iurie Malai Nov 7 '14 at 17:45
  • Thank you, Jeremiah! With your help my function now works as expected! – Iurie Malai Nov 8 '14 at 7:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.