WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
WPDKPreferences Class Reference

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...
 

Detailed Description

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.

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];
  }
}
Author
=undo= info@.nosp@m.wpxt.nosp@m.re.me
Date
2013-08-20
Version
1.0.0
Since
1.2.0

Definition at line 90 of file wpdk-preferences.php.

Constructor & Destructor Documentation

__construct (   $name,
  $user_id = false 
)
protected

Construct.

Return an instance of WPDKPreferences class

Parameters
string$nameA string used as name for options. Make it unique more possible.
bool | int$user_idOptional. User ID

Definition at line 231 of file wpdk-preferences.php.

Member Function Documentation

defaults ( )

Defaults.

Override this method to set the defaults values for this preferences

Definition at line 280 of file wpdk-preferences.php.

delete ( )

Delete.

Delete this configuration

Definition at line 340 of file wpdk-preferences.php.

delta ( )

Delta (align) object.

Do a delta compare/combine from two tree object config

Returns
object

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.

Returns
WPDKPreferences

Definition at line 269 of file wpdk-preferences.php.

update ( )

Update.

Update on database this configuration.

Definition at line 325 of file wpdk-preferences.php.

wpdk_preferences_feedback_reset ( )

Feedback.

Restored feedback message

Definition at line 243 of file wpdk-preferences.php.

wpdk_preferences_feedback_update ( )

Feedback.

Updated feedback message

Definition at line 255 of file wpdk-preferences.php.

Field Documentation

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

Version.

Version of preferences

Definition at line 108 of file wpdk-preferences.php.


The documentation for this class was generated from the following file: