1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[Docs] Making a Plugin - Case Study 1: Hello World

Discussion in 'Developing Plugins' started by Nick, Jun 18, 2009.

  1. Nick

    Nick Well-Known Member

    The first ever plugin for Hotaru CMS is, unsurprisingly, Hello World. It's a plugin that does absolutely nothing, except display the words "Hello World" on the screen. While the result isn't very impressive, it's a good first step in learning how Hotaru CMS plugins are put together.

    There are 5 key steps in making a plugin:

    1. You must have a folder, e.g. "hello_world".

    2. You must have a .php file with exactly the same name as the folder.

    3. You must include comments at the top of the file. Here's a list of what's needed and what's optional:

    name - plugin name
    description - plugin description
    version - version number
    folder - plugin folder name
    class - plugin class name
    hooks- comma separated list of plugin hooks (all on the same line)

    type - the kind of plugin, e.g. "avatar"
    requires - for plugin dependencies
    extends - for overriding another plugin
    author - for the plugin author's name
    authorurl - for a link to the author's website.

     * name: Hello World
     * description: Displays "Hello World!"
     * version: 0.1
     * folder: hello_world
     * class: HelloWorld
     * hooks: hello_world
     * You can type notes here
    4. You must wrap your functions in a class that extends the PluginFunctions library, e.g.:

    class HelloWorld

    5. You must have a function with the same name as each hook [1], with $h as the first parameter [2]. For example:

    class HelloWorld
        public function 
    "Hello World!";
    Once that's done, put the plugin folder in Hotaru's content/plugins directory, then go to Admin->Plugin Management and install it in Admin -> Plugin Management.

    To see the results, you just need to add this line in your template [3]:

    <?php $h->pluginHook('hello_world'); ?>

    [1] If you include a plugin hook in the comment block at the top of the file, but don't have a function for it, Hotaru will fall back on the default method in the Hotaru.php under "DEFAULT PLUGIN HOOK ACTIONS". If there's no default function either, you'll get an error. You can use this fall-back behavior to your advantage, using it to simplify plugins.

    [2] Hotaru passes the global $h object to every plugin hook function. This can then be used to access all of Hotaru's built-in functions.

    [3] You don't have to make your own plugin hook. You can use any existing hook just as long as you put the hook name in the comment block and give your function the same name. In the case of Hello World, change the hook and function name to footer, reinstall the plugin and you should see "Hello World!" displayed in your footer. That's because it's using a built-in plugin hook in footer.php called "footer".
    Last edited: Jan 8, 2010
    JonH likes this.

Share This Page