The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
[How to] Write Plug-ins/Hooks
This is your basic guide to making plug-ins and hooks, as we are all coming over from the 'hack the files' mentality I am posting this thread more for people that are used to hacking the 3.0.x source code and looking to port modifications. Although a newbie should be able to come away with a good understanding of how to do this to . [high]Things to consider[/high] Ok before we get started here are a few things to keep in mind. First and foremost plug-ins are stored in the database, serlized, unserlized and evaled on page generation. If you code preforms badly with such a wrapper forget making a plug-in and just hack it, trust me you'll thank yourself for it when your forum gets large. Second thing, hooks will not get you into every corner of the code. Some things will always be done best with a hack. For example if you are looking to add something but need to query the db for some extra data and want to avoid and extra query (in other words you are going to modify an existing one with a join or such) forget it and hack it in, there are no hooks that let you modify existing queries. Last but not least hooks are not magic, don't add a million of them and expect your forum to run as fast as it did when you first installed it. Only plug-in/hack-in what you really need! Ok enough with the boring stuff, lets add our first plug-in! [high]Basics:[/high] First thing you need to do is make sure plug-ins are enabled, you can find this option in the admin cp by browsing to vBoptions -> Select Plugin/Hook System from menu -> Set Enable Plugin/Hook System to yes. Now head to the add plug-in page located at http://www.yoururl.com/forum/admincp/plugin.php?do=add Lets go over what all these options mean: Hook Location: This is where the php code will be executed at, hook locations at defined all across vBulletin. You can find them by opening and php file and searching for the var $hook. When you find a bit of php code like this you have found a hook: PHP Code:
Title: This is the title of your plug-in, use a good name because this is the only thing you have to identify the plug-in in the plug-in manager. Plugin PHP Code: Can you guess? This is where you put your custom php code, on page generation it is executed at the hook location in the .php files. Note that you do not need <?php ?> tags here, in other words: wrong: PHP Code:
PHP Code:
Edit - Thanks to Revan for this addition: Quote:
At first approach coding the plug-in like a hack. Open the php file you would normally edit and get your mind around the new code. Once you have a good understanding of the new code you should start looking for where you need to add your custom php. Once you find the right location in the code start looking for a nearby hook, if you don't see one you can work with you are out of luck! Edit- Thanks to KirbyDE for his addition: Quote:
|
#62
|
|||
|
|||
Fair enough, I don't see why that link I posted wouldn't work the same in a plugin. Just do the same but instead of writing the hook in the PHP file stick it in your plugin. No harm in trying if you haven't already done so
Did you get some kind of error or was it just not working? |
#63
|
|||
|
|||
I didn't try it yet, as I didn't need it at the time (I need it today).
I'll try soon though and post what happened. |
#64
|
|||
|
|||
Is this tutorial current as of vb 3.6.8?
I'm looking for a plugin tutorial and wondered if this is still relavent |
#65
|
|||
|
|||
The advice by KirbyDE at the end of the main entry was BY FAR the most useful part for me, but yes, I believe it is all still relevant.
|
#66
|
|||
|
|||
At the beginning, thank you for the good basic guide.
But I'm not completely understudying how I can associate my hook with two or more "hookname" at once? E.g. "newreply_post_start", "newthread_post_start". Quote:
Code:
<title>vB Category Icons</title> <hookname>newreply_post_start</hookname> <hookname>newthread_post_start</hookname> Is it the only way to make the fully copy of the code into a new hook and associate it with new hookname??? |
#67
|
|||
|
|||
This tutorial is old. You can add plugins through the AdminCP via the Plugin Manager.
I don't think it is possible to associate the same code to two hooks. Just copy the code over to a new plugin to create code for another hook. |
#68
|
|||
|
|||
Quote:
If no other, "normal" way, off cause i do that. But I hope that someone will prompt more correct way. |
#69
|
|||
|
|||
Hi, I just want to display a list of users who have posted on a thread at the top of the thread using the hook system. I'm brand new to VBulletin and was wondering if there is a good tutorial or documentation that would help. I've looked in the vb manual and it just has like 2 pages on writing plugins. Can anyone help?
|
#70
|
|||
|
|||
Quote:
Is there a way to add WHERE and ORDER statements to this query as well, using hooks? |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|