Writing Plugin Code 
Plugin code is regular PHP, and should be written as if editing the vBulletin scripts directly.

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.

For example, let us consider this hypothetical hook in a hypothetical script:


$foo 1;
$bar 2;

$hook vBulletinHook::fetch_hook('hypothetical_hook')) ? eval($hook) : false;

'print_output("' fetch_template('hypothetical_template') . '");');

Using this code, when the script terminates, $foo will equal 1 and $bar will equal 2.

We will now add a plugin to the hypothetical_hook hook, using this code:
if ($_SERVER['REMOTE_ADDR'] == '')
$foo 10;
$bar 20;

When PHP runs the script now, the code will appear in effect as this, where the red code is the plugin code:


$foo = 1;
$bar = 2;

if ($_SERVER['REMOTE_ADDR'] == '')
    $foo = 10;
    $bar = 20;

eval('print_output("' . fetch_template('hypothetical_template') . '");');

At the termination point of the script, if the IP address of the visiting browser is, $foo will now equal 10 and $bar will equal 20, though the original PHP code remains unmodified.
User Contributed Notes: Writing Plugin Code Add a Comment
Ryan 14th Apr 2016, 03:09am
This is a typo right?

eval('print_output("' . fetch_template('hypothetical_template) . '");');

Should it be:

eval('print_output("' . fetch_template('hypothetical_template') . '");');
Add a Comment