Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a blog network (Multisite), with domain mapping plugin installed, and some of my sites are under development, so I want to lock them from not registered users.

I tested a few plugins designed for this purpose (Private Only, Private WP suite, Private WP, Members Only, Registered Users Only, Absolute Privacy and Wp-Private) and all failed.

I accessed site, saw login form, filled it in, marked "Remember Me", logged in and I was redirected to Dashboard (user section) not to site itself. When I re-entered site URL (domain) I again saw login page, though I marked "Remember Me". There is not way I can access site itself.

I even wrote my own, as simple as possible, plugin for this:

function show_guest_notice()
{
    if(!is_user_logged_in())
    {
        echo('No way, man!');
        die();
    }
}

add_action('get_header', 'show_guest_notice');

and it also failed.

It seems that either is_user_logged_in() or string user cookie fails on Multisite with Domain Mapping plugin.

I saw this post and answer by amontobin ("(...) was a domain mapping cookie issue. Now working fine"), but it only assured me that using Multisite with Domain Mapping is source of these problems, but it brings no solution to it.

So, can anyone help me or got any idea how to make site bloking (is_user_logged_in()) work on Multisite network with Domain Mapping plugin enabled?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I don’t have the domain mapping on a test installation at hand currently, but what should work is:

add_action( 'template_redirect', 'auth_redirect' );

As a plugin here: T5 Force Log In.
auth_redirect() is WordPress’ native handler for authentication, if it doesn’t work, something is broken in core code.

share|improve this answer
    
This also doesen't work. The only difference is, that after login, I'm not redirected to Dashboard, but back to login page (but without any error, which means -- as I assume -- that login was successful, only login cookie was not stored correctly). From the support forum thread I assume, that the problem is not in core code, but rather Domain Mapping plugin is interferencing somehow. –  trejder Nov 9 '12 at 22:11
    
Maybe the problem is that login cookie is set for incorrect domain. If you have Domain Mapping plugin enabled, it will always redirect browser to declared domain. So, for example, I have one.page.com site, mapped to one.com domain. Whenever I enter one.page.com URL, I'm redirected to one.com domain, if Domain Mapping plugin is enabled. Wordpress problably writes down login cookie for one.page.com, which is not available for one.com and everything fails. Dashboard is always accessible under one.page.com (plugin is enabled only for frontend), so this works fine. –  trejder Nov 9 '12 at 22:15
1  
Issue reported in Domain Mapping plugin support forum. –  trejder Nov 9 '12 at 22:27

You can use the plugin Authenticator, it works with Multisite too.
If you publish different parts of content via oauth or a kex, the use the development version.

share|improve this answer
    
Have you read my comments above, to toscho's answer? The problem is not in Multisite, but with Domain Mapping plugin enabled. I'm pretty sure, even without testing, that even Authenticator will fail in this situation. Simply because Wordpress itself fails, as it records login cookie for a different domain then is actually used (after redirection done by Domain Mapping). –  trejder Nov 10 '12 at 14:55
    
Yes, I Have read this; but I use the plugin in a MU with Domain-Mapping. –  bueltge Nov 13 '12 at 12:01
    
Problem has been solved. All I needed to do, was to switch main domain of each site from default subdomain address to top-level domain that is mapped to that site, through Domain Mapping. I think that now all force-login plugins should work, but I decided to use underConstruction plugin, as it best fit my needs. Thanks. –  trejder Nov 13 '12 at 22:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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