I want to know if there is code to hide a button when logged in.
I can hide a module/menu item by using the built in ACL features, but how can I do it from a code perspective.
A simple way is to check if the user has an id - if so it means the user is logged in. If id = 0 then it's a guest user and you can show the button as below:
$user = JFactory::getUser();
if($user->id == 0)
{
// Code to run for non-logged in users.
}
You can find some examples on how to accomplish various conditional tasks using the user info in these JSE Q/A: