PHP Класс 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]; } }
С версии: 1.2.0
Автор: =undo= ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$name string Name used in WordPress option save
$user_id integer Used to store the preferences for user
$version string Version of preferences

Открытые методы

Метод Описание
__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

Описание методов

__construct() публичный Метод

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() публичный Метод

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

delete() публичный Метод

Delete this configuration
public delete ( )

delta() публичный Метод

Do a delta compare/combine from two tree object config
public delta ( ) : object
Результат object

get() публичный Метод

Helper to get the preferences from global options or for single users.
public get ( ) : WPDKPreferences
Результат WPDKPreferences

init() публичный статический Метод

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
Результат WPDKPreferences

update() публичный Метод

Update on database this configuration.
public update ( )

wpdk_preferences_feedback_reset() публичный Метод

Restored feedback message

wpdk_preferences_feedback_update() публичный Метод

Updated feedback message

Описание свойств

$name публичное свойство

Name used in WordPress option save
public string $name
Результат string

$user_id публичное свойство

Used to store the preferences for user
public int $user_id
Результат integer

$version публичное свойство

Version of preferences
public string $version
Результат string