06-03-2011, 01:09 PM
>>To create a plugin you will need PHP and SQL knowledge.<<
Right first things first, to prevent any possible problems we only want our plugin to run when mybb runs it and to prevent users from running it directly.
This is just the array of info that will be displayed to the admin on the plugin managment page.
Right now we need the install function, This is what will happen when that admin clicks install in the plugin manager.
Just a side note some of the functions (ones that are <yourpluginname>_function) will require the name of your plugin file. So replace <yourpluginname> With the name of your php file (without .php).
Now incase your install function does anything you dont want being run twice, We need a function to stop them installing it twice without clicking uninstall.
Now we add the code for what happens when the plugin is activated (this should probably edit templates you need)
Now we add the deactivate and uninstall functions.
This is just the base, In my next tutorial I will Write about how to make the plugin do something and how to use mybb hooks & classes.
Right first things first, to prevent any possible problems we only want our plugin to run when mybb runs it and to prevent users from running it directly.
Code:
<?php
if(!defined("IN_MYBB")) die("Nou!"); //If not being run by MyBB display the text Nou! and cancel any further operations.
This is just the array of info that will be displayed to the admin on the plugin managment page.
Code:
function <yourpluginname>_info()
{
return array(
"name" => "MyFirstPlugin",
"description" => "My first go at writing a mybb plugin",
"website" => "http://yoursite.com/myfirstplugin/",
"author" => "My_name",
"authorsite" => "http://yoursite.com/",
"version" => "1",
);
}
Right now we need the install function, This is what will happen when that admin clicks install in the plugin manager.
Just a side note some of the functions (ones that are <yourpluginname>_function) will require the name of your plugin file. So replace <yourpluginname> With the name of your php file (without .php).
Code:
function <yourpluginname>_install()
{
//Code to install plugin
}
Now incase your install function does anything you dont want being run twice, We need a function to stop them installing it twice without clicking uninstall.
Code:
function <yourpluginname>_is_installed()
{
if(something = something) //Something to check if it's installed like if an SQL table you add in "<yourpluginname>_install" exists
{
return true; // Plugin is installed
}
return false; //Plugin is not installed
}
Now we add the code for what happens when the plugin is activated (this should probably edit templates you need)
Code:
function <yourpluginname>_activate()
{
//Code to activate plugin
}
Now we add the deactivate and uninstall functions.
Code:
function <yourpluginname>_deactivate()
{
//Generally the opposite of what activate does
}
function <yourpluginname>_uninstall()
{
//Generally the opposite of what install does
}?>
This is just the base, In my next tutorial I will Write about how to make the plugin do something and how to use mybb hooks & classes.