Info
- 3 posts
- 2 voices
- Started 2 years ago by 4crickj
- Latest reply from 4crickj
- This topic is resolved
Check if user is logged in in 1.0.1
-
- Posted 2 years ago #
I want to check if the visitor is logged in, I can't find a function that works in version 1.0.1 (such as
bb_is_user_logged_in(),is_user_logged_in(),bb_is_logged_in()andis_logged_in()). All of those functions raise the "Call to undefined function" error.I am trying to make my forum private, redirecting all users that are not logged in to the login page. The following code is in my
functions.phptheme file:
if(!preg_match("/bb-login.php/", $_SERVER["SCRIPT_NAME"]) && !bb_is_user_logged_in()) {
header("Location: " . $bb->uri . "bb-login.php");
die("Authorisation required.");
}
Any help is appreciated.
-
- Posted 2 years ago #
bb_is_user_logged_in()is right there, still in 1.0.1The problem is you are checking too early, right when the plugin loads which is too soon.
A user is not determined as logged in until bb_init happens. So you have to make a mini-plugin
add_action('bb_init','check_login'); function check_login() { if(!preg_match("/bb-login.php/", $_SERVER["SCRIPT_NAME"]) && !bb_is_user_logged_in()) { header("Location: " . $bb->uri . "bb-login.php"); die("Authorisation required."); } } -
- Posted 2 years ago #
Brilliant!
Works perfectly when $bb->uri is replaced with bb_get_option('uri') .
Many thanks for your fast reply.
-
This topic is
closed