Initializing the Plugin - lokothodida/DM_Matrix GitHub Wiki
So you've read up on your PHP now and understand some of the essential tools required to start developing a GetSimple plugin. Let's hop to it then!
Plugin structure
GetSimple plugins are stored in the /plugins directory of the installation. A well build plugin tends to be made up of the following files:
- A main PHP file (that has the hooks to the GetSimple API
- A corresponding folder that contains the necessary plugin files (php, css, javascript etc...)
- A CSS folder for the sheetstyles
- A JS folder for the Javascript
- An IMG folder for the images
- An INCLUDE folder for the extra PHP files
- A LANG folder for the language files
So assuming that we have a plugin called 'dummy', our plugin structure might look something like this:
- dummy.php
- dummy(directory)
- .htaccess (with one line: Deny from all)
- css (directory)
- .htaccess (with one line: Allow from all)
- style.css
- js (directory - houses any Javascript files you might need)
- .htaccess (with one line: Allow from all)
- script.js
- img (directory - houses any images you might need (particularly for your CSS rules)
- .htaccess (with one line: Allow from all)
- add.png
- delete.png
- edit.png
- lang (directory)
- .htaccess (with one line: Deny from all)
- en_US.php
- de_DE.php
- it_IT.php
- include (directory - houses any php files you might need)
- .htaccess (with one line: Deny from all)
- dummy.class.php (main class that subsumes all of the necessariy includes)
- admin.class.php (class for building admin-end functions)
- display.class.php (class for displaying plugin content on the front-end (e.g. as pages))
Again, this is just an example structure that you may want to adopt.
PHP files
dummy.php
This is the basic structure of your main php file.
<?php
/* DUMMY PLUGIN
* DUMMY PLUGIN DESCRIPTION
*/
# requires
require_once(GSPLUGINPATH.'dummy/php/dummy.class.php');
# class instantiation
$dummy = new Dummy; // instantiate class
# register plugin
register_plugin(
$dummy::ID, // id
$dummy::NAME, // name
$dummy::VERSION, // version
$dummy::AUTHOR, // author
$dummy::URL, // url
$dummy::DESC, // description
$dummy::PAGE, // page type - on which admin tab to display
array($dummy, 'admin') // main function (administration)
);
# activate actions/filters
# front-end
add_action('error-404', array($dummy, 'display')); // display for plugin
# back-end
add_action($dummy::PAGE.'-sidebar', 'createSideMenu' , array($dummy::ID, $dummy::SIDEBAR)); // sidebar link
?>
dummy.class.php
<?php
/* Class for subsuming your various plugin pieces into one include file
*/
// load all PHP includes
foreach (glob(dirname(__FILE__).'/*.php') as $php) {
$php = realpath($php);
if ($php!=realpath(__FILE__)) {
include_once($php);
}
}
class Dummy {
# constants
const ID = 'dummy';
const NAME = 'Dummy Plugin';
const VERSION = '1.0';
const AUTHOR = 'Author';
const URL = 'http://';
const DESC = 'Description';
const PAGE = 'plugins';
const SIDEBAR = 'Dummy Settings';
# properties
private $admin;
private $display;
# methods
// constructor
public function __construct() {
// initialize objects
$this->admin = new DummyAdmin;
$this->display = new DummyDisplay;
// ...
}
// display (front-end)
public function display() {
// load essential globals for changing the 404 error messages
global $id, $data_index;
// ...
}
// admin panel (back-end)
public function admin() {
// ...
}
}
?>
Main PHP file
Custom template displays