English plugin dev 1 1

goodpic edited this page Nov 7, 2011 · 19 revisions

First steps in developing plug-ins


This is the first step in developing plug-in: an overview

Types of plug-ins

Plug-ins are small pieces of code that add a specific and limited function to Movable Type. The Movable Type plugins have the following main types

  • Function Tag Plugin
    • Extending Movable Type with new template tags. it is also possible to contact external services and interact with their API for richer page
  • Block Tag Plugin
    • Movable Type includes the ability to write block-tags, that transform entire block, or defines a specific variables / context for the scope of the block
  • Conditional Tag Plugin
    • Similar to block tags, but focus on a condition. If that condition does not true, will skip the block
  • Global Modifier Plugin
    • Global modifier is a type of template tag argument that has the ability to transform the contents of the some function tag. A plugin can add new global modifier similar to dirify or pad.
  • Transformer Plugin
    • A plugin that customize some screens, similar to CustomFields
  • Spam filter Plugin
    • A plugin can add new criteria on which Movable Type marks comments and trackbacks as spam

Plug-in directory structure

The plug-in directory structure, it is based on Movable Type’s own structure. For example, if the plug-in is called MyPlugin, here is how to organize the directory structure. (Where MT is installed at $MT_DIR directory)

|__ plugins/
|  |__ MyPlugin/
|     |__ config.yaml
|     |__ my_plugin.cgi
|     |_ t/
|     |  |_plugin_test.t
|     |__ lib/
|     |  |__ MyPlugin.pm
|     |__ tmpl/
|     |  |__ config.tmpl
|     |__ php/
|        |__ function.my_plugin.php 
|__ mt-static/
   |__ plugins
      |__ MyPlugin/
         |__ styles.css
         |__ images/
         |  |__ logo.jpg
         |__ js/
            |__ myplugin.js
  • Plugin Script directory
    • Under MT’s plugins directory, create a directory for your plugin. In that directory there should be a configuration file for the plugin, (config.yaml) a “lib” directory for various Perl modules, “tmpl” for templates, etc. If you want to put your plugins in other places, change the PluginPath configuration directive
  • Static Files
    • Images, Style sheets, JavaScript files and other statics should be placed in $MT_DIR/mt-static/plugins/MyPlugin. (this is configurable using the StaticWebPath configuration directive)
  • Support For Dynamic Publishing
    • If your plugin supports dynamic publishing, place the PHP files in plugins/MyPlugin/php/, named in accordance to the smarty framework
  • Test Files
    • Please put your plugin test files in the plugins/MyPlugin/t/ directory

Step in the development of plug-ins

  1. Create a YAML file named config.yaml and put it in the plugin script directory (MT/plugins/)
  2. Create a test file for Test-driven development.
  3. Write your Perl code, using the Movable Type API. The API is documented using the perldoc format, and can be viewed with the following command:
     $ cd lib
    $ perldoc MT.pm

    Also, we publish this documentation on the web:
  4. Test your Perl code. if if fails then either the code or the test is wrong. or both. fix and repeat
  5. If the plugin includes template tags or filters, you may need to support dynamic publishing. Write the needed PHP scripts and put them in the php directory
  6. Add images and style sheets, release notes and operation manual so people will know how to use your plugin
  7. Create a package for distribution, compressed using zip or tar.gz, and includes the directory structure

Starting a Plugin

Starting from Movable Type 3.2, each plugin is registered, and can be activated or deactivated from the plugins setting screen.

For our first plugin, let’s write plugin that only registers itself to MT.

Put the following text in $MT_DIR/plugins//config.yaml (for example, $MT_DIR/plugins/MyPlugin01/config.yaml)

id: MyPlugin01
name: Sample plugin registration
version: 1.0
description: Sample plugin registration
author_name: Plugin author
author_link: http://www.example.com/about/
doc_link: http://www.example.com/docs/

Explaining the fields:

  • id (required)
    • A unique ID for this plugin
  • name (required)
    • The full name of the plugin
  • version (required)
  • description
    • A summary describes the plug-in. Which features do you offer in this plugin, and simply explained.
  • author_name、author_link
    • The name of the author, and link to his home page. If you have a plugin-homepage, use plugin_link instead of author_link
  • doc_link
    • A link to release notes and other documentation. very important – please include it

Extending Movable Type

A plugin can extend Movable Type, using some of:

  • Extending the Registry
    • Almost everything in Movable Type is connected to the Registry, and a plugin can extend it.
  • Extend and create objects using MT components
    • It is possible to extend existing objects or create new objects using the MT component
  • Managing plugin components
    • Add new management screens to the CMS for adding, deleting and modifying your components
  • Implementation by config.yaml
    • We recommend new style plugin definition by config.yaml. Of course, You can still write a plugin by xxx.pl.
    • You can write your perl functions in config.yaml as a following example, but it is not recommended since it will make harder to trace a bug when you are debugging.
        HelloWorld: sub { return "Hello, world!" }

Best Practices for Developing Plug-ins

  • When writing a tag, don’t put MT in the beginning, as it cause the template writers to use “<$MTMTfoobar$>” which is ugly
  • Always put a link to the plugin documentation and release notes
  • If your plugin have settings, provide a configuration setting screen
  • Do not access directly to the database, use MT’s API
  • Consider the memory usage of the plugin – please make it as compact as possible
  • Movable Type is designed to run on Perl version 5.8 and up. make sure your plugin is too
  • A lot of our users are using dynamic publishing. Try to provide dynamic publishing support for template tag, filters and global modifiers

Plugin Download



Index >> Next:Extending the registry using yaml

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.