bbPress Session Variable Names
bbPress uses encrypted cookies, you’ll need to give us a little more information on what you are trying to do if we are to help you.
Hmm… I’m just trying to verify login on a page on the same site that is not part of the bbPress install. I’d like to be able to use the bbPress user system for the entire site if that is possible.
If sessions are the way to go, perhaps I could just include a couple of the function files. Which ones would be necessary to include to enable the is_user_logged_in() function?
Just to clarify, my site is at mysite.com. I’ve got bbPress installed at mysite.com/forums. I’d like to be able to enforce login using the bbPress user system at mysite.com/blah.php, but blah.php isn’t part of the bbPress install so the bbPress functions aren’t available to it. How do I go about enforcing login on a non-bbPress page?
Oh, and by the way, is there a way to return the current user’s username and ID if one is logged in?
Without going through the bbpress functions or mimicing the login authentication system (look in pluggable.php) you could never tell if a user is actually logged in, or being spoofed.
However the bbpress/wp cookie will persist and if the cookie path is set to the website root (instead of locked to “/forums/” – you’d have to change the default cookiepath) you could read the cookie and see if the visitor has a bbpress username. But if several people used the same computer there possibly could be several cookies.
In theory you could force sessions to always be on via a plugin for bbpress and watch it that way too. But note that sessions slow down server performance if it’s an active site.
Best bet is to change the cookiepath and decode the cookie with a smaller subset of code.
It sounds like just including the bbPress function files and using those functions would be the easiest. I couldn’t figure out which files needed to be included for the login functions to work though.
I tried doing
if (bb_is_user_logged_in()), which required /bb-includes/pluggable.php and /bb-includes/functions.php, but after I included both those files I was left with the following error:
Fatal error: Call to a member function get_row() on a non-object in /bb-includes/functions.php on line 1228
Am I missing some other file, or is it just not possible to use this function outside of the actual bbPress build?
By the way, assuming I can get these functions to run, what would be the function for getting the current users’s id?
I got lost somewhere in bb_get_current_user() and bb_get_user() without really being able to figure out what returns what. If I can get them running though, then I can test them, so I should be able to figure it out…
Try requiring bb-load.php and going from there.
Thank you rmccue! bb-load.php was the only file required to make those functions work. I guess that was the source of the chain of includes. Thanks a bunch
OK, I take that back. Requiring bb-load.php definitely fixed all the errors, but the functions still aren’t working. They don’t throw an error, but they don’t return anything either and so are pretty much worthless.
Is it perhaps because the files I am trying to use them in are in the parent directory above the bbPress installation?
There must be some way to get access to the bbPress login info directly through PHP…
bb-load essentially loads the entire bbpress framework
It just doesn’t generate any template output
It’s how RSS feeds, etc. are done
You can indeed evaluate the user login via loading the entire framework. But you can also write a very small subset of code to check the cookie and then read the database directly too.
However note that if your bbpress cookies are locked to a path (ie. /forums/) as they are by default, they will not be valid outside of the path and no user will be detected. So you have to change the cookiepath in config.php
Otherwise neither method will work.
Sam, I noticed that may have changed in/after 0.8.3.1
After some tinkering I also had to add:
$bb->sitecookiepath = '/';
(there is also a related minor issue in that I can’t seem to affect the cookie domain to be undotted in the newest builds)
- You must be logged in to reply to this topic.