PDA

View Full Version : Change Default vB Settings via Custom Mod


Black Snow
10-02-2014, 01:36 PM
Hi,

Is it possible to create a new modification and use it to change settings that come in default vB?

For example:

If I create a mod for "Who has read a thread" that changes the CSS style etc, is it possible to enable/disable the "Who has read a thread" via this new mod without making new tables etc?

If so, how would I go about it?

kh99
10-02-2014, 01:45 PM
If I understand what you're asking, then yes, you can usually change vb settings in a plugin by resetting the value, if your plugin is at a hook location that gets called before the value is used. The settings values are in $vbulletin->options['setting_name']. You have to know 'setting_name' for the setting you want to change, of course. You can figure that out by looking at the code where it's used, or by hovering your cursor over the value in the admincp (I think you need to have the site in debug mode for that to work). You can also look at the html source for the settings page in the admin cp, if all else fails.

Black Snow
10-02-2014, 02:04 PM
Thanks for the reply. It's not a plugin I want to do it with (I don't think). When you go to admincp>options>settings, turn board on/off, there is an select option to turn the board online/offline. Is it possible to create an addon with that exact setting in it so I can turn the board on/off via my new mod in settings?

kh99
10-02-2014, 02:08 PM
No, you wouldn't be able to add that exact setting to your mod. But you could add a setting to your mod and use the same text as the vb setting so that it looks the same, then write a plugin that changes the vb setting depending on your mod's setting.

But maybe I still don't understand, because I don't see why you'd want your mod to have the same setting as one of the vb settings.

Black Snow
10-02-2014, 02:18 PM
There are some mods available that require certain settings to be enabled or disabled for the mod to work. For Example:

If I wanted to change how reputation was shown on postbit_legacy but I had the rep system turned off. I wanted to be able to make a mod with various options. Therefore I would have to enable the new rep mod, then go to the rep settings and enable the rep system.

I want to be able to turn it on/off and change my custom settings on the same page.

kh99
10-02-2014, 02:22 PM
OK, fair enough. What I mentioned above would actually be a way to override the default vb setting. If you want a setting that would mirror the vb setting (so that no matter which one the user changed, the other would change also), then I think it could be done but you need a plugin that runs when the settings are changed. If that's what you want, I don't know offhand how to do that but I think, Ozzy47 does.

Black Snow
10-02-2014, 02:26 PM
OK thanks. I see the variable for turning the board on/off is:

$vbulletin->options['bbactive'] but I can't for the life of me work out where it sends a request to change/store the option selected.

kh99
10-02-2014, 02:36 PM
In general I think it calls save_settings(), which is in includes/adminfunctions_options.php. If you were writing your own code to change the setting, you could just update the value in the settings table in the db, then call build_options(). If you want to do it in response to one of your mod options begin changed, then you need a plugin, maybe on one of the hooks in that function, I'm not sure.

I'd figure it out, but like I mentioned I believe Ozzy was just talking about something like this so I think he'll know off the top of his head.

Black Snow
10-02-2014, 02:43 PM
So I could just create a plugin and run an UPDATE sql command to change the setting from on to off and vice versa?

kh99
10-02-2014, 02:53 PM
Right. I haven't tried it, but I think you can use the save_settings() function like this:

include_once("includes/adminfunctions.php");
include_once("includes/adminfunctions_options.php");

save_settings(array('bbactive' => 0));

or if you just wanted to change the setting when your mod is installed, you could put that in your mod's install code (although I'm not sure that's what you'd want to do - some people might object to it).

Edit: On second thought, I'm not really very familiar with install code. It might be that wouldn't want to do it that way because build_options() might already get called when a product is installed. If that is what you want to do, I could check the product install code and see (unless someone else happens to know)

Black Snow
10-02-2014, 03:01 PM
So I could do this then to make it possibly easier:

include_once("includes/adminfunctions.php");
include_once("includes/adminfunctions_options.php");

if(new_mod_setting_board_offline){
save_settings(array('bbactive' => 0));
}
if(new_mod_setting_board_online){
save_settings(array('bbactive' => 1));
}


EDIT: No, I wouldn't want to do that as it would then run on all pages unless there's and option or a way to only run it when settings are saved, right?

kh99
10-02-2014, 04:31 PM
EDIT: No, I wouldn't want to do that as it would then run on all pages unless there's and option or a way to only run it when settings are saved, right?

Right. Sorry, I'm going to tell you a different thing once again. But if you want your mod to have a setting that always has the same value as another (bbactive, for example), then I think you might be able to create a plugin using hook admin_options_processing and code like this:

if ($oldsetting['varname'] == 'bbactive')
$settings['my_new_bbactive'] = $settings['bbactive'];
else if ($oldsetting['varname'] == 'my_new_bbactive')
$settings['bbactive'] = $settings['my_new_bbactive'];



so that is either one is changed, the other is set to the same value (of course you'd change my_new_bbactive to whatever the varname of your new setting actually is).

I guess with this code, if someone changed both at the same time and saved, I'm not sure what would happen. If you think that's a problem you might want to check if both values are in the $setting array and have one take precedence or something.

ozzy47
10-02-2014, 08:04 PM
I would not go around changing peoples settings they have set in the DB at all. I would just use this in my plugin.

$vbulletin->options['bbactive'] = '1';

Otherwise if I disable your mod, it would still leave my board active, the way you are doing it.