0

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

6
  • Do you want to check this before the page even loads up? Why do you want to redirect after headers are sent? 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 Nov 21 '11 at 14:18
  • Aha... I get it. Then try using loop_start action. It runs before the loop begins. 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 } 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. Nov 21 '11 at 15:15
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).

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.