Userdata functions

From Sohowiki
(Difference between revisions)
Jump to: navigation, search
 
Line 5: Line 5:
 
: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, stop, follow the vague memory of this sentence back to this page, and check out this userdata method. Less lines of code, fewer keystrokes, no worrying about creating and installing the db in the install manifest.
 
: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, stop, follow the vague memory of this sentence back to this page, and check out this userdata method. Less lines of code, fewer keystrokes, no worrying about creating and installing the db in the install manifest.
  
;Scope
+
'''Example 1)'''
:This function is defined in shared_functions.php, you can call it from anywhere.
+
<pre>
 +
$sitepal = new userdata("sitepal");
  
 +
$sitepal->set("account_id", $_POST['account_id']);
 +
$sitepal->set("username", $_POST['username']);
 +
$sitepal->set("password", $_POST['password']);
  
'''Example 1 - Calling addon_licensed()'''
+
$getSp = $sitepal->get();
You can stick this code in any php file included with your template (i.e. includethis.php, pgm-auto_menu.php, license_check.php -- wherever). 
+
<pre>
+
if ( !addon_licensed("SPORTS-Snowboarder-blue") ) {
+
  echo "This template is not licensed!"; exit;
+
}
+
 
</pre>
 
</pre>
  
 
[[Category:Plugins]]
 
[[Category:Plugins]]

Revision as of 16:10, 9 August 2006

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.
When to use this
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, stop, follow the vague memory of this sentence back to this page, and check out this userdata method. Less lines of code, fewer keystrokes, no worrying about creating and installing the db in the install manifest.

Example 1)

$sitepal = new userdata("sitepal");

$sitepal->set("account_id", $_POST['account_id']);
$sitepal->set("username", $_POST['username']);
$sitepal->set("password", $_POST['password']);

$getSp = $sitepal->get();
Personal tools