...
- /plugins/
- my_plugin/
- controllers/
- models/
- views/
- language/
- my_plugin_controller.php
- my_plugin_model.php
- my_plugin_plugin.php
- config.json (for version 3.1+)
- my_plugin/
my_plugin_controller.php is the plugin's parent controller. This controller can be used to add supporting methods for the other controllers to inherit. Similarly, my_plugin_model.php is the plugin's parent model and can be used to add supporting methods for the other models to inherit.
...
Finally, my_plugin_plugin.php is a special class that must extend the Plugin class of /components/plugins/lib/plugin.php. This class is used for installing, upgrading, uninstalling, and branding the plugin in conjunction with the config.json file.
Install Logic
If your plugin requires any code to execute when installed, place that logic in your plugin's install() method.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php class MyPluginPlugin extends Plugin { public function __construct() { Loader::loadComponents($this, array("Input")); } ... public function upgrade($current_version, $plugin_id) { // Ensure new version is greater than installed version if (version_compare($this->version, $current_version) < 0) { $this->Input->setErrors(array( 'version' => array( 'invalid' => "Downgrades are not allowed." ) ); return; } } } ?> |
Branding The Plugin
For version 3.1+ simply create a config.json file and include it in the constructor of your plugin.
Code Block | ||||
---|---|---|---|---|
| ||||
{ "version": "1.0.0", "name": "My Plugin Name", "description": "A plugin like no other!", "authors": [ { "name": "Phillips Data, Inc.", "url": "http://www.blesta.com" } ] } |
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
class MyPluginPlugin extends Plugin {
public function __construct() {
$this->loadConfig(dirname(__FILE__) . DS . "config.json");
}
}
?> |
For version 3.0, you must define all of the branding details through methods.
Expand | |||||||||
---|---|---|---|---|---|---|---|---|---|
| |||||||||
All that any plugin truly requires is branding. These options come from three methods: getName(), getVersion(), getAuthors().
The getAuthors() method requires a multi-dimensional array, so you can specify multiple authors if needed. |
Info | ||
---|---|---|
| ||
Use the Language library to help internationalize your plugin. Just create a language directory in your plugin, then a directory for each language (i.e. /plugins/my_plugin/language/en_us/) and place your language files in there. See Translating Blesta for how to load, format, and use language definitions. |
Lastly, each plugin needs a logo. By default these are loaded from /plugins/my_plugin/views/default/images/logo.png. You can override the location of the logo file by implementing the getLogo() method in your plugin. |
...
Code Block | |
---|---|
php | |
title | /plugins/my_plugin/my_plugin_plugin.php |
linenumbers | true | <?php class MyPluginPlugin extends Plugin { ... public function getLogo() { return "views" . DS . "default" . DS . "images" . DS . "some_other_logo.png"; } } ?> |
Info | ||
---|---|---|
| ||
Use the Language library to help internationalize your plugin. Just create a language directory in your plugin, then a directory for each language (i.e. /plugins/my_plugin/language/en_us/) and place your language files in there. See Translating Blesta for how to load, format, and use language definitions. |
Managing a Plugin
If your plugin requires certain configurable options, you can create a management link viewable to staff members that have access to installed plugins. To do so, all you need to do is create an AdminManagePlugin controller. This is a special controller that is initialized by Blesta internally, so all views must be returned (as strings) from the requested action methods.
...