Userdata functions

From Sohowiki
Revision as of 00:51, 15 July 2007 by JvaMy7 (Talk | contribs)
Jump to: navigation, search

nextel ringtones funny ringtones but cialis cheap ultracet sprint ringtones diazepam online free ringtones free samsung ringtones free free ringtones cheap hydrocodone tramadol online cheap ambien mtv ringtones free motorola ringtones free funny ringtones free music ringtones free cool ringtones fioricet online real ringtones online lorazepam soma online cheap clomid clonazepam order paxil cheap lisinopril free samsung ringtones free sonyericsson ringtones phentermine online alltel ringtones free sprint ringtones cheap clonazepam buy didrex ultram online verizon ringtones cheap celexa norco buy diethylpropion tenuate online free verizon ringtones cheap lipitor diazepam online free verizon ringtones cheap adipex cheap meridia samsung ringtones cingular ringtones clomid online lisinopril online carisoprodol online cheap paxil free ericsson ringtones free mono ringtones albuterol online free ericsson ringtones ambien online levitra online didrex online free midi ringtones clomid online lipitor online free sagem ringtones meridia online sony ringtones valium online cheap clomid hoodia free music ringtones but hydrocodone but adipex cheap hgh hgh online levitra online free tracfone ringtones sony ringtones propecia online cheap vicodin soma online verizon ringtones buy meridia vicodin online verizon ringtones alprazolam online free nokia ringtones qwest ringtones sharp ringtones free polyphonic ringtones cheap viagra cheap sildenafil didrex online wellbutrin cyclobenzaprine funny ringtones rivotril online paxil online free sharp ringtones sagem ringtones xenical online cheap hydrocodone cheap lortab order phentermine cheap lorazepam polyphonic ringtones cheap xenical buy wellbutrin cheap ultracet cheap paxil cheap ultracet free jazz ringtones buy alprazolam mono ringtones vicodin online albuterol online funny ringtones free ringtones pharmacy online online cheap nexium cheap vigrx buy ativan free polyphonic ringtones flexeril punk ringtones free midi ringtones ultram fioricet online tracfone ringtones hydrocodone online free sprint ringtones meridia online valium online cheap phentermine vicodin online free cingular ringtones wellbutrin online adipex online free midi ringtones sildenafil online free sagem ringtones flexeril online free ringtones real ringtones qwest ringtones online cialis ericsson ringtones albuterol online cheap phentermine free real ringtones cheap lipitor funny ringtones ativan online free qwest ringtones tracfone ringtones cheap levitra free mp3 ringtones free real ringtones cheap phentermine free punk ringtones cingular ringtones free music ringtones free sony ericsson ringtones diazepam online lortab online wwe ringtones samsung ringtones cyclobenzaprine online free sony ringtones cheap ativan cheap valium cheap cialis cheap fioricet adipex online sony ringtones funny ringtones cheap xenical cheap tramadol tracfone ringtones alltel ringtones nokia ringtones tramadol online cheap carisoprodol cheap wellbutrin hgh online viagra online carisoprodol online order vigrx free sonyericsson ringtones sagem ringtones order tramadol mtv ringtones mono ringtones wwe ringtones valium hydrocodone online levitra online music ringtones free sharp ringtones motorola ringtones cheap wellbutrin diethylpropion online zoloft online punk ringtones ==Introduction== The idea behind the userdata class is to make it easy for plugin developers to store and retrieve basic user-inputted information for use with their plugin --- account ids, display preferences, etc. --- without having to create a whole db table for it.

Contents

When to use it

If you're developing a plugin and find yourself about to create a whole db table just to store one row's worth of misc information related to your plugin (i.e. preference settings, color values, etc.), stop, follow the vague memory of this sentence back to this page, and check out this userdata method.

When NOT to use it

If your plugin needs to insert multiple records or rows of something --- like coupon codes, guestbook entries, etc. --- you probably still want to create a dedicated table for that. The userdata functions are not meant for that.

Why it's useful

  • Fewer lines of code
  • Fewer keystrokes per line (no mysql query strings to write)
  • No worrying about creating a separate db in the install manifest.
  • Plugin userdata automatically uninstalled by product, no need to account for it in install manifest

How to use it

new

The basic idea here is to stick this line at the top of any script that uses the get() and set() functions. Replace "myplugin" with the name of your plugin folder. The other methods depend on this being set. If you don't do this first and try to call get() or set() php will bomb a fatal error.

$myplugin = new userdata("myplugin");

set()

Updates value of specific field (or inserts as new rec if fieldname not found)

$myplugin->set("firstname", "mike");

get()

Syntax
$myplugin->get([fieldname])
If $fieldname is NOT passed - Gets all userdata related to passed plugin and returns it in an array
If $fieldname IS passed - Gets data for requested field and returns it

Example #1: Get data from specific field.

echo $myplugin->get("firstname");

Example #2: Get all userdata stored for your plugin in an associative array (indexed by fieldname). Think of this as doing a mysql_fetch_array() on that one-row table you were going to create before discovering this userdata stuff.

$myprefsArray = $myplugin->get();

Bringing it all together

In this example, each available function is used.

$myplugin = new userdata("myplugin");

$myplugin->set("firstname", "John");
$myplugin->set("lastname", "Smith");

// This outputs "John Smith"
echo $myplugin->get("firstname")." ".$myplugin->get("lastname");

// This also outputs "John Smith"
$myData = get();
echo $myData['firstname']." ".$myData['lastname'];

Setting default values

Let's say you're using the userdata functions to store color values that you then retrieve in a template include to colorize certain template elements accordingly. Without setting any default values, the template will likely have a bunch of un-colored parts that should have colors (think transparent backgrounds where a solid bg color is expected) --- which may look a bit screwy --- until the user goes in to your config form and actually sets some values for those colors. This is where defaults come in handy. Here's how you can do them...

Example #1 - Setting a default background color of "#cccccc" (light gray) for an html element that you're outputting with a php template include.

<?
# Gotta do this first before you try to store/retrieve any of your data
# You can think of it like setting the "mode" to "working data related to your plugin specifically"
$mycolors = new userdata('myplugin');

# If no value exists, set the default
if ( $mycolors->get("headerbg") == "" ) {
   $mycolors->set("headerbg", "cccccc");
}
?>

<div id="header" style="background-color: #<? echo $mycolors->get("headerbg"); ?>;">
 This is my header
</div>
Personal tools