As of MyBB 1.2.x, modules have been deprecated. Please use the plugin system
Contents |
Authoring modules for MyBB is like any other PHP undertaking. It will require some knowledge of PHP/MySQL and a decent knowledge of MyBB. The basis behind modules allows you to take advantage of the admin cp without having to edit files. In order to use modules you must apply a small amount of modifications to your forum, which can be found here
Note: The Actual file that the user interacts with should be named modulename.php (e.g. foo.php)
These things you MUST do within your module code:
- The names of the installation, uninstallation, and info functions MUST be the name of your file (minus the extention) + _install, _uninstall, or _info respectively. (e.g. foo_activate if your module filename is foo.php).
- The name of your installation file must have a _ (underscore) at the beginning. (e.g. _foo.php)
- You must also include a navigation file (e.g. foo.nav.php - More info: Modules Navigation) and a permissions file (e.g. foo.perms.php - More info: Modules Permissions)
// The information that shows up on the plugin manager
function pluginname_info()
{
return array(
"name" => "Module Name",
"description" => "Module Description",
"website" => "Module's Website",
"author" => "Your name",
"authorsite" => "Your website",
"version" => "Module Version",
);
}
// This function runs when the plugin is activated.
function pluginname_install()
{
global $db;
$install_module = array(
'eid' => NULL,
'module' => 'modulename',
'status' => 1,
);
$db->insert_query(TABLE_PREFIX.'emods', $install_module);
if ($db->num_rows($db->query("SHOW COLUMNS FROM `".TABLE_PREFIX."adminoptions` LIKE 'modulename'")) == 0)
{
$db->query("ALTER TABLE `".TABLE_PREFIX."adminoptions` ADD `modulename` CHAR(3) NOT NULL");
}
// Extra code goes here
echo "<script language=\"JavaScript\"> parent.nav.location.href = \"./index.php?action=navigation\"; </script>";
cpredirect('eMods.php', $lang->mod_installed);
}
// This function runs when the plugin is deactivated.
function modulename_uninstall()
{
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."emods WHERE module='modulename'");
if ($db->num_rows($db->query("SHOW COLUMNS FROM `".TABLE_PREFIX."adminoptions` LIKE 'modulename'");) == 1)
{
$db->query("ALTER TABLE `".TABLE_PREFIX."adminoptions` DROP COLUMN `modulename`");
}
echo "<script language=\"JavaScript\"> parent.nav.location.href = \"./index.php?action=navigation\"; </script>";
cpredirect('eMods.php', $lang->mod_uninstalled);
}
- Functions in your modules can be called anything you choose, but it is a good idea to prefix them with the name of your file (minus the extension) in order to avoid clashes with other modules. (ie. if your filename is _foo.php, name your plugin functions: foo_run or foo_bar, foo_foo, etc)