Plugins can do just about anything. Create custom cron jobs, listen for events, create pages, create widgets, extend the API, etc., etc. If it's not a Module or a Payment Gateway, it's a plugin. So let's dig in.
...
Code Block |
---|
language | php |
---|
title | /plugins/my_plugin/my_plugin_plugin.php |
---|
linenumbers | true |
---|
|
<?php
class MyPluginPlugin extends Plugin {
public function __construct() {
Loader::loadComponents($this, array("Input"));
}
...
public function upgrade($current_version) {
// 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
All that any plugin truly requires is branding. These options come from three methods: getName(), getVersion(), getAuthors().
Code Block |
---|
language | php |
---|
title | /plugins/my_plugin/my_plugin_plugin.php |
---|
linenumbers | true |
---|
|
<?php
class MyPluginPlugin extends Plugin {
...
public function getName() {
return "MyPlugin";
}
public function getVersion() {
return "1.0.0";
}
public function getAuthors() {
return array(
array(
'name' => "MyCompany",
'url' => "http://www.mycompanyplugindevelopment.com"
)
);
}
}
?> |
The getAuthors() method requires a multi-dimensional array, so you can specify multiple authors if needed.
Info |
---|
title | Internationalize it! |
---|
|
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 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 |
---|
language | 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";
}
}
?> |