Posted on June 30th, 2007
6506 views
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 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 FILENAME_info() <?php 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 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. |