Simple typo ? Should be:
$username = $bp->loggedin_user->id;
https://codex.buddypress.org/developer-docs/the-bp-global/
Even better: bp_loggedin_user_id()
that was my typo in the post, i did have $bp in my code.
i just tried bp_loggedin_user_id()
and i got this.
Fatal error: Call to undefined function bp_loggedin_user_id()
can someone help me out?
i’m not sure what to do, do i need to include a php file? do i need to put my php file in a specific directory?
are you calling that from bp-custom.php ? or your theme ?
i created a buddypress page and that page embeds a php file to display, for testing purposes i just want that to display the users id. the file is called myphp.php and i have it in the buddypress directory.
im new to php so i’m not sure how to do this. i feel like im supposed to include one of buddypress’s php files in order to call the function.
so to answer your question, i guess neither?
well, In that case, some more questions will help.
1. how do you create a buddypress page? from wordpress admin? from theme, have you added a new component as I don’t see other way to add a page in buddypress
2. Is the page opened using wordpress/is coming inside wordpress (seems to me iT is not )
3. Or is the page independent of wordpress, you are loading that page(php) directly inside the browser ?
i am adding the page by going to the pages section in the dashboard and simply adding a new page. In the html for that page i embed a php file. That makes the php page independent of buddypress.
I guess a better way of looking at it would be, if i accessed an independant php page, how could i make it return the user id of buddypress.
No, you are doing it right then(assuming you are using some sort of PHp exec plugin for wordpress as wp will not allow including raw php). Doing independent page will need extra care to include wp-load.php and not a very good idea.
in the current case, just double check that you have enabled BuddyPress plugin. I don’t see any other reason of the error.