I guess you lock down your site from guests? Really I can not guess on your mods. In the gallery viewing permissions are set via category permissions via what usergroup a user is in.
without knowing more I really cant guess as all our variables are defined via various functions. That may work in our pp-inc.php file
There really is no support for code mods. I am just posting my thoughts based on what your doing.
remember you can do what I suggest in our code but you need to define that is_bot variable. That means maybe including that file in our code where your doing the code change.