Hotaru Docs


Making a Plugin - Case Study 2: Hello World Widget

Plugin Versus Widget

There isn't much difference between a plugin and a widget in Hotaru. In fact, a Hotaru widget is a plugin which can be displayed in any widget block (the default theme's sidebar.php contains a widget block). Examples include the Categories Widget, Posts Widget, Search, and RSS feeds from the RSS Show plugin.

How to make a Hello World widget

Here are the steps you need to take to make the most basic of widgets, one that does nothing more than display "Hello World" in your sidebar. Of course, you could do this manually in about 5 seconds, but this way is much more fun!

1. Build the Hello World plugin

The best place to start is with the Hello World plugin. If you haven't already done so, go and make that first. You can also download the Hello World plugin here.

2. Change the Header info

Update the description and version number, require the Widgets plugin, and a different hook to replace the old "hello_world" one:

 * name: Hello World
 * description: Displays "Hello World!" in the sidebar
 * version: 0.2
 * folder: hello_world
 * class: HelloWorld
 * requires: widgets 0.6
 * hooks: install_plugin

3. An install function

The install_plugin function will register your plugin as a widget when it's installed. Add it within your HelloWorld class.

public function install_plugin($h)
    // plugin name, function name, optional arguments
    $h->addWidget('hello_world', 'hello_world', '');  

4. Rename the old Hello World function

This function was originally called hello_world, but since we're not making a manual plugin hook for it anymore, we need to use a special function name for widgets: widget_hello_world

public function widget_hello_world()
    echo "Hello World!";

5. Install and enjoy!

Go to Plugin Management and install the Widgets and Hello World plugins if you haven't already. Installing it will register it as a widget and you can then go to Admin -> Widgets under Plugin Settings and move your widget around.

Case Study 3: Tweet This

Getting StartedDesign and LayoutPlugin DevelopmentAdvanced TopicsFunction ReferenceTroubleshooting