Call these functions in your My_Plugin/index.php file.
Install, uninstall, activate and deactivate
Installation hook. Runs when the plugin is installed. Run the needed SQL queries or validate the purchase code here.
register_installation_hook("My_Plugin", function ($item_purchase_code) {
//validate purchase code if you wish
if (!validate_purchase_code($item_purchase_code)) {
echo json_encode(array("success" => false, 'message' => "Invalid purchase code"));
exit();
}
//run necessary sql queries
$db = db_connect('default');
$db_prefix = get_db_prefix();
$db->query("SET sql_mode = ''");
$db->query("CREATE TABLE IF NOT EXISTS `" . $db_prefix . "plugin_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
`deleted` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;");
});
Uninstallation hook. Runs when the plugin is uninstalled.
register_uninstallation_hook("My_Plugin", function () {
//run something
});
Activation hook. Runs when the plugin is activated.
register_activation_hook("My_Plugin", function () {
//run something
});
Deactivation hook. Runs when the plugin is deactivated.
register_deactivation_hook("My_Plugin", function () {
//run something
});
Update hook. Shows information about updating your plugin. If your update needs a minimum version of RISE, check it here.
register_update_hook("My_Plugin", function () {
//show necessary information to update this plugin in the modal
});
Data hooks
These run for every table that is saved through the main app's models.
Before insert. Runs before a new row is inserted. You can change the data. Always return the array.
register_before_insert_filter_hook(function ($data) {
/*
the $data array has 3 items
table => associated table with db prefix
table_without_prefix => associated table without db prefix
data => data array that will be inserted
*/
return $data;
});
Data insert hook.
register_data_insert_hook(function ($data) {
//some data has been inserted
/*
the $data array has 4 items
id => inserted id
table => associated table with db prefix
table_without_prefix => associated table without db prefix
data => inserted data array
*/
});
Data update hook.
register_data_update_hook(function ($data) {
//some data has been updated
/*
the $data array has 4 items
id => updated id
table => associated table with db prefix
table_without_prefix => associated table without db prefix
data => updated data array
*/
});
Data delete hook.
register_data_delete_hook(function ($data) {
//some data has been deleted
/*
the $data array has 3 items
id => deleted id
table => associated table with db prefix
table_without_prefix => associated table without db prefix
*/
});
Added in RISE 4.2
Each of these has its own article with examples.
| Function | What it does | Article |
| register_notification_event() | Adds your own notification event to the notification settings. | Add notifications from a plugin |
| register_notification_term() | Adds your own "Notify to" option for your events. | Add notifications from a plugin |
| register_email_template() | Adds your own email template to the email templates settings. | Add email templates from a plugin |
| send_email_template() | Sends an email with a template, in the given language. | Add email templates from a plugin |
| register_payment_gateway() | Adds an online payment method. | Add a payment gateway from a plugin |
| register_payment_context() | Takes online payments for your own records (not invoices). | Take online payments from a plugin |
For files, see Work with files from a plugin.