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.

Using a plugin,I am looking a way to Show/Hide all Content after Headers are sent. If I have an authenticated user then show the content other wise redirect the user to authenticate first.

I want to use Facebook PHP SDK to authenticate the user. My questions are

  1. Using which Hook or Action I can put a check whether User is authenticated or Not.
  2. If user is authenticated, continue with WordPress Loop to show Content else Redirect to Facebook for Authentication.

A rough pseudo code is

After header if Facebook user Continue WordPress Loop else Redirect

share|improve this question
    
Do you want to check this before the page even loads up? Why do you want to redirect after headers are sent? –  Rutwick Gangurde Nov 21 '11 at 3:18
    
Headers are sent by Facebook SDK and also a check before <Head> blocks Facebook to crawl Open Graph tags. In short, it can be checked right after <Body> at sometime before content Loads –  Umair Bussi Nov 21 '11 at 14:18
    
Aha... I get it. Then try using loop_start action. It runs before the loop begins. –  Rutwick Gangurde Nov 21 '11 at 14:24
    
Can you kindly elaborate the logic more? Suppose that i do this what would be the code to stop or continue the loop and also where would be the else check add_action('loop_start','myfunction') then function myfunction() {if ($user) //How do I Continue Loop else //How Do I Stop Loop } –  Umair Bussi Nov 21 '11 at 14:38
    
Its an action, so you won't need to return anything. Just check if you're logged in, if not, then redirect to login / warning page, else continue. –  Rutwick Gangurde Nov 21 '11 at 15:15

1 Answer 1

You can use this library located at Github.

    <?php

  require './facebook.php';

   $facebook = new Facebook(array(
  'appId'  => 'YOUR APP ID',
  'secret' => 'YOUR API SECRET',
'cookie' => true, // enable optional cookie support
));


 if ($facebook->getSession()) {
   PLACE YOUR WP LOOP HERE
} else {
   echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
   ADD YOUR APP's 'Connect' button here.
}
    ?>

Include facebook.php from the library located at Github (2nd line).

share|improve this answer

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.