Skip to content

Extending Datawrapper

gka edited this page Jun 11, 2013 · 3 revisions

You can extend Datawrapper by creating a new plugin. Our plugin architecture was heavily inspired by the way Wordpress plugins work.

Hooks-API

DatawrapperHooks::register( hook_name, hook_function )

Called by the plugins who want the hook_function to be executed by the core on certain occasions.

Example plugin that hooks into mail sending process:

function mymail($to, $subject, $body, $headers) {
   return mail($to, $subject, $body, $headers);
}
DatawrapperHooks::register('send_email', 'mymail');

DatawrapperHooks::execute( hook_name, args )

Called by the core to allow plugins execute their own code. This executes any function that has been registered for a hook.

Example code that sends mail via hook functions:

DatawrapperHooks::execute(
   "send_email",
   "[email protected]",
   "Hello world",
   "Hi John, hope you're fine."
);

Adding visualizations

DatawrapperVisualization::register( plugin, vis_meta )

Allows plugins to register new visualizations. With the first argument the plugin should pass a reference to itself, the second argument is the array that used to be stored in the visualizations meta.json.

DatawrapperVisualization::register($this, array(
   "id" => "pie-chart",
   "extends" => "raphael-chart"
));