MyBB Community Forums

Full Version: How to hook only on some pages?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,
I need to run a pre_output_page hook only when on index page. How can I do it (if possible at all)?
Is there any $var that stores the current page viewed?
I need this because in this hook,after replacing some tags, I run an heavy query to display an output from db after the forum list, so I don't want to waste that time on pages other than index where the hook output is shown.
Running with debug active I noticed that pre_output_page hooks are ran on every page (thread list/post list), no matter if they are useful for something that page displays or not.
There is the this_script variable, but depending on the sizeof the query output and the required freshness, why not cache the result?
(2015-11-22, 10:14 AM)Leefish Wrote: [ -> ]There is the this_script variable, but depending on the sizeof the query output and the required freshness, why not cache the result?

Yes, I'll cache later on for my code. But I see this is a common problem among plugins in your repo, so I tought it was good to know for editing some of them too.
I saw some THIS_SCRIPT defines in plugin, is that you are referring to? Or $this_script var? Can I use that at any point in my plugin?
Try this.... Wink
if(my_strpos($_SERVER['PHP_SELF'], 'index.php'))
{
// plugin actions
}
(2015-11-22, 12:46 PM)SvePu Wrote: [ -> ]Try this.... Wink
if(my_strpos($_SERVER['PHP_SELF'], 'index.php'))
{
// plugin actions
}

Worked as expected Big Grin  Thank you.