get php function information to use in jquery

I’m using a WordPress plugin to create users for my site and I need to check if a user if logged in and then execute something in a jquery function. The plugin states they have public functions set up for such things. I’m not sure if I have this set up correctly, whether the user is logged in or out it is coming up “loggedout”. The public function is in my functions.php file of my theme and is :

function loggedin() {
    $FEUP = new FEUP_User;
    if ($FEUP->Is_Logged_In()) {
        echo "loggedin";
    } else {
        echo "loggedout";
    }
}

my jquery function is :

var user = "<?php loggedin(); ?>";
if(user == "loggedin") {
    console.log("user is logged in");
}else {
    console.log("user is logged out");
}

Read more here: get php function information to use in jquery

Leave a Reply

Your email address will not be published. Required fields are marked *