Third Party Contributions > API Based Plugins
Register global action
lmitoraj:
Hi everyone:) I'm new developer in roundcube:) I'm writing simply plugin. In this plugin I would like init by ajax action from other plugin:) It is possible?:) I try init action from extra plugin by her name action, but it doesn't work.
JohnDoh:
plugins can register an action like this:
$this->register_action('plugin.myplugin.action', array($this, 'do_something'));
eg: https://github.com/roundcube/roundcubemail/blob/master/plugins/acl/acl.php#L48
jcmoreno:
Hello, I'm having the same difficulty.
I need to trigger an alert immediately after the action of sending the email "send". I could not understand where to insert the code to perform the action, follow the alert.js and test.php that I create inside plugin/ (folder).
PS: the add_hook option works the alert runs on all the screens, but as I said need only after sending the email
---
teste.php
class teste extends rcube_plugin
{
public $task = 'mail';
private $rc;
/**
* Plugin initialization
*/
function init()
{
$this->rc = rcmail::get_instance();
// Plugin actions
// $this->add_hook('startup', array($this, 'startup'));
$this->register_action('plugin.teste', array($this, 'startup'));
}
function startup($args)
{
$rcmail = rcmail::get_instance();
$this->include_script('alert.js');
// Only AJAX actions
$this->rc->output->send();
}
}
---
alert.js
$(document).ready(function(e) {
alert('Catanduvas verdes!!!!');
});
Thank You.
JC
SKaero:
If you want to do something with PHP you use the "message_sent" https://github.com/roundcube/roundcubemail/wiki/Plugin-Hooks#message_sent hook. If you want to do something in JS you'd need to use the before/after hooks https://github.com/roundcube/roundcubemail/wiki/Plugin-Events#before-and-after
jcmoreno:
I was able to run the alert debug on the email composition screen, but it still runs when I enter the screen, I need to run the routine after the email is sent.
Studying the manual I found the message_ready someone can show by applying the command in my code?
--------------------
class testealert extends rcube_plugin
{
public $task = 'settings|mail|login';
function init()
{
$rcmail = rcmail::get_instance();
if ($rcmail->task == 'mail' && ($rcmail->action == 'compose')) {
$this->add_hook('startup', array($this, 'startup'));
}
}
function startup()
{
$this->include_script('alert.js');
}
}
--------------------
Thank You
JC
Navigation
[0] Message Index
[#] Next page
Go to full version