An Overview on PHPFox Plugins
Simply, Plugins in phpfox are similar to hooks in wordpress. This is the best and the right way to customize your phpfox. You can inject your own custom code into phpfox controllers, service classes, templates etc where the plugin hooks are availble.

For example:
(($sPlugin = Phpfox_Plugin::get(‘blog.component_controller_view_process_start’)) ? eval($sPlugin) : false);
This is a plugin hook from the process() function of view controller inside the blog module. By using this plugin we can insert our custom code into blog/view controller. We will be able to use all the variables defined in that function or class in our custom code also.

How to write a custom plugin?
The first thing that we should know is, we can create plugins only at the locations where the plugins hooks are available. Phpfox has some built-in plugin hooks at different location in every calsses, controllers, templates etc. Like we have shown above.

Phpfox provides 2 different ways to create plugins.

1. Create plugin from phpfox admincp
2. Create plugin file.

Lets go with the above example to make it easier to understand. Inject our custom code into the process function of blog/view controller.
(($sPlugin = Phpfox_Plugin::get(‘blog.component_controller_view_process_start’)) ? eval($sPlugin) : false);
This plugin hook is already available in the process function().

Create plugin from phpfox admincp

To create a plugin from phpfox admincp,
Go to Extensions > Plugin > Create New Plugin
Select the your product name.
Select the module “Blog”.
Enter any name like “Blog view process start”.
Select appropriate hook name. Here that is ‘blog.component_controller_view_process_start’
Select the Active status Yes
Insert your custom code into the box

if (Phpfox::isUser())
{
$user = Phpfox::getUserBy('user_name');
echo $user;
}

Click save button.
Now go to any of your blog view page and refresh. You can see the username displayed in that page.

Create plugin file inside your custom module.

This is the most useful and suggested way to create your plugin. You can create the plugin inside your custom module or inside any other modules. Create a folder named ‘plugin’ inside the include folder in your module.
Inside that folder, create a file named “blog.component_controller_view_process_start.php”, that is the plugin name with php extension. Now clear the site cache from admincp. Done!
Any custom code you write in this file will be injected into the blog/view controller’s process() function start.
You need to clear the site cache after every change you made in this file. The active state of this plugin will depend upon the active state of your module. You can create any plugin in any modules plugin folder, only the file name matters.

If there no plugin hook available in a required location, you can request phpfox team to include a plugin hook in their next version release.

Hope it helps!

Know More About This Topic from our Techies

Latest Post