Writing your first plugin

Ok, lets start by writing a simple plugin. Basically, each plugin is a PHP class that inherits from the predefined class NucleusPlugin. Below is an example of a HelloWorld-plugin:

<?php

class NP_HelloWorld extends NucleusPlugin {

	// name of plugin
	function getName() {
		return 'Hello World';
	}

	// author of plugin
	function getAuthor()  {
		return 'Wouter Demuynck';
	}

	// an URL to the plugin website
	// can also be of the form mailto:foo@bar.com
	function getURL()
	{
		return 'http://nucleuscms.org/';
	}

	// version of the plugin
	function getVersion() {
		return '1.0';
	}

	// a description to be shown on the installed plugins listing
	function getDescription() {
		return 'Just a sample plugin.';
	}

	function doSkinVar($skinType) {
		echo 'Hello World!';
	}

}
?>
  1. Copy this code in a file called NP_HelloWorld.php, and put it in your plugins directory. Make sure that there are no spaces after the last ?> or before the first <?.. By the way, NP stands for "Nucleus Plugin" :-)
  2. Open the Nucleus Administration area and go into Nucleus Management/Manage Plugins
  3. You'll find out that there's a HelloWorld plugin you can install. Do this. If everything worked out correctly, you'll see that your plugin is now listed in the list of installed plugins.
  4. Now edit some skin, and insert the following statement at a place of which you know where it will show up on the actual page.
    <%plugin(HelloWorld)%>
    Some notes: the name (HelloWorld) is case sensitive!
  5. Now visit a page that uses the skin you edited: notice the "Hello World" on the location where you added the plugin-skinvar

So, that wasn't so hard after all. Read on to find out more.

Plugin API