Skip to content

Instantly share code, notes, and snippets.

@gocom
Created October 12, 2012 18:11
Show Gist options
  • Save gocom/3880618 to your computer and use it in GitHub Desktop.
Save gocom/3880618 to your computer and use it in GitHub Desktop.
An example Textpattern plugin with an updater
<?php
/**
* The plugin class.
*/
class abc_plugin
{
/**
* The plugin version.
*
* @var string
*/
static public $version = '1.2';
/**
* Constructor.
*/
public function __construct()
{
register_callback(array($this, 'install'), 'plugin_lifecycle.'.__CLASS__, 'installed');
register_callback(array($this, 'uninstall'), 'plugin_lifecycle.'.__CLASS__, 'deleted');
}
/**
* Installer.
*/
public function install()
{
$version = (string) get_pref(__CLASS__.'_version', '');
if (!$version)
{
// base install
}
if (version_compare($version, '1.1', '<'))
{
// update to 1.1
}
if (version_compare($version, '1.3', '<'))
{
// update to 1.3
}
// Write version number to database.
set_pref(__CLASS__.'_version', self::$version, __CLASS__, PREF_HIDDEN);
}
/**
* Uninstaller.
*/
public function uninstall()
{
safe_delete(
'txp_prefs',
"name LIKE '".str_replace('_', '\_', __CLASS__)."\_%'"
);
}
}
new abc_plugin();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment