PHP Class WPDKConfiguration

## Overview You rarely (never) instantiate WPDKConfiguration object directly. Instead, you instantiate subclasses of the WPDKConfiguration class. ### Getting started Write a your own custom class and extends WPDKConfiguration. For example: class MySettings extends WPDKConfiguration { } Implements your custom properties and your branch to other configuration class MySettings extends WPDKConfiguration { const CONFIGURATION_NAME = 'mysetting-config'; public $version = '1.0'; function __construct() { parent::__construct( self::CONFIGURATION_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 MySettings extends WPDKConfiguration { const CONFIGURATION_NAME = 'mysetting-config'; public $version = '1.0'; static function init() { return parent::init( self::CONFIGURATION_NAME, __CLASS__ ); } function __construct() { parent::__construct( self::CONFIGURATION_NAME ); } } If you have a sub configuration branch, or subset of configuration, use: class MySettings extends WPDKConfiguration { const CONFIGURATION_NAME = 'mysetting-config'; public $version = '1.0'; My configuration branch public $branch; static function init() { return parent::init( self::CONFIGURATION_NAME, __CLASS__ ); } function __construct() { parent::__construct( self::CONFIGURATION_NAME ); $this->branch = new MyConfigurationBranch(); } } class MyConfigurationBranch { public $number_of_seat; function __construct() { $this->number_of_seat = 10; // Default value } } ### Reset to default values The code above shows how it possible reset all or a portion of your configuration. To reset a branch to default values just: $myconfiguration->branch = new MyConfigurationBranch(); If you like it possible implement a simple resetToDefault() method as: class MyConfigurationBranch { public $number_of_seat; function __construct() { $this->resetToDefault(); } function resetToDefault() { $this->number_of_seat = 10; // Default value } } ### Developing When you are in develop your settings change and the store object on db could be different from last develop version. No problem, you can invoke the delta() method to perform a delta from the database version and the onfly (last) version. This method usually is called on activation of plugin. In this way you can align the configuration setting just deactive and re active your plugin.
Deprecation: since 1.2.0 use WPDKPreferences instead
Since: 0.6.2
Author: =undo= ([email protected])
Afficher le fichier Open project: wpxtreme/wpdk Class Usage Examples

Méthodes publiques

Méthode Description
delete ( ) Delete this configuration
delta ( ) : object Do a delta compare/combine from two tree object config
init ( ) public static function init( $name = null, $class_name = null ) {
update ( ) Update on database this configuration.

Méthodes protégées

Méthode Description
__construct ( string $name ) Return an instance of WPDKConfiguration class

Method Details

__construct() protected méthode

Return an instance of WPDKConfiguration class
protected __construct ( string $name )
$name string A string used as name for options. Make it unique more possible.

delete() public méthode

Delete this configuration
public delete ( )

delta() public méthode

Do a delta compare/combine from two tree object config
public delta ( ) : object
Résultat object

init() public static méthode

public static function init( $name = null, $class_name = null ) {
public static init ( )

update() public méthode

Update on database this configuration.
public update ( )