MyBB Community Forums

Full Version: Plugin settings
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there some hook or method that allows you to define setting groups and settings for your plugin? Like an interface for plugins to interact with the Add New Setting, Add New Setting Group and Modify Settings dialogs.

If there isn't an easy hook for it, what would be the best way to do that using something like a SQL query?
admin_config_settings_begin
admin_config_settings_add
admin_config_settings_start

However, you can use the following function to directly add / insert an setting group with plugin file during activation / installation;
	$PLUGIN_group = array(
		"gid"			=> "NULL",
		"name"			=> "PLUGIN_SETTING_GROUP",
		"title" 		=> "SETTING_GROUP_NAME",
		"description"	=> "Settings for the plugin.",
		"disporder"		=> "1",
		"isdefault"		=> "no",
	);
	$db->insert_query("settinggroups", $PLUGIN_group);
	$gid = $db->insert_id();

Kindly note: This will add only "setting group". To add settings, you have to add another array of settings like;
	$PLUGIN_setting = array(
		"sid"			=> "NULL",
		"name"			=> "SETTING_NAME",
		"title"			=> "SETTING_NAME",
		"description"	=> "DESCRIPTIOn",
		"optionscode"	=> "yesno",
		"value"			=> "no",
		"disporder"		=> "1",
		"gid"			=> intval($gid),
	);

	$db->insert_query("settings", $PLUGIN_setting);
If you're asking about how to create a setting group and settings for your plugin; you currently have to do that manually using SQL queries. Which unfortunately leads to problems and errors just about everywhere. For example I don't like plugin groups just using disporder 1 for their groups.

I'm currently working on a plugin library which among other things allows you to create (and update) groups and settings. This code originally comes from my Google SEO plugin (which has several setting groups and a growing number of settings to manage, so the manual SQL approach would be bothersome).

/**
* SETTINGS
*
* $PL->settings(name, title, description, list)
*
* Create a setting group with any number of settings with $PL->settings()
* If the setting group already exists, the settings are updated properly.
*/
    $PL->settings("hello_pl", // group name and settings prefix
                  "Hello PluginLibrary!",
                  "Setting group for the Hello PluginLibrary sample plugin.",
                  array(
                      "foobar" => array(
                          "title" => "Foo Bar",
                          "description" => "The setting name depends on the prefix (hello_pl) and the key (foobar). The name of this setting is hello_pl_foobar.",
                          ),
                      "no" => array(
                          "title" => "Simple Yes/No setting",
                          "description" => "The default is no. The name of this setting is hello_pl_no.",
                          ),
                      "yes" => array(
                          "title" => "Yes/No setting",
                          "description" => "This one is set to yes. The name of this setting is hello_pl_yes.",
                          "value" => 1,
                          ),
                      "text" => array(
                          "title" => "Text setting",
                          "description" => "Give me a word. The name of this setting is hello_pl_text.",
                          "optionscode" => "text",
                          ),
                      "textarea" => array(
                          "title" => "Text area (hello_pl_textarea)",
                          "description" => "Multiple lines. The name of this setting is hello_pl_textarea.",
                          "optionscode" => "textarea",
                          "value" => "line1\nline2",
                          ),
                      )
                  // , true /* optional, prints a language file */
        );

Such a function should be in MyBB itself, unfortunately that isn't the case.
(2010-12-31, 03:47 AM)Yaldaram Wrote: [ -> ]admin_config_settings_begin
admin_config_settings_add
admin_config_settings_start

You can also embed PHP code or JavaScript in the setting itself. MyBB itself has some multiple choice settings that work like that, if I remember correctly when selecting smtp/php mail, it shows the smtp detail settings only when necessary. And this can be done without hooks...