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'm using this code below as a plugin. It seems to work but sometimes it seems to be stuck in a loop. When I have this plugin running my facebook social sharing doesn't grab the correct page and content for a share post. I turn off the plugin and facebook share works great. What am I doing wrong?

add_action ('template_redirect', 'protect_whole_site');

function protect_whole_site() {
if ( !is_user_logged_in() &&  !in_array( $GLOBALS['pagenow'], array( 'wp-    login.php', 'wp-register.php' ) ) ) {
        auth_redirect();
    exit;
    }
}

thanks!!

share|improve this question

1 Answer 1

Facebook grabs your site's content by making an http request just like any other visitor, you're forwarding any attempts to scrape your pages to the login page.

You could try checking for the Facebook user agent to let their crawlers through, but anyone could masquerade as the Facebook bot and browse your site without logging in by simply changing their browser's user agent.

share|improve this answer
    
thanks.. but my real issue here is to find the correct/best way to force users to login to the standard wordpress login or any url I may want. can anyone suggest a way or help me fix this endless loop which ultimately crashes. –  Thom Edward Mar 6 '13 at 2:18
    
You could try not using Facebook and other sharing code on pages that users have to log in to see. –  Otto Mar 6 '13 at 5:40
    
again, I would rather forget about facebook right now and fix this endless loop... any suggestions on this function? is there a better one that doesn't loop out? –  Thom Edward Mar 6 '13 at 8:18
    
@ThomEdward what endless loop problem? Describe the steps to reproduce this issue. Your code works fine for me on a vanilla WP install and twentytwelve theme. –  Milo Mar 6 '13 at 15:15

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.