Home > MT-Plugin-Plugin-Callbacks

MT-Plugin-Plugin-Callbacks

MT-Plugin-Plugin-Callbacks is a project mainly written in Perl, based on the GPL-3.0 license.

Movable Type exposes a number of different callbacks that developers can hook their code to. Missing, however, are callbacks triggered by events occurring to plugins themselves. This plugin adds those callbacks.

Overview

Movable Type exposes a number of different callbacks that developers can hook their code to. But sometimes you want a little extra mustard. Sometimes you just need a callback in a certain place. This plugin demonstrates how to do exactly that.

Whether you should is not a topic I'm going to cover here. Just be aware that there are very good reasons not to do this, and that there are other ways of accomplishing the same thing.

How to Use

Other plugins can consume your custom callbacks by doing something like this in their config.yaml file:

callbacks: pc_pre_save: $Example::Example::Plugin::pre_save pc_post_save: $Example::Example::Plugin::post_save

And then they consume the callbacks like so:

sub presave { my ($cb, $param, $scope, $pdata) = @;

# Do your thing.

}

This process should already be familiar to developers. The real magic occurs in the overriding of MT's core methods as demonstrated in this plugin's Plugin.pm file.

A Note

You should not use this plugin as is. The specific callbacks demonstrated by this plugin are already built into the core MT:Object system and so this code should serve only as an example of what you can do. If you need to use the pre/post_save callback on a plugin you should use:

callbacks: MT::PluginData::pre_save: $Example::Example::Plugin::pre_save MT::PluginData::post_save: $Example::Example::Plugin::post_save

Acknowledgements

I'd like to give a special thanks to the following people for paricipating in the discussion that led to this plugin:

Steve Cook
Byrne Reese
Mike Thomsen
Dan Wolfgang