Register Members List Search Today's Posts Mark Forums Read

Reply
 
Article Options
[How to] Add new/custom hook locations
Brad
Join Date: Nov 2001
Posts: 4,765

Washington
by Brad Brad is offline 09 Jun 2005

This guide will teach you how to add your own hook locations to your scripts/default vBulletin source code. Note that I assume that you are working within the vBulletin.php files or you have included vBulletin's global.php.

Adding custom hook locations -

Method one:

See paul's thread here for the best method, if you are going to release your modification to the public this is the way you should go:

http://www.vbulletin.org/forum/showthread.php?t=83390

Method two:

All hooks listed in this drop down live in the .xml file located at /vbroot/includes/xml/hooks_vbulletin.xml

Find this bit of code at the very top of the file:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


Looks simple eh? Heres what these tags do

<hooks> - anything between this tag and </hooks> will be included in the drop down

<hooktype type="name"> - The name of your hook group, you should group all common hooks under a group so you can find them quickly. Make sure you don't use a name already used by a default hooktype.

<hook> - The name of your hook, this must be the same as the hook's name in the php code

Here is an example of my .xml file, I added three custom hooks under a new hooktype:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

The php code:

Adding a hook location to the php code is easy, just make sure you use the correct hook name! Use this bit of php anywhere after your call to global.php to call your custom hook. Also note that you must use the $hook var!


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Here is an example of my custom hooks working in vBulletin's index.php file:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

As you can see I added them right under a current hook, which mostly defeats the purpose of making custom hooks. But for this post they serve their purpose

Now all you need to do is browse to your admincp's add new plug-in page and test your new hook location! I use this just to make sure it is working correctly:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If that outputs its text above the vBulletin header then you are good to go!.

Last edited by Brad; 23 Jan 2006 at 01:37..
Views: 14881
Reply With Quote
Comments
  #2  
Old 09 Jun 2005, 18:16
Floris Floris is offline
 
Join Date: Jan 2002
Great job, nice of you to share
__________________
My community; http://wetalknation.net

Last edited by Wayne Luke; 09 Jun 2005 at 20:27. Reason: Do we really need to quote the entire first post?
Reply With Quote
  #3  
Old 09 Jun 2005, 19:51
Logikos Logikos is offline
 
Join Date: Jan 2003
Very handy information
__________________
Full Time PHP Developer
Please feel free to contact me if you have any paid work to be done.
Reply With Quote
  #4  
Old 10 Jun 2005, 00:29
Creative Suite's Avatar
Creative Suite Creative Suite is offline
 
Join Date: May 2004
it's ok with me , thank you
__________________
Easy come .. Easy go
:sleep:

Last edited by Creative Suite; 10 Jun 2005 at 00:42.
Reply With Quote
  #5  
Old 10 Jun 2005, 03:43
rjordan's Avatar
rjordan rjordan is offline
 
Join Date: Sep 2004
If I might offer a suggestion... if were to add custom hooks in my code and upgrade my forums later, I would want to be able to find my hooks I entered easily so I can re-enter them if needed.

My suggestion:

Instead of doing this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I would do this instead:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Of course, there is absolutely nothing wrong the other way, but this way I can search for $customhook and know exactly what was added instead of searching through all of the $hook lines.

Only a thought I would share. Noone has to use it! :nervous:
Reply With Quote
  #6  
Old 21 Jun 2005, 12:16
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Real name: Lucius Hunk
Ok I think I forgot it but what are hooks used for ? (in the programming term, not end-users)

something like this line:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

what does it mean ?
Reply With Quote
  #7  
Old 21 Jun 2005, 12:23
Brad Brad is offline
 
Join Date: Nov 2001
Hooks are used to execute raw php code in the files.

Basicly that bit of code does this:

Checks if hooks are on in vboptions, checks if any hooks exist for that hook location.
If any hooks are found and enabled your custom php code is set to the $hook var
If there is php code set to $hook it is sent to eval for the php code to be executed, if not nothing is done and php moves on to the rest of the code in the file.
Reply With Quote
  #8  
Old 21 Jun 2005, 15:02
deathemperor's Avatar
deathemperor deathemperor is offline
 
Join Date: Jul 2003
Real name: Lucius Hunk
many thanks, I understand it now and is writing my hack.
Reply With Quote
  #9  
Old 21 Jun 2005, 17:51
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Real name: Paul M
If you are adding custom hooks, you might want to read this as well.


http://www.vbulletin.org/forum/showthread.php?t=83390
__________________
Former vBulletin.org Staff Member


Cable Forum
Please do not PM me about custom work - I no longer undertake any.
Note: I will not answer support questions via e-mail or PM - please use the relevant thread or forum.
Reply With Quote
  #10  
Old 07 Jul 2005, 17:26
Highlander65 Highlander65 is offline
 
Join Date: Mar 2005
Originally Posted by rjordan
If I might offer a suggestion... if were to add custom hooks in my code and upgrade my forums later, I would want to be able to find my hooks I entered easily so I can re-enter them if needed.
You could also just use "My_" (or any tag) in front of all your custom hook names. Then just search for your tag.
Reply With Quote
  #11  
Old 07 Jul 2005, 22:28
rjordan's Avatar
rjordan rjordan is offline
 
Join Date: Sep 2004
Tomato (A), tomato (o). Same idea.

It would be nice to have something that could be considered "unofficially standard" so if anyone created an update script that searched for custom hooks, a universal pattern could be looked for. Granted that this would be completely up to the forum admin. Thus, the suggested $customhook rather than $hook for the variable name.
Reply With Quote
  #12  
Old 08 Jan 2007, 18:57
punchbowl punchbowl is offline
 
Join Date: Nov 2006
fantastic article - cheers
Reply With Quote
  #13  
Old 27 Feb 2007, 16:34
aim aim is offline
 
Join Date: Jun 2006
Originally Posted by Brad View Post
...
The php code:

Adding a hook location to the php code is easy, just make sure you use the correct hook name! Use this bit of php anywhere after your call to global.php to call your custom hook. Also note that you must use the $hook var!


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

...
I already implemented hooks as advised in this thread and they also work.

But today I noticed Warnings in the Webserver-Logfile concerning the Lines the Hooks where called:

PHP Warning: Call-time pass-by-reference has been deprecated - argument
passed by value; If you would like to pass it by reference, modify the
declaration of [runtime function name](). If you would like to enable
call-time pass-by-reference, you can set allow_call_time_pass_reference
to true in your INI file. However, future versions may not support this
any longer. in .../includes/init.php(403) :
eval()'d code on line 52, ....

Does this mean that future PHP-versions won't support the vBulletin-Hook-System?
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Article Options

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 03:58.

Layout Options | Width: Wide Color: