Hi, a method in the $AWD_facebook exists to force the login.
So you do not need to use the code you post.
Open the function.php file in your theme, and add thoses lines
function force_fb_login()
{
//access to the Facebook AWD object
global $AWD_facebook;
//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
$AWD_facebook->login_required();
}
add_action('init', 'force_fb_login');
Try it and tell me, i will update the plugin to work 100% with canvas
OMG..that what SOOO fast ! thanks…
will update you shortly and thanks again!!
If it works, you can use write it with less code…
global $AWD_facebook;
add_action('init', array($AWD_facebook, 'login_required');
In fact i am not sure this will work, because the redirect is set to the current url. but in an app canvas the current url is the app page, but for the plugin the current url is the WP url.
Try it, and tell me.
Nope.. sorry..pasted it on in the function.php file of the default template..(twentyeleven)…and it gave me a blank page..
I pasted it at the bottom as the last function.
any additional suggestions?
thx
Ok, i know why, when the file functions.php is read, the $AWD_facebook is not yet an object.
However i saw that in the code the redirect url of this function after the login will be your website url, not the fb app url.
So I wrote a little hack, in wait of a new version of the plugin.
function force_fb_login()
{
//access to the Facebook AWD object
global $AWD_facebook;
//define the app url and the redirect after login
$redirect_uri = $AWD_facebook->options['app_infos']['link'] . (get_option('permalink_structure') != '' ? '?' : '&') . 'redirect_to=' . $AWD_facebook->get_current_url();
$scope = $AWD_facebook->options["perms"];
$login_options = array(
'scope' => $scope,
'redirect_uri' => $redirect_uri
);
//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
if (!is_user_logged_in()) {
echo '<script>top.location.href="'.$AWD_facebook->fcbk->getLoginUrl($login_options).'";</script>';
exit();
}
}
add_action('wp_head', 'force_fb_login');
I tested it, and it works great in app canvas !
So this one !
function force_fb_login()
{
//access to the Facebook AWD object
global $AWD_facebook;
//define the app url and the redirect after login
$redirect_uri = 'https://apps.facebook.com/'.$AWD_facebook->options['app_infos']['namespace'].'/?redirect_to=' . $AWD_facebook->get_current_url();
$scope = $AWD_facebook->options["perms"];
$login_options = array(
'scope' => $scope,
'redirect_uri' => $redirect_uri
);
//Check if the user is logged in with Facebook, if no, redirect him to the Facebook login page.
if (!is_user_logged_in()) {
echo '<script>top.location.href="'.$AWD_facebook->fcbk->getLoginUrl($login_options).'";</script>';
exit();
}
}
add_action('wp_head', 'force_fb_login');
I owe you!!
Thanks for the code and the smile of success!!!
Highly appreciated!
Limor
and its say also this:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Die Anwendungseinstellungen lassen die angegebene URL nicht zu.
Sry for my bad english ^^
@gamerarenade That means the redirect url is not specified in the allowed url of facebook connect settings on facebook side.