Home » V2 » Plugins


Contents

Introduction

We use plugins to interact with the core product, modules or other 3rd party plugins without the need to modify the source code as it simply plugs into 3rd party code. We have gone over how to create a Product and a Module. In order to work with a module you need to create new PHP and HTML source files, however with plugins you can do this from the comfort of the AdminCP. We also provide the method to create plug-ins via a PHP source file as it is easier to develop when using an IDE compared to working with code in the AdminCP. In the examples we will be using the product we created earlier as well as the module we worked on.

Creating a Plugin via the AdminCP

Log into your AdminCP and navigate to:

Extensions >> Plugin >> Create New Plugin

Complete the Form

Product

We will use the product we created earlier:

phpFox Sample Product

Module

We will use the module we worked on earlier:

phpfoxsample

Title

We need to identify the plugin and here is where you can best describe what your plugin does. Here we can add:

User Space Usage

Hook

The drop down provides a long list hooks provided by the script and is where you can plugin your code. In order to find where you want to plug your code in you will need to look further into the source code and find the right spot to place for your plugin depending what it is you would like to accomplish. In this example we will be adding a plugin to display the total space usage for a user on their profile in the Basic Information block. This block can be found on a users profile and is located on the side panel. For the hook find and select:

profile.template_block_info

We selected this hook as it can be found in the file:

/module/profile/template/default/block/info.html.php

look for:

{plugin call='profile.template_block_info'}

This is where we plan on plugging in our code.

Active

This identifies if a plugin is active or inactive. Lets set this to Yes.

PHP Code

Here is where you can add your PHP code. You do not need to add the PHP open and closing tags. Let us add the following:

$aUser = $this->getVar('aUser');
echo '<div class="p_2">';
echo 'Space Usage: ' . Phpfox::getLib('phpfox.file')->filesize($aUser['space_total']);
echo '</div>';

Your form should look similar to this: http://wiki.phpfox.com/images/screenshot_30.png

Submit the form and visit a members profile. Look for the Basic Information block and you should find at the bottom:

Space Usage

As you can see modifying the core product and other 3rd party products won't be has hard as it has been in the past since it does not require overwriting or breaking source code.


Previous Chapter: Modules | Next Chapter: Completed Product



Copyright © Benc Enterprises AB, 2005-2010. All Rights Reserved.
Toll Free (US/Canada):