Skip to:
Content
Pages
Categories
Search
Top
Bottom

Check if user is logged in in 1.0.1

  • @4crickj

    Member

    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() and is_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.php theme 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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @_ck_

    Participant

    bb_is_user_logged_in() is right there, still in 1.0.1

    The 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.");
    }
    }

    @4crickj

    Member

    Brilliant!

    Works perfectly when $bb->uri is replaced with bb_get_option(‘uri’) .

    Many thanks for your fast reply.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar