PDA

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


crkgb
29 Apr 2009, 22:54
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
29 Apr 2009, 23:03
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
29 Apr 2009, 23:16
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
29 Apr 2009, 23:28
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
29 Apr 2009, 23:30
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
29 Apr 2009, 23:31
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
29 Apr 2009, 23:34
So you did! :D

j883376
29 Apr 2009, 23:37
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
29 Apr 2009, 23:43
'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
30 Apr 2009, 00:00
Thank you very much guys!

j883376
30 Apr 2009, 00:09
Thank you very much guys!

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

Dismounted
30 Apr 2009, 08:27
You also have to look out for things you must set, otherwise, weird things will happen.