What's the difference between a plugin and a widget?
There isn't much difference at all. 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...
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:
3. An install function
* 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
The install_plugin function will register your plugin as a widget when it's installed. Add it within your HelloWorld class.
4. Rename the old Hello World function
public function install_plugin($h)
$h->addWidget('hello_world', 'hello_world', ''); // plugin name, function name, optional arguments
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
5. Install and enjoy!
public function widget_hello_world()
echo "Hello World!";
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.