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

[Docs] Extending Plugins

Discussion in 'Developing Plugins' started by Nick, Jan 10, 2010.

  1. Nick

    Nick Well-Known Member

    Hotaru's ability to extend plugins is one of the best features of this CMS. Without any plugin hooks, you can alter or extend the behavior of other plugins, simply by overriding functions with new functions of the same name. Here's are two examples:

    Goodbye World - alters the Hello World plugin so that it displays "Goodbye World!" instead of "Hello World!"

    PHP:
    <?php
    /**
     * name: Goodbye World
     * description: Displays "Goodbye World!"
     * version: 0.1
     * folder: goodbye_world
     * class: GoodbyeWorld
     * extends: HelloWorld
     * hooks: hello_world
     * requires: hello_world 0.5
     */

    class GoodbyeWorld extends HelloWorld
    {
        
    /**
         * Displays "Goodbye World!" wherever the plugin hook is.
         */
        
    public function hello_world()
        {
            echo 
    "Goodbye World!";
        }
    }

    ?>
    Submit Light - Alters the Submit plugin so that it doesn't use step 3 of submission.

    PHP:
    <?php
    /**
     * name: Submit Light
     * description: Reduces Submit to two steps
     * version: 0.1
     * folder: submit_light
     * class: SubmitLight
     * hooks: theme_index_top
     * requires: submit 1.9
     * extends: Submit
     */

    class SubmitLight extends Submit
    {
        
    /**
         * Determine the submission step and perform necessary actions
         */
        
    public function theme_index_top($h)
        {
            
    /* This is the same (long) function as the one in Submit, except 
                the step 3 code has been removed and a successful submission 
                at step 2 redirects to the Latest page. */
        
    }
    }
    You can, of course, add new functions and extra plugin hooks. Just be aware of how Hotaru processes plugins:

    Hotaru has a list of plugin hooks, taken from the top of all plugin files. It goes through the list, looking for those functions...

    1. If Hotaru finds a child function (e.g. in GoodBye World), it uses that instead of its parent function (e.g. in Hello World);
    2. If it can't find the function it's looking for in the child plugin, it looks in the parent plugin;
    3. If it can't find the function it's looking for in the child or parent plugins, it looks in Hotaru.php (there are default fall-back functions there.)
     

Share This Page