Skip to content

Creating a Plugin with Lava

danielchatfield edited this page Dec 18, 2011 · 5 revisions

Plugin Structure

The following outlines all the files/folders that are to do with the Lava Framework. A working Plugin doesn't need all of these files & folders and can indeed have many more.

/plugin.php - The main file that contains the Plugin Header, and sets up the plugin administration options.

/pluginCallbacks.php - Contains the Plugin Callback Class which has all of the code that makes the plugin do its stuff

/branding.php - manages the look of the admin pages as well as any custom interfaces etc. The code is isolated from the rest of the plugin definitions as it is usually the same for every plugin by one author and isn;t included except on admin requests.

/skins/ - If the plugin needs skins then these are placed in here.

/extensions/ - Any extensions that the plugin has should be in here. The directory should exist whether the plugin is bundled with extensions or not.

/_static/ - This folder contains any custom styles or scripts for the admin interface.

/lava/ - This folder contains the Lava Framework code

plugin.php

Plugin Header

The top of your Plugin's main PHP file must contain a standard Plugin information header. This header lets WordPress recognize that your Plugin exists, add it to the Plugin management screen so it can be activated, load it, and run its functions; without the header, your Plugin will never be activated and will never run. Here is the header format:

<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>

Plugin definition

After the WordPress Plugin header you should have the lava definition which tells the Lava class that you want to create a plugin. It should look like this:

include( dirname( __FILE__ ) ."/lava/lava.php" );

$pluginName = "Name Of Plugin";
$pluginVersion = "Plugin Version";


$thePlugin = lava::newPlugin( __FILE__, $pluginName, $pluginVersion );
$pluginSlug = $thePlugin->_slug();

This loads the lava file and then registers a new plugin. The plugin name will appear in admin pages and on the sidebar. The plugin version should be a number with one decimal place. Whilst developing a plugin you should append "beta" to the plugin version number. This makes sure callbacks that are called if the version number doesn't match the one in the database are called every time. The plugin slug is a formatted version of the plugin name in lowercase and with no spaces.

Plugin Settings Definition

Assuming your plugin will have some settings for the user to define you should now define them. Lava will take care of the rest. To define a series of settings you must:

Access the lavaSettings class by calling the settings method.

$thePlugin->_settings()