1. Textpattern Plugin Preferences With set_pref

    jake on 2008.01.23
    at 05:57 pm

    To 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 to 2 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 to 1 nor do I know if there are other possibilities. Please leave a comment if you can explain this further and help other developers.


    Thanks to Mary we now have clarification on the $type setting. If you go into Admin->Preferences you’ll see Basic and Advanced tabs. The 0 and 1 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 the 2 (hidden) setting makes the most sense.

    Posted in: Programming · Web


    Comments (2)

    1. Mary said on 2008.01.23 at 10:30 pm

      Here you are. :)

      0: “Basic”
      1: “Advanced”
      2: hidden

    2. jake said on 2008.01.24 at 12:08 am

      Thanks Mary! I’ll add the clarifications to the post.

    Comments have been automatically disabled to curtail spam.

by date

« May 2017 »
Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31