PDA

View Full Version : Hook Question


paul41598
08 Aug 2006, 20:37
When you write an XML file and use plugin code at a certain hook location...does the code in your plugin execute before the hook location or after it?

Does your code run alongside the preexisting code in the PHP file, or does it replace it?

For example...if I had a xml file where I was trying to replace a certain chunk of code in the PHP file, how does that work?


Im trying to add a condition to this chunk of code without directly editing the file:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

Sean S
08 Aug 2006, 20:43
Personally I don't think that there is a way to edit a line or overwrite parts of it with hook/plugins.

Basically what you want to do is a file edit, and you should edit the php file. However, leave that as your last option and try to find another way of coding to get the same job done. If you can't find any, then you have to edit the php file.

Basically the hooks/plugins allow you to place a chunk of code within vbulletin's php files at certain predefined locations. You can't overwrite or replace lines with it, as far as I know.

May I ask what condition you are trying to add?

paul41598
08 Aug 2006, 20:45
Just trying to add a if condition around it

if (!$_REQUEST['refer'])
{
code block here
{

Sean S
08 Aug 2006, 20:51
So you want to add

Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

to this part

Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

?

If so, then I think you have to edit the php file.

Also have you tried putting the exact same code in the plugin and see if it works? So that you're plugin would look the exact same with that extra condition?



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------



not sure if that will work but give it a try.

paul41598
08 Aug 2006, 20:54
no like this



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

Sean S
08 Aug 2006, 20:56
oh ok, then I don't know. Again try putting that whole thing in the plugin and see if it will work. If the plugin/hook location is called before that chunk of code, I'm guessing that it will work. But I'm not sure, sorry.

paul41598
08 Aug 2006, 21:00
well ya, I tried placing the whole thing in the plugin at the right hook location, but no go. :( Oh well, file edit is the way to go

Nxs
08 Aug 2006, 21:08
yeah the code you hook replaces the hook - so to speak.

eg.

code line 1
code line 2
$hook = blahblah
code line 3
code line 4

Anything you put in the hook will execute between line 2 and line 3

paul41598
08 Aug 2006, 21:12
So Id almost have to make a new hook at the location I want it to execute. In which case, how do you release a new hook with ur hack?

Sean S
08 Aug 2006, 21:43
in that case it doesn't really matter whether you add another hook location in your file or just edit the php file and add in your code. Cause either way you are going to end up editting the php file.