Getting Started with Plugin Development
A minimum viable Pubvana plugin requires exactly two files: plugin_info.json and Plugin.php. Everything else is optional and added incrementally.
Step 1: Create the Plugin Directory
mkdir plugins/MyPlugin
The directory name becomes the namespace root. Use PascalCase with no spaces or hyphens.
Step 2: Create plugin_info.json
{
"name": "My Plugin",
"version": "1.0.0",
"min_pubvana_version": "2.2.3",
"max_pubvana_version": "2.2.4",
"update_url": "https://example.com/api/update/check",
"support_url": "https://example.com/contact",
"description": "A short description of what this plugin does.",
"author": "Your Name"
}
The slug field must be lowercase, no spaces, no hyphens. It is used as the URL prefix and settings namespace.
Step 3: Create Plugin.php
<?php
namespace PluginsMyPlugin;
use AppInterfacesPluginInterface;
class Plugin implements PluginInterface
{
public function getName(): string
{
return 'My Plugin';
}
public function getSlug(): string
{
return 'myplugin';
}
public function getVersion(): string
{
return '1.0.0';
}
public function getMenuItems(): array
{
return [];
}
public function getCsrfExemptions(): array
{
return [];
}
public function getPublicRoutes(): array
{
return [];
}
public function register(): void
{
// Nothing yet
}
}
Step 4: Discover and Activate
- Log into the Pubvana admin panel
- Go to Plugins
- Click Discover Plugins — Pubvana scans
plugins/and findsMyPlugin - Click Activate next to My Plugin
Step 5: Add a Route and Controller
Create plugins/MyPlugin/Config/Routes.php:
<?php
$routes->get('myplugin', 'PluginsMyPluginControllersMain::index');
Create plugins/MyPlugin/Controllers/Main.php:
<?php
namespace PluginsMyPluginControllers;
use AppControllersBaseController;
class Main extends BaseController
{
public function index(): string
{
return $this->themeService->view('PluginsMyPluginViewsstoreindex', [
'page_title' => 'My Plugin',
]);
}
}
Create plugins/MyPlugin/Views/store/index.tpl:
{% extends "layout.tpl" %}
{% block content %}
<div class="{{ cls.cls_container }}">
<h1>Hello from My Plugin</h1>
</div>
{% endblock %}
Namespace Convention
| Item | Convention |
|---|---|
| Directory | plugins/MyPlugin/ |
| PHP namespace root | PluginsMyPlugin |
| Controllers | PluginsMyPluginControllers |
| Models | PluginsMyPluginModels |
| Services | PluginsMyPluginServices |
| Views (admin) | PluginsMyPluginViewsadmin |
| Views (public) | PluginsMyPluginViewsstore |