MyBB Community Forums
Change variable in settings.php? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Change variable in settings.php? (/thread-205519.html)



Change variable in settings.php? - CoolComfort - 2016-10-31

How can I change a variable that exists in settings.php? 


Can I use find_replace_templatesets?
If so, how do I use it?


RE: Change variable in settings.php? - Matt - 2016-10-31

I'm not really sure what you're asking, the settings.php file is automatically generated based on what's in the settings table, it's not something you change yourself as any changes you make will get removed as soon as you save settings in the ACP, and it's nothing to do with templates. What is is you're actually trying to do?


RE: Change variable in settings.php? - CoolComfort - 2016-10-31

Ah, so here's what I want to know. Can I create a new variable in settings through MySQL and have it appear in settings.php?


RE: Change variable in settings.php? - Matt - 2016-11-01

You can yes, plugins will typically add settings groups that contain settings for the plugin, then if you call rebuild_settings() it will re-generate the settings.php file

$settings_group = array(
	"name" => "myplugin",
	"title" => "My Plugin Settings",
	"description" => "Settings for my plugin.",
	"disporder" => "10",
	"isdefault" => 0
);
$db->insert_query("settinggroups", $settings_group);
$gid = $db->insert_id();

$insert = array(
	"name" => 'mysetting',
	"title" => 'My Setting',
	"description" => 'This setting does something cool',
	"optionscode" => 'yesno',
	"value" => 1,
	"disporder" => 1,
	"gid" => intval($gid),
);
$db->insert_query("settings", $insert);

rebuild_settings();

You could then use $mybb->settings['mysetting'] to access the value of that setting.


RE: Change variable in settings.php? - CoolComfort - 2016-11-02

Amazing! rebuild_settings is EXACTLY what I needed. What an amazing function this code does. I've never seen something store variables so easily, and I know if I ever start from scratch on a website I will use a function similar to this. What I was doing was removing the settings.php page everytime so it would automatically reupdate. What a huge waste of resources. Lol.