-
Textpattern Plugin Preferences With set_pref
jake on 2008.01.23
at 05:57 pmTo insert preferences into the Textpattern database you use a function called
set_pref
. There is one area of the command that generated confusion while I was working on my latest plugin.set_pref($name, $val, $event, $type)
Most of the information you pass to
set_pref
is straightforward. The$name
and$val
are simply the name of the variable for the database and the value of that variable.$event
is what the preference is associated with, in this case the name of my plugin. But it’s harder to surmise the effect of$type
. And a search through Google and the Textpattern forums returns no explanation.Originally I copied another developer and set this value to
0
. While this works it also adds all the settings alphabetically to the main preferences tab. Because I already have a separate tab for my plugin (and this option adds clutter) having all the settings duplicated and unformatted is not ideal.Setting the
$type
variable to2
creates a hidden preference. No more list in the main preferences yet I can access the information. This is how my plugin is now set up.I have not made attempts to set the value to1
nor do I know if there are other possibilities. Please leave a comment if you can explain this further and help other developers.Update:
Thanks to Mary we now have clarification on the
$type
setting. If you go into Admin->Preferences you’ll see Basic and Advanced tabs. The0
and1
are to place preferences on these respective pages. The Basic tab is primarily for system settings. But the advanced can be used for a few, relevant options.In most circumstances managing the preferences on another page and using the2
(hidden) setting makes the most sense.Posted in: Programming · Web