Mar 10, 2007, 04:18 PM
You should start off with the basic plugin template.
Notations are in BLUE and need to be removed from final plugin product
RED text is areas that you will replace with your own information and variable for the plugin
This is explained well at the mybb wiki here:
http://wiki.mybboard.net/index.php/Authoring_Plugins
What is not explained well is exactly HOW to use the hooks and create a functioning plugin.
To add an admin setting to your plugin you first need to add a query array to your activation function.
Something like this is used to first create the "Settings Group"
(note the 88 is display order and you should create a number somewhere between 30 and 250 as sometimes mybb has a conflict here and a setting won't be displayed because of this)
Next the actual settings within the group are added to your activation function.
In the above example the first setting is an "enable/disable" query. The second is a setting for the plugin. Both of these I will explain how to use in a function. But first let's finish off the deactivation part of your plugin.
At this point your plugin will look like this:
Notations are in BLUE and need to be removed from final plugin product
RED text is areas that you will replace with your own information and variable for the plugin
Quote:// The information that shows up on the plugin manager
function pluginname_info()
{
return array(
"name" => "Plugin Name",
"description" => "Plugin Description",
"website" => "Plugin's Website",
"author" => "Your name",
"authorsite" => "Your website",
"version" => "Plugin Version",
);
}
// This function runs when the plugin is activated.
function pluginname_activate()
{
}
// This function runs when the plugin is deactivated.
function pluginname_deactivate()
{
}
This is explained well at the mybb wiki here:
http://wiki.mybboard.net/index.php/Authoring_Plugins
What is not explained well is exactly HOW to use the hooks and create a functioning plugin.
To add an admin setting to your plugin you first need to add a query array to your activation function.
Something like this is used to first create the "Settings Group"
Quote: require "../inc/adminfunctions_templates.php";
global $db, $mybb;
$GROUPNAME_group = array(
"gid" => "NULL",
"name" => "GROUPNAME",
"title" => "GROUP TITLE",
"description" => "GROUP DESCRIPTION",
"disporder" => "88",
"isdefault" => "no",
);
$db->insert_query(TABLE_PREFIX."settinggroups", $GROUPNAME_group);
$gid = $db->insert_id();
(note the 88 is display order and you should create a number somewhere between 30 and 250 as sometimes mybb has a conflict here and a setting won't be displayed because of this)
Next the actual settings within the group are added to your activation function.
Quote: $PLUGINNAME_setting_1 = array(
"sid" => "NULL",
"name" => "PLUGIN SETTING NAMEenable",
"title" => "Enable",
"description" => "Would you like to enable PLUGINNAME?",
"optionscode" => "yesno", Plugin types are "yesno"(radio button), "text"(single line), and "textarea".
"value" => "yes",
"disporder" => "1",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $PLUGINNAME_setting_1);
$PLUGINNAME _setting_2 = array(
"sid" => "NULL",
"name" => "PLUGIN SETTING NAME",
"title" => "PLUGIN TITLE",
"description" => "PLUGIN DESCRIPTION",
"optionscode" => "text",
"value" => PLUGIN VALUE",
"disporder" => "2",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $PLUGINNAME_setting_2);
In the above example the first setting is an "enable/disable" query. The second is a setting for the plugin. Both of these I will explain how to use in a function. But first let's finish off the deactivation part of your plugin.
Quote: require '../inc/adminfunctions_templates.php';
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('$PLUGIN SETTING NAME', '$PLUGIN SETTING NAME')");Here you will replace all your PLUGIN SETTING NAMES into this array
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='GROUPNAME'"); The groupname should be the same as the one created above in the activation
At this point your plugin will look like this:
Quote:// The information that shows up on the plugin manager
function pluginname_info()
{
return array(
"name" => "Plugin Name",
"description" => "Plugin Description",
"website" => "Plugin's Website",
"author" => "Your name",
"authorsite" => "Your website",
"version" => "Plugin Version",
);
}
// This function runs when the plugin is activated.
function pluginname_activate()
{
require "../inc/adminfunctions_templates.php";
global $db, $mybb;
$GROUPNAME_group = array(
"gid" => "NULL",
"name" => "GROUPNAME",
"title" => "GROUP TITLE",
"description" => "GROUP DESCRIPTION",
"disporder" => "88",
"isdefault" => "no",
);
$db->insert_query(TABLE_PREFIX."settinggroups", $GROUPNAME_group);
$gid = $db->insert_id();
$PLUGINNAME_setting_1 = array(
"sid" => "NULL",
"name" => "PLUGIN SETTING NAMEenable",
"title" => "Enable",
"description" => "Would you like to enable PLUGINNAME?",
"optionscode" => "yesno", Plugin types are "yesno"(radio button), "text"(single line), and "textarea".
"value" => "yes",
"disporder" => "1",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $PLUGINNAME_setting_1);
$PLUGINNAME _setting_2 = array(
"sid" => "NULL",
"name" => "PLUGIN SETTING NAME",
"title" => "PLUGIN TITLE",
"description" => "PLUGIN DESCRIPTION",
"optionscode" => "text",
"value" => PLUGIN VALUE",
"disporder" => "2",
"gid" => intval($gid),
);
$db->insert_query(TABLE_PREFIX."settings", $PLUGINNAME_setting_2);
}
// This function runs when the plugin is deactivated.
function pluginname_deactivate()
{
require '../inc/adminfunctions_templates.php';
global $db;
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('$PLUGIN SETTING NAME', '$PLUGIN SETTING NAME')");Here you will replace all your PLUGIN SETTING NAMES into this array
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='GROUPNAME'"); The groupname should be the same as the one created above in the activation
}