Site in read-only mode
This site is now read-only following the release of MyBB 1.8 and the new mods site.
If you are looking for MyBB 1.8 mods please click here to visit the new mods site.
You can continue to download submissions for MyBB 1.6 and earlier here, however new submissions will only be accepted via the new mods site.
Getting Started with Plugins
A tutorial to get you started in making plugins for MyBB.
Introduction
In this tutorial, we'll take a look at the coding behind a plugin, and get
to work on creating your own.
Requirements
- Some Knowledge of PHP
- The latest version of MyBB
- An editor (NotePad works just fine)
Basics of a Plugin
A plugin file in MyBB generally has the following functions:
- FILENAME_info()
- FILENAME_activate()
- FILENAME_deactivate()
(FILENAME is the name of the file). People sometimes need to add other
functions to the file for the plugin to work, but a plugin file pretty much
always have those functions.
FILENAME_info()
This function returns info about the plugin, inluding the plugin name, the
author, and the current version of the plugin.
FILENAME_activate()
This function runs when the plugin is activated in the Admin CP. Some
plugins have nothing in this function, while some do things like create a
MySQL table, or edit a template here.
FILENAME_deactivate()
This function runs when the plugin is deactivated in the Admin CP. If the
above function is empty, then this will most likely be empty also. In
tables were created, or if templates were edited, they will be either
deleted, or reverted to the originals.
Creating the Plugin
Okay, so you know what the basic functions are that a plugin requires. Now,
you\'re just itchin\' to make your own. But what's the exact coding that
needs to be added?
At the beginning of the page, it is a good idea to comment in some
copyright info, such as the author, version number, and creation date.
<?php
/**
@ Author: LegosJedi
@ Created: 04/09/07
@ Version: 1.0
@ Contact: [email protected]
*/
?>
Some people also include code that would prevent people from loading the
file right in their browser. To do this, add something like this:
<?php
if(!defined("IN_MYBB"))
{
die("You cannot directly access this file.");
}
?>
FILENAME_info()
<?php
function modcp_info()
{
return array(
"name" => "PLUGIN NAME",
"description" => "PLUGIN DESCRIPTION",
"website" => "PLUGIN WEBSITE",
"author" => "AUTHOR",
"authorsite" => "AUTHOR WEBSITE",
"version" => "VERSION NUMBER",
);
}
?>
The other two functions can have pretty much whatever you want to put into
them that makes the plugin work.
Hooks
Sometimes, you need to edit pages to get your plugin to work. One of the
great things with MyBB is their hooks system. Basically, it works like
this:
On pretty much every page, there is code that runs functions associated
with a certain phrase. By adding a piece of code that adds a function to
that phrase, that function will run with all the other functions that are
run by that phrase.
Adding Hooks
To add a hook to a phrase, you need to insert a piece of code that looks
something like this (Taken from the MyBB "Hello World" plugin):
<?php
$plugins->add_hook("pre_output_page", "hello_world");
?>
Now, in the plugin file, there should be a function called 'hello_world'.
It will be executed when the functions associated with that pharse are run
(For a full list of hooks, check here).
Conclusion
That should help you start writing your own plugin for MyBB. If you have
any questions about this tutorial, feel free to contact me at the MyBB Community Forums, or at the MyBB Mods Community Forums.
Copyright Info
This tutorial is copyright 2007 - present LegosJedi. You may not post this
tutorial anywhere else without the author's permission.