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:
|
#22
|
|||
|
|||
A Plug-In is the code that uses a Hook to attach itself to exisitng code.
|
#23
|
||||
|
||||
Quote:
|
#24
|
||||
|
||||
Thanks Brad
|
#25
|
||||
|
||||
When adding new plugin, there's a input field name 'Developer Key' . Do you know what it does, Brad ? the strange thing is that I installed 2 vb3.5 board, one has it but the another doesn't
Edit: it shows when you enabled debug mode |
#26
|
||||
|
||||
Quote:
I thought it was going to be more of a standardized method of calling certain functions. Like if you want to start a new thread each time someone registers, instead of copying all the code around creating a new thread you just call build_new_post() (which surprisingly wasn't enough in vb 3.07). Or for a custom PM every time someone reaches 100 posts you call build_new_pm(). It sounds like this is very different than I was expecting. |
#27
|
|||
|
|||
You can see a Plugin as an externally definable include.
What you are talking about has nothing to fo with Plugins, but with standard functions offered, and maybe with approaching this as OOP classes. |
#28
|
||||
|
||||
Quote:
To tell the truth, I'm pretty disappointed by this. It sounds like adding a ton of complexity to something as simple as inserting a bit of code in a file. This might actually make upgrades worse. Includes need to happen at the right place. I'd rather look at the code on one page when upgraded to see if the placement has to change. Now if there are 3 mods working on a similar piece of code, it will be much harder to get a feel of the flow of the code. As it is, with regular code, to follow the logic you need to look at all the included files. I've found that to be quite a pain several times, but there it's understandable. I dunno. Maybe it will all work out, but I'm wondering if this is such a good thing... What's the big benefit? Just to make mods easier to install for newbies? (Just in case this comes off wrong, I'm not trying to say this in a negative manner or just to nag...I also want to check if I'm understanding this properly and give feedback about it. As always, I want it clear that I love vb!) |
#29
|
||||
|
||||
ok im a bit confused at how these hooks work.. i mean i understand the basics of it but i think i need a bit more explanation
now say i wanted to add my code into /admincp/user.php and i want to modify this area PHP Code:
PHP Code:
so would i need to do this? PHP Code:
|
#30
|
||||
|
||||
Quote:
|
#31
|
|||
|
|||
yeah ... I'd have to agree that most of the hacking I've done and would like to do involves calling extra fields in the database ... I haven't really looked into it yet, but it would seem that it would make alot of sense to have hooks at the end of some select statements.
... or better yet, have "replacement hooks" for some queries ... where the default querry would be used ... but if there was an active hook for that location, that segment would be replaced. Although I'm guessing this 2nd option would make you have to change your hook after upgrading if the original query required changes. Anyhow ... I guess I should try a Plug-in or two before I make too many more suggestions! lol |
Thread Tools | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|