How to hook only on some pages?
#1
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.
Reply
#2
There is the this_script variable, but depending on the sizeof the query output and the required freshness, why not cache the result?
Random Fish and Sims Maniac
MY PLUGINS
Help MyBBSupport help you - remember to mark your threads as solved


Reply
#3
(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?
Reply
#4
Try this.... Wink
if(my_strpos($_SERVER['PHP_SELF'], 'index.php'))
{
// plugin actions
}
Reply
#5
(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.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)