Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: Aurora on July 14, 2016, 01:08:18 PM

Title: Error Message when Implementing a Callback Function using Roundcube Plugin
Post by: Aurora on July 14, 2016, 01:08:18 PM
I wrote a plugin which hooks into attachment_upload.  I get the following error:

PHP Error:  Invalid callback function for attachment_upload in rcube_plugin_api.php at line 168.

I checked that add added the hook correctly in my init() function.

I put in some test messages.

Is it possible certain return args need to be specifically set?

Where are the list all values in the args[] array?

Aurora.
Title: Re: Error Message when Implementing a Callback Function using Roundcube Plugin
Post by: SKaero on July 14, 2016, 02:51:36 PM
Can you post your code?
Title: Re: Error Message when Implementing a Callback Function using Roundcube Plugin
Post by: Aurora on July 18, 2016, 05:05:24 PM
Posted Code:

1. config-inc.php:    $config['plugins'] = array('carryon');

2. carryon.php

class carryon extends rcube_plugin
{
     public $container;
     public $dbuf;

     function init()
     {
         $this->add_hook('attachment_upload', array($this, 'upload');
     }

   function upload($args)
   {
        $temp_dir        = rcmail::rcmail::get_instance();
        $tmpfname      = tempnam($temp_dir, 'rcmAttmnt');
        $args['id']        = $this->file_id();
        $args['path']    = $tmpfname;
        $args['status'] = false;

        return $args;
  }

         
Title: Re: Error Message when Implementing a Callback Function using Roundcube Plugin
Post by: SKaero on July 18, 2016, 05:20:23 PM
You need to add "public" before your functions since its in a class, you also are over stacked on your rcmail calls, "rcmail::rcmail::get_instance()" should be "rcmail::get_instance()":
Code: [Select]
class carryon extends rcube_plugin
{
     public $container;
     public $dbuf;

     public function init()
     {
         $this->add_hook('attachment_upload', array($this, 'upload');
     }

   public function upload($args)
   {
        $temp_dir        = rcmail::get_instance();
        $tmpfname      = tempnam($temp_dir, 'rcmAttmnt');
        $args['id']        = $this->file_id();
        $args['path']    = $tmpfname;
        $args['status'] = false;

        return $args;
  }