Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to write a MyBB Plugin Base
#1
>>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.

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.
Need website or forum help?
[Image: logo.png]
Reply
#2
Thanks for this... I'm interested in learning how to make a MyBB plugin... I will take this and learn from it. ^^
Reply
#3
Thanks a lot. I am learning PHP now. Just bookmarked your tutorial
Reply
#4
Indeed a very nice contribution to the forum. Keep it up.
Reply
#5
Hi, this is a very nice contribution to the forum but I have one problem, it's not PHP and MYSQL(UNLESS NEEDED BY PLUGIN) but I'll say you'll need to know MyBB coding, since that's quite different to PHP.
[Image: signaturera.png]
Reply
#6
(06-04-2011, 11:43 AM)Laughynose Wrote: Hi, this is a very nice contribution to the forum but I have one problem, it's not PHP and MYSQL(UNLESS NEEDED BY PLUGIN) but I'll say you'll need to know MyBB coding, since that's quite different to PHP.
True but you will need to know some PHP for functions and maybe SQL if you concider something big. But mybb has its own built in SQL class for use.
Need website or forum help?
[Image: logo.png]
Reply
#7
Yes, but MYSQL is not needed for every single plugin, a big majority yes.
[Image: signaturera.png]
Reply
#8
(06-04-2011, 12:04 PM)Laughynose Wrote: Yes, but MYSQL is not needed for every single plugin, a big majority yes.
Yeah, I'll take out the bit about SQL. The next tut I make will be about making a plugin that requires SQL.
Need website or forum help?
[Image: logo.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mybb Plugin Issue Rуan 1 1,061 07-14-2012, 06:25 PM
Last Post: 'Snorlax
  Tabbed Menu plugin error after upgrading to MyBB 1.6.6 RedKarma 2 1,189 03-03-2012, 01:03 PM
Last Post: BreShiE
  Wordpress flash plugin NekoChan 1 844 01-14-2012, 04:49 PM
Last Post: NekoChan
  [Help] How to add Snow Fall Plugin? Jinu 3 1,442 11-28-2011, 07:43 AM
Last Post: Jinu
  Problem with labroccas tabbed menu plugin HostMyPicture 17 2,262 08-14-2011, 12:39 AM
Last Post: FISH

Forum Jump:


Users browsing this thread: 1 Guest(s)