dhfola
Junior Member
Posts: 30
Joined: Oct 2008
Reputation: 0
|
Creating a MyBB Plugin
Its Basic making plugins but you gotta know how.
This is a basic tutorial.
lets start. Create a new file in inc/plugins/yourpluginname.php.
now start by opening and closing PHP Tags, and add your copyright.
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ ?>
Its REALLY Important to add
PHP Code:
if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); }
So your file is
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); } ?>
Now lets add the plugin Info Function When making a plugin Make sure you use the file name lets say i named my file yourplugin.php.
PHP Code:
function yourplugin_info() { }
PHP Code:
return array( "name" => "", "description"=> "", "website" => "", "author" => "", "authorsite" => "", "version" => "", "guid" => "", "compatibility" => "" );
Name => The name of your Plugin eg. Your Plugin
Description => The Description Of Your Plugin eg. This Plugin Is a Test Plugin
Website => The Plugin Site eg. http://www.yoursite.com/YourPlugin
Author => Your Name eg. Dhfola
Author Site => Your Website eg. http://www.yoursite.com/
Version => The Plugin Of Your Plugin eg. 1.0
GUID => This is for Version Checking. You Get It From MyBB Mods Site. This can be blank, No Example
Compatibility => The Version Of MyBB It Is Compatible with. eg *
So Now you know how to fill this out. Add To the file in yourplugin_info
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); }
function yourplugin_info() { return array( "name" => "YourPlugin", "description"=> "This is a Example Plugin", "website" => "http://www.ismybb.info", "author" => "Dhfola", "authorsite" => "http://www.ismybb.info", "version" => "1.0", "guid" => "", "compatibility" => "*" ); } ?>
Easy? Well Now When the user activates the plugin this function will call.
PHP Code:
function yourplugin_activate() {
}
This is where we will add the DB's Settings Templates ect. We will add a Group Called YourPlugin and in the group there will be YourPlugin Enabled.
Really Easy to do that.
To Start
add
after the { line.
PHP Code:
function yourplugin_activate() { global $db; }
Then we make the new group in a array.
PHP Code:
$yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', );
Insert into DB
PHP Code:
$yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $db->insert_query('settinggroups', $yourplugin_group); $gid = $db->insert_id();
Now lets make a new setting.
PHP Code:
$yourplugin_setting = array( 'sid' => 'NULL', 'name' => 'enabled_yourplugin', 'title' => 'Do you want YourPlugin Enabled', 'description' => 'If Yes People Can Use YourPlugin, If No People Cannot Use YourPlugin.', 'optionscode' => 'yesno', 'value' => '1', 'disporder' => 1, 'gid' => intval($gid), );
Add It To The DB
PHP Code:
$db->insert_query('settings', $yourplugin_setting); rebuild_settings();
Thats Why We Need to global $db xD
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); }
function yourplugin_info() { return array( "name" => "YourPlugin", "description"=> "This is a Example Plugin", "website" => "http://www.ismybb.info", "author" => "Dhfola", "authorsite" => "http://www.ismybb.info", "version" => "1.0", "guid" => "", "compatibility" => "*" ); } function yourplugin_activate() { global $db; $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $db->insert_query('settinggroups', $yourplugin_group); $gid = $db->insert_id(); $yourplugin_setting = array( 'sid' => 'NULL', 'name' => 'enabled_yourplugin', 'title' => 'Do you want YourPlugin Enabled', 'description' => 'If Yes People Can Use YourPlugin, If No People Cannot Use YourPlugin.', 'optionscode' => 'yesno', 'value' => '1', 'disporder' => 1, 'gid' => intval($gid), ); $db->insert_query('settings', $yourplugin_setting); rebuild_settings(); } ?>
Looks Good. Check if it works if not post here.
We Gotta now to use Hooks
View Hooks.txt
To Use Hooks use this code:
PHP Code:
$plugins->add_hook("HOOK","FUNCTION");
For example. this hook will add text to the index_start hook.
PHP Code:
$plugins->add_hook("index_start","hello");
PHP Code:
function hello(){ global $mybb; if ($mybb->settings['enabled_yourplugin'] == 1){ echo "<center><h1>YourPlugin Works!</h1><br />Try To Disable The Plugin :) You'll See This Text Will Hide.."; } }
Ok Here is the code.
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); } //HOOKS GOES HERE BTW $plugins->add_hook("index_start","hello"); function yourplugin_info() { return array( "name" => "YourPlugin", "description"=> "This is a Example Plugin", "website" => "http://www.ismybb.info", "author" => "Dhfola", "authorsite" => "http://www.ismybb.info", "version" => "1.0", "guid" => "", "compatibility" => "*" ); } function yourplugin_activate() { global $db; $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $db->insert_query('settinggroups', $yourplugin_group); $gid = $db->insert_id(); $yourplugin_setting = array( 'sid' => 'NULL', 'name' => 'enabled_yourplugin', 'title' => 'Do you want YourPlugin Enabled', 'description' => 'If Yes People Can Use YourPlugin, If No People Cannot Use YourPlugin.', 'optionscode' => 'yesno', 'value' => '1', 'disporder' => 1, 'gid' => intval($gid), ); $db->insert_query('settings', $yourplugin_setting); rebuild_settings(); } function hello(){ global $mybb; if ($mybb->settings['enabled_yourplugin'] == 1){ echo "<center><h1>YourPlugin Works!</h1><br />Try To Disable The Plugin :) You'll See This Text Will Hide.."; } } ?>
Now all we need to is deactive this plugin
PHP Code:
function yourplugin_deactivate() { global $db; $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_yourplugin')"); $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='yourplugin'"); rebuild_settings(); }
Add it before the Hello Function
PHP Code:
<?php /** * YourPlugin 1.0 * © 2010 Dhfola * http://www.ismybb.info */ if(!defined("IN_MYBB")) { die("You Cannot Access This File Directly"); } //HOOKS GOES HERE BTW $plugins->add_hook("index_start","hello"); function yourplugin_info() { return array( "name" => "YourPlugin", "description"=> "This is a Example Plugin", "website" => "http://www.ismybb.info", "author" => "Dhfola", "authorsite" => "http://www.ismybb.info", "version" => "1.0", "guid" => "", "compatibility" => "*" ); } function yourplugin_activate() { global $db; $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $yourplugin_group = array( 'gid' => 'NULL', 'name' => 'yourplugin', 'title' => 'YourPlugin', 'description' => 'Settings For YourPlugin', 'disporder' => "1", 'isdefault' => 'no', ); $db->insert_query('settinggroups', $yourplugin_group); $gid = $db->insert_id(); $yourplugin_setting = array( 'sid' => 'NULL', 'name' => 'enabled_yourplugin', 'title' => 'Do you want YourPlugin Enabled', 'description' => 'If Yes People Can Use YourPlugin, If No People Cannot Use YourPlugin.', 'optionscode' => 'yesno', 'value' => '1', 'disporder' => 1, 'gid' => intval($gid), ); $db->insert_query('settings', $yourplugin_setting); rebuild_settings(); } function yourplugin_deactivate() { global $db; $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_yourplugin')"); $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='yourplugin'"); rebuild_settings(); } function hello(){ global $mybb; if ($mybb->settings['enabled_yourplugin'] == 1){ echo "<center><h1>YourPlugin Works!</h1><br />Try To Disable The Plugin :) You'll See This Text Will Hide.."; } } ?>
It Works
© Dhfola
|
|