PDA

View Full Version : Creating a product - what variables are available?


crkgb
04-29-2009, 09:54 PM
I am trying to create a new product with its own plugins and templates. When I add a new plugin to my product, how do I know what objects are created and available, and what variables are set? The vBulletin manual states (http://www.vbulletin.com/docs/html/creating_a_product):
When adding code to a plugin, you should bear in mind that your code will have access to all variables and classes that are exposed at the point where the hook is placed.

vBulltin API docs (http://members.vbulletin.com/api/) provide lots of info on classes themselves, but nothing on what is available at what point?

j883376
04-29-2009, 10:03 PM
The product itself does nothing. It's just a container to your plugins. You have to look in each PHP file for the hook locations and then create a plugin which uses said hook. It will inject the code that you put into the plugin where you see ($hook= etc, etc)

crkgb
04-29-2009, 10:16 PM
The product itself does nothing. It's just a container to your plugins. You have to look in each PHP file for the hook locations and then create a plugin which uses said hook. It will inject the code that you put into the plugin where you see ($hook= etc, etc)
Thank you. Yes, I understand that the plugin will "replace" the corresponding hook in the php file with my plugin code. But before vBulletin loads that said file it also loads a number of others, where objects and variables are initialised, creating a working environment for my plugin. I am trying not to reinvent the bicycle by querying the database for the data that has been pulled already and is just sitting somewhere in an object I don't know about. That's what I am trying to figure out - how do I know what variables and objects are created by the time my hook is pulled up. I hope vBulletin provides some documentation on this and not just "go through the code" advice, although either one is appreciated.

j883376
04-29-2009, 10:28 PM
You read the code. Honestly, that's what I've seen a lot of other people say to do. It's personally how I learned how to program for vBulletin. You need to see what's defined in the PHP file for whatever you're trying to do. For example, if you want to do something right before a post is accepted and parsed into the database, you look for the proper hook (They have pretty easy to understand names) and then put in your code in that hook. The proper classes and functions that you'll need will be there elsewhere in the file.

The API is handy because it tells you the arguments for the functions and such, but it's not going to tell you what's in each of the files.

Lynne
04-29-2009, 10:30 PM
vBulletin does not have some list somewhere that tells you exactly what has been defined already at every hook location. You need to look at the php page and see what has been defined already.

j883376
04-29-2009, 10:31 PM
vBulletin does not have some list somewhere that tells you exactly what has been defined already at every hook location. You need to look at the php page and see what has been defined already.

Beat you to it ;)

Lynne
04-29-2009, 10:34 PM
So you did! :D

j883376
04-29-2009, 10:37 PM
So you did! :D

At first when I saw people saying "just read the code", I thought it was some sort of condescending "ur a n00bz lol" thing, but then I realized that there's no way to really code anything without going through the PHP files.

Lynne
04-29-2009, 10:43 PM
'Reading' the code also helps to tell you the name of the variable you want to use ($group or $discussion for example) and tells you if some fields other than the fields in the table have already been 'calculated' or evaled for you. It really does help to find your hook in the code and look at the stuff around it.

crkgb
04-29-2009, 11:00 PM
Thank you very much guys!

j883376
04-29-2009, 11:09 PM
Thank you very much guys!

We look forward to seeing some of your releases. :)

Dismounted
04-30-2009, 07:27 AM
You also have to look out for things you must set, otherwise, weird things will happen.