-
Textpattern Plugin Preferences With set_pref
jake on 2008.01.23
at 02: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_prefis straightforward. The$nameand$valare simply the name of the variable for the database and the value of that variable.$eventis 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
$typevariable to2creates 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 to1nor 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
$typesetting. If you go into Admin->Preferences you’ll see Basic and Advanced tabs. The0and1are 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: Web · Programming

