How to put some custom PHP code at the top of every page in Vanilla
Hi there
I'm trying to execute some custom PHP code at the top of every page in Vanilla (using 2.1.3), said PHP code needing to be inserted before the html head.
I've found the file vanilla-core-2-1-3\vanilla\themes\bittersweet\views\default.master.tpl in the Bittersweet theme (which I am using) and added the PHP code as the first few lines inside that, but while this then code appears in all the pages when I do a view source, it doesn't actually appear to execute.
Is there a more fundamental/core design file I need to edit?
There used to be a file at applications\dashboard\'default.master.php' in version 2.0.18.8 which looks like it'd do the trick, but I can't find anything similiar to that in 2.1.3.
I've also tried using the 'Pockets' plugin to see if that will do the job, but its settings page blanks out on me, so no go-there . . . I presume the plugin is flaky with Vanilla 2.1.3.
Any ideas of how to slap some custom PHP code into every Vanilla page that will actually execute when run?
Ta
Comments
Welcome to the community!
The following code, placed in
/plugins/ExecuteBeforeRender/class.executebeforerender.plugin.php
should do the trick:That said, there is possibly a better, more specific way to do this if you mind sharing why you want to run PHP on every page.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Don't edit core files. You can put a bootstrap.before.php in you /conf/ directory, which will be excecuted on every pageload before vanilla bootstraps itself.
We could probably help you better, if you describe what you are trying to do, maybe a simple custom plugin which handles Base_Render_Before would also be sufficient.
Edit: @hgtonight beat me again
As for the pockets plugin, try the one in the github repository, which is more up to date:
https://github.com/vanilla/addons/tree/master/plugins/Pockets
My themes: pure | minusbaseline - My plugins: CSSedit | HTMLedit | InfiniteScroll | BirthdayModule | [all] - PM me about customizations
VanillaSkins.com - Plugins, Themes and Graphics for Vanillaforums OS
A third possibility: Smarty
http://vanillaforums.org/discussion/comment/214576#Comment_214576
A fourth possibility
add method to themehooks file
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Thanks everyone for you suggestions - I'll give them a try and see if they work, starting with hgtonight's. I'm trying to call a password script so I can lock sight of the forum away from everyone except the forum's registered users.
There are some settings in the dashboard that suggested Vanilla could do this by itself, but when I tried them, I can still view the forum posts without first logging in.
You're right, that's a standard feature and you will not need to code anything for that. Just go to /dashboard/role and edit the Guests role. Uncheck the "View" permission by "Default Category Permissions" and eventually the "View" permission for categories with custom permissions. Don't forget to hit the Save button and that's it!
If you are doing it this way you are probably not doing it right. passward authentication should be one time. Session authentication is different. You should never carry passwords around willy nilly. You make yourself vulnerable.
Like R_J said in you case you need to look at roles and permissions.
grep is your friend.
I tried R_J's route again, "Uncheck the "View" permission by "Default Category Permissions" and eventually the "View" permission for categories with custom permissions" and it worked this time, so job done.
Thanks for all your help.