MyBB Community Forums

Full Version: Change variable in settings.php?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How can I change a variable that exists in settings.php? 


Can I use find_replace_templatesets?
If so, how do I use it?
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?
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?
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.
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.