Download Docs Forums


Developing Plugins

ExamplesVariablesSanitizingStoring DataInstall, RemoveJS LibTips

Plugins are an easy portable way to add functionality and keep changes in one spot. They're also easier for users to add and remove or re-add after an update.


Note in the examples below the value (Polls / poll) is the function name.

# PLUGIN - SITUATIONAL: Simple if statement.
if (THEO === 1) {
 echo 'Displays on front end.';
# PLUGIN - ADMIN PANEL: Use if admin settings.
$plugins[] = array('panel'=>'Polls');
function Polls() {
 echo 'Example Panel.';
# ADD-IN - ADDS INTO POST: Includes help (addinfo). Can pass options. Must use return.
$plugins[] = array('addin'=>'poll', 'addinfo'=>'poll(id)\nAdd a poll');
function poll($id = '') {
 return 'Example Add-In.';
$plugins[] = array('panel'=>'Polls', 'addin'=>'poll', 'addinfo'=>'poll(id)\nAdd a poll');
function Polls() {
 echo 'Example Panel.';
function poll($id = '') {
 return 'Example Add-In.';

Common Variables

You may need to use or store data in these variables (brought into function via global).

$D - Database connection.

$P - Table prefix.

$L - Language array.

$S - Site settings needed by front end.

$A - Admin settings never used on front end.

$R - Current row retrieved.

$U - Sanitized URL as string.

$UA - Sanitized URL as array.

$UT - Sanitized post title.

$head - Add (.=) meta tags, javascript or styling.

$mode - 1=Category, 2=Page, 3=Homepage, 4=Search/Tags, none=404.

Sanitizing Input

The clean() function escapes data for the database and includes a flag to sanitize visitor input.

# Admin Panel: Just use clean().
# Front End: Use with flag.
clean($var, 1);

Storing Data, Install, Remove

$S and $A store settings and load when the Site ($S) or Admin ($S and $A) loads. Other data should be stored in a new table or in the config table. If using the database, have an install / remove routine.

This example shows using $S, $A, a new table, and install / remove.

$plugins[] = array('panel'=>'Stats');
function Stats() {
 global $D, $P, $S, $A;
 # INSTALL if plugin setting doesn't exist. Install to $S, $A and create new table.
 if (!isset($S['st_skip'])) {
  $S['st_skip'] = 5;
  $A += array('st_topd'=>10, 'st_topn'=>5);
  mysqli_query($D,"UPDATE ".$P."cfgs a, ".$P."cfgs b
   WHERE a.cfg='site' AND b.cfg='admin'");
  mysqli_query($D,"CREATE TABLE ".$P."st_visits(id int unsigned auto_increment primary key)");
 # UNINSTALL if user clicks uninstall. Remove from $S, $A and remove table.
 } elseif (isset($_POST['uninstall'])) {
  unset($S['st_skip'], $A['st_topd'], $A['st_topn']);
  mysqli_query($D,"UPDATE ".$P."cfgs a, ".$P."cfgs b
   WHERE a.cfg='site' AND b.cfg='admin'");
  mysqli_query($D,"DROP TABLE ".$P."st_hits, ".$P."st_visits");

To uninstall an Add-In, use mysqli's string replace to remove it from posts.

Note: You may not need the database if you don't need data on load. Store settings in variables at the top of your function (or if statement) along with a comment directing users to set it.

Admin Javascript Library

Panels can use Theo's javascript, like toggle and highlighted save / confirm. This example uses all three.

echo '<a onclick="T(\'expand\')" style="cursor:pointer">Click To Expand</a>
<form method="post" onkeypress="S(1)" id="expand" style="display:none">
 <input type="text" value="" name="" />
 <input type="checkbox" onchange="S(1)" name="" />
 <input type="submit" value="Saved" id="1" name="" />
 <input type="button" onclick="R(\'rm\')" id="rm" value="Remove" name="" />


Check out existing plugins for other examples. Feel free to ask for help!

Please keep coding minimal and efficient. Code must be safe for use in production.

After posting, check back occasionally to answer user questions (subscribe to thread).

Make sure your code works after a Theo update, and update the plugin if needed.

Horizons Theme Powered By Theo CMS
© 2015-2019 Theo CMS - Ultra Light Content Management
Hi - one of your members has posted a ripped off copy of my CMS. Please see the license bundled with the download for restrictions on modifying and redistributing the code base. Please remove the content, thank you.