WPDK
1.5.0
WordPress Development Kit
|
Public Member Functions | |
wpdk_preferences_feedback_reset () | |
Feedback. More... | |
wpdk_preferences_feedback_update () | |
Feedback. More... | |
get () | |
Get preferences from store. More... | |
defaults () | |
Defaults. More... | |
delta () | |
Delta (align) object. More... | |
update () | |
Update. More... | |
delete () | |
Delete. More... | |
Data Fields | |
$name | |
Preferences name. More... | |
$version | |
Version. More... | |
$user_id | |
User ID. More... | |
Protected Member Functions | |
__construct ($name, $user_id=false) | |
Construct. More... | |
This class make easy plugin options management. In WPDK the plugin options are called preferences. We likes use preferences term more that options. So is made the WPDKPreferences class.
You rarely (never) instantiate WPDKPreferences object directly. Instead, you instantiate subclasses of the WPDKPreferences class.
Write a your own custom class and extends WPDKPreferences. For example:
class MyPreferences extends WPDKPreferences { }
Implements your custom properties and your branch to other configuration
class MyPreferences extends WPDKPreferences { const PREFERENCES_NAME = 'my-preferences'; public $version = '1.0.0'; public function __construct() { parent::__construct( self::PREFERENCES_NAME ); } }
You can implement this utility static method to get the configuration from database or create it onfly if missing or the first time.
class MyPreferences extends WPDKPreferences { const PREFERENCES_NAME = 'my-preferences'; public $version = '1.0.0'; public static function init() { return parent::init( self::PREFERENCES_NAME, __CLASS__ ); } }
If you have a preferences branch, or subset of preferences, use:
class MyPreferences extends WPDKPreferences { const PREFERENCES_NAME = 'my-preferences'; public $version = '1.0.0'; // My configuration branch public $branch; public static function init() { return parent::init( self::PREFERENCES_NAME, __CLASS__ ); } public function defaults() { $this->branch = new MyBranch(); } } class MyBranch extends WPDKPreferencesBranch { const NUMBER_OF_SEAT = 'number_of_seat'; public $number_of_seat; public function defaults() { $this->number_of_seat = 10; // Default value } public function update() { $this->number_of_seat = $_POST[self::NUMBER_OF_SEAT]; } }
Definition at line 90 of file wpdk-preferences.php.
|
protected |
Construct.
Return an instance of WPDKPreferences class
string | $name | A string used as name for options. Make it unique more possible. |
bool | int | $user_id | Optional. User ID |
Definition at line 231 of file wpdk-preferences.php.
defaults | ( | ) |
Defaults.
Override this method to set the defaults values for this preferences
Definition at line 280 of file wpdk-preferences.php.
delete | ( | ) |
delta | ( | ) |
Delta (align) object.
Do a delta compare/combine from two tree object config
Definition at line 292 of file wpdk-preferences.php.
get | ( | ) |
Get preferences from store.
Helper to get the preferences from global options or for single users.
Definition at line 269 of file wpdk-preferences.php.
update | ( | ) |
wpdk_preferences_feedback_reset | ( | ) |
wpdk_preferences_feedback_update | ( | ) |
string $name |
Preferences name.
Name used in WordPress option save
Definition at line 99 of file wpdk-preferences.php.
int $user_id |
User ID.
Used to store the preferences for user
Definition at line 117 of file wpdk-preferences.php.
string $version |