User:Skippy/Creating A Plugin Part 1

From Habari Project

Jump to: navigation, search

A plugin is something that extends or enhances the internal functioning of Habari. Throughout the Habari source code are calls to plugin hooks: these hooks are the places in which plugins can execute. A plugin is not a complete program, but rather a portion of a program that gets integrated into, and invoked by, Habari.

Actions and Filters

Habari defines two different things a plugin can do, called actions and filters. Actions do stuff, and filters change stuff. For example, before Habari saves a post into the database it first invokes the filter post_insert_allow, passing along the current Post object and a boolean variable $allow. Any plugins that implement the filter_post_insert_allow method will receive the post object and the $allow variable. The plugins could make a decision as to whether or not to save the post to the database, and return their decision in the $allow variable. If the final value of $allow is false, Habari will not save the post.

Similarly, after saving a new post to the database, Habari triggers the post_insert_after plugin hook. Any plugins that implement the action_post_insert_after method will be executed, and passed a copy of the Post object that was saved. A plugin might send email notification to a list of subscribers, for example. Even if an action sends back a return value, Habari won't use it.

Objected Oriented

In fact, all Habari plugins are object classes which extend the core Habari Plugin class. The Plugin class defines the basics of what a plugin can do, and ensures that all plugin classes implement the same minimal functions.

When you write your own plugins, you'll extend the core Plugin class. You extend the Plugin<code> class like this:

class Foo extends Plugin

Here, <code>Foo is the name of your class. Generally speaking, you'll want to name your plugin class close to what the name of your plugin is. So if you're writing a plugin that you've decided to call "Free Ponies", you might name your class FreePonies.

Personal tools