MyBB Community Forums

Full Version: How do I create a plugin for 1.8?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
As per title, how do I create a plugin for 1.8? 
This is my really first time making a plugin for MyBB and I do not know even the basics.

Please explain me how to create one! 
This page is an excellent introduction for a complete beginner on creating MyBB plugins. Plugins are located in /inc/plugins, and follow a specific format with a few key components. Essentially, they work by "hooking" into various parts of the code. For example, if you are trying to add an announcement bar to your forum's header, you might go into "global_end" (end of global.php file) and add a "hook" for a "pluginname_announcement_bar" function. Once enabled, pluginname_announcement_bar() will be called at the end of global.php, which might then generate the template variable that contains the announcement bar's finalized HTML. (Template variables only need to be global variables in your code and they will be parsed when the template is parsed. )

Of course if you're generating template variables, you'll need to have the variables in the templates themselves. Plugins have a few essential functions for activation and deactivation where template edits can be done. The MyBB documentation website explains all of that pretty well.

Creating plugins is pretty simple once you get the hang of it, thanks to a great plugin system and the documentation that MyBB has provided on the documentation site. Big Grin
(2014-08-28, 01:17 PM)Darth Apple Wrote: [ -> ]This page is an excellent introduction for a complete beginner on creating MyBB plugins. Plugins are located in /inc/plugins, and follow a specific format with a few key components. Essentially, they work by "hooking" into various parts of the code. For example, if you are trying to add an announcement bar to your forum's header, you might go into "global_end" (end of global.php file) and add a "hook" for a "pluginname_announcement_bar" function. Once enabled, pluginname_announcement_bar() will be called at the end of global.php, which might then generate the template variable that contains the announcement bar's finalized HTML. (Template variables only need to be global variables in your code and they will be parsed when the template is parsed. )

Of course if you're generating template variables, you'll need to have the variables in the templates themselves. Plugins have a few essential functions for activation and deactivation where template edits can be done. The MyBB documentation website explains all of that pretty well.

Creating plugins is pretty simple once you get the hang of it, thanks to a great plugin system and the documentation that MyBB has provided on the documentation site. Big Grin
Thanks for your info. I must study a lot to create my own plugins. I'll start once 1.8 is officially released! 
You can start drafting even before (:
The best thing to do it to look at existing plugins and get an idea for how they work.

The thing people get most confused about is hooks, so as a brief rundown...

In the MyBB core code, you'll see things like this:

$plugins->run_hooks('global_start');

This runs all functions that plugins have bound to that hook. In your plugin file, you would have this:

$plugins->add_hook('global_start', 'my_function');

Then, in your file, you would define that function:

function my_function()
{
    // code
}

So, it basically says, when the MyBB code runs the global_start hook, run your function.

Like I say, have a look at some plugins to see this in action and you should get the hang of it Smile