Add options per forum
What this is
This guide will teach you to use the hooks system to add options to your admincp/forum.php page. One finished, you will be able to add new options to your forum with just a few lines of code. Don't understand? Ever wanted to turn something on, but only in one of your forums? For example, lets say you want to execute code, but only in forum I.D. 2, 16, and 45. Lets begin! In this tutorial we will assume that you want a yes or no option; in order to enable/disable some code. In order to do that we first need to create a new row in the database. This will hold the information of which forums will be enabled/disabled. Always remember that '1' is considered as on, or enabled. And that '0' is considered off, or disabled. Please make sure this is all done on a test forum! We have to store the data! Run this SQL Query: [sql] ALTER TABLE forum ADD ( var smallint(3) unsigned not null default '' ) [/sql] Var = The name of the row in the database. This should be a name that will describe your system in one word. For example. In my vB Category Icons hack. This row is named 'forumhomeicon' Now that we have added our new row named 'var'. We now have to add the on/off option in the forums manager area of the admin control panel. Add the option in the ACP To add this new option in the ACP we need to create a new hook and add some code to that hook. The hook name should be: forumadmin_edit_form And the code should be: PHP Code:
That will actually add the yes/no row to all your forums in the admincp. So when you click on the save button, it will add your selection to the database. But how does it know which row to add it to? Glad you asked. You have to create one more hook! The hook name should be: forumdata_start And the code to add there is the following PHP Code:
I want to add more then just one option! Then you will need to repeat this tutorial for each option you would like to have. Now that you have saved both hooks. You can now use the following code in any of your hooks. PHP Code:
HTML Code:
<if condition="$foruminfo['var'] == 1"> If you have 2 or more options being added to the forums, you can place all the code in each hook. For example: Hookname: forumadmin_edit_form Code: PHP Code:
Code: PHP Code:
Custom Fields The following fields can also be used. PHP Code:
PHP Code:
PHP Code:
This tutorial was created for a member who needed to know how to do this exact thing, so I figured I would teach everyone. :p |
There is actually an easier way:
Just add a new bit to the $_FORUMOPTIONS array and you are there. Why alter the database? |
Quote:
|
Using existing Bitfields is bad coding style ;)
This will cause problems sooner or later when Jelsoft starts to use further Bits. Furthermore, $_FORUMOPTIONS doesn't even exist in vBulletin 3.5 And as it is possible not to use forumoptions here, it should be encouraged to do so (eg. use custom fields). This is official Jelsoft stance regarding Bitfields. |
Thanks for clearing that up Andreas. I thought the way I was doing it was incorrect for a min.
|
Nope, it's absolutely correct - but you might want to point out that if you are adding a bunch of Yes/No type settings, it could be a good idea to introduce a custom bitfield :)
|
Quote:
|
Quote:
Quote:
Quote:
Quote:
Quote:
|
When i said incorrect, I meant not to your coding standards. ;)
|
Quote:
It is bad, as (in contrary to custom tables/colums/variables) using default vBulletin Bitfields for custom settings will cause Problems. Wort Case scenario: Your Hack uses the next available Bit in forumoptions for "Show Quick Stats for this Forum". Now the next vBulletin Version comes and redifines this Bit to "Prune this Forum every 24 hours". Now all users of this Hack have the Bit set ... Quote:
It adds a record to Table profilefield and alters table userfield to have a new MEDIUMTEXT columd fieldxx. This is just an easy-to-use frontend to alter the Database, so where is the difference? Keeping the Product Manager in mind, such DB alterations can be done easily, without the User having to know anything about running queries. |
All times are GMT. The time now is 04:12 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|