PHP Class WPDKPreferences

## Overview You rarely (never) instantiate WPDKPreferences object directly. Instead, you instantiate subclasses of the WPDKPreferences class. ### Getting started 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]; } }
Since: 1.2.0
Author: =undo= ([email protected])
Datei anzeigen Open project: wpxtreme/wpdk Class Usage Examples

Public Properties

Property Type Description
$name string Name used in WordPress option save
$user_id integer Used to store the preferences for user
$version string Version of preferences

Public Methods

Method Description
__construct ( string $name, boolean | integer $user_id = false ) Return an instance of WPDKPreferences class
defaults ( ) Override this method to set the defaults values for this preferences
delete ( ) Delete this configuration
delta ( ) : object Do a delta compare/combine from two tree object config
get ( ) : WPDKPreferences Helper to get the preferences from global options or for single users.
init ( ) : WPDKPreferences Return the preferences object from the option. If not exists then an object is create runtime for you.
update ( ) Update on database this configuration.
wpdk_preferences_feedback_reset ( ) Restored feedback message
wpdk_preferences_feedback_update ( ) Updated feedback message

Method Details

__construct() public method

Return an instance of WPDKPreferences class
public __construct ( string $name, boolean | integer $user_id = false )
$name string A string used as name for options. Make it unique more possible.
$user_id boolean | integer Optional. User ID

defaults() public method

Override this method to set the defaults values for this preferences
public defaults ( )

delete() public method

Delete this configuration
public delete ( )

delta() public method

Do a delta compare/combine from two tree object config
public delta ( ) : object
return object

get() public method

Helper to get the preferences from global options or for single users.
public get ( ) : WPDKPreferences
return WPDKPreferences

init() public static method

This is a utility method but you have to override if you don't like insert name and class name parameters. In you own class just use: public static function init() { return parent::init( self::PREFERENCES_NAME, __CLASS__ ); } Or, if you like check the prefernces version public static function init() { return parent::init( self::PREFERENCES_NAME, __CLASS__, LAST_VERSION ); } If you wish store preferences for each user use: public static function init() { $user_id = get_current_user_id(); return parent::init( self::PREFERENCES_NAME, __CLASS__, LAST_VERSION, $user_id ); }
public static init ( ) : WPDKPreferences
return WPDKPreferences

update() public method

Update on database this configuration.
public update ( )

wpdk_preferences_feedback_reset() public method

Restored feedback message

wpdk_preferences_feedback_update() public method

Updated feedback message

Property Details

$name public_oe property

Name used in WordPress option save
public string $name
return string

$user_id public_oe property

Used to store the preferences for user
public int $user_id
return integer

$version public_oe property

Version of preferences
public string $version
return string