Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Store Plugin Prefs
I want to store Plugin Prefs into the db, but I’m not sure where.
The albumpattern prefs are stored in txp_prefs whith id=1.
So the albumpattern prefs are delivered with get_prefs().
To store prefs in txp_prefs, is a good idea for ap, because it’s deeply connected with txp.
But is it a good idea for other plugins?
How about store it in txp_prefs with id != 1?
Is there any standard?
Offline
#2 2005-05-31 20:52:24
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Store Plugin Prefs
We were just discussing that a little while ago.
The basic gist of the discussion was this:
“Insert a new record, and get_prefs() will automagically turn it into a global. Just make sure you use a prefix on the name so it doesn’t clash with anything else.”
and this:
“A plugin can store things in the txp_prefs table. The option won’t be displayed on the prefs page (that form is hard-coded), but the data will stay. The ‘name’ field will be used as the name of a global variable.”
(See the example code posted by Alex — the last link.)
Alex said then: “I’m not entirely sure what the prefs_id field is for.”
There isn’t any kind of standard that I know of, other than the prefix on the name (like we already do for plugin names).
Offline
#3 2005-05-31 22:45:53
- Andrew
- Plugin Author
- Registered: 2004-02-23
- Posts: 730
Re: Store Plugin Prefs
I’m still uneasy about this method. Seems like time combined with a heavily plugin’d site will lead toward a bunch of old crufty plugin values — all with different standards — laying around in that table. Oh well, better than nothing I suppose.
Offline
#4 2005-06-01 00:51:40
- zem
- Developer Emeritus
- From: Melbourne, Australia
- Registered: 2004-04-08
- Posts: 2,579
Re: Store Plugin Prefs
Though it’s not used yet, there was a ‘type’ field added to the prefs table a few weeks or so back. That’s intended for distinguishing between regular, admin and plugin config values.
Alex
Offline
Re: Store Plugin Prefs
I’m finding the preferences table very limiting. I want to have different data types, and not be limited to just one value per row.
I have a number of yet unreleased plugins which actually create their own table if it doesn’t exist. I know this is far from ideal as I’m sure people will point out. I myself wouldn’t want plugins creating tables with me not knowing about and why first.
I’m undecided as to when to release these plugins – should I wait for a better solution? Or just use a disclaimer which shows before creating any tables – giving the user a choice.
Offline
Re: Store Plugin Prefs
You could always store multiple values in a row by serializing an array and storing that.
Offline
Re: Store Plugin Prefs
Thanks wilshire, I didn’t think of that.
Limits to a data length of 255 so still it’s not a ideal solution. But it would be possible to spread data over multiply rows. Extra work for plugin developers but much nicer for the end user.
Offline
Re: Store Plugin Prefs
Thank you all for the quick response!
Offline
Re: Store Plugin Prefs
I wrote a plugin (which I haven’t released yet) based on Matt Mullenweg’s Firefox Counter. After I examined his code, I noticed WordPress seems to offer the following capability:
<code>update_option(‘firefox_counter’, $count);</code>
Which can be recalled with:
<code>get_option(‘firefox_counter’)</code>
Something like this would seem to be what everyone is looking for.
Offline
#10 2005-06-01 21:17:42
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Store Plugin Prefs
Just a repeat of the discussion there.
Alex said he was going to look at how to allow much larger settings, and it was mentioned using forms, and giving forms some kind of “admin” or plugin” attribute to differentiate from other forms.
(Disclaimer: In a nut-shell, that’s what I remember, but I may have interpreted incorrectly, and also there were no promises or anything made, just letting know that the situation was being considered.)
Offline
Re: Store Plugin Prefs
If anyone is interested I used the plugin preferences table to store a few setting in the rss_live_archive plugin. The plugin includes an admin interface for updating and saving the settings.
Offline
Pages: 1