Preventing the instance Data Store from being serialized with the containing WC_Data object

This commit is contained in:
Michael Pretty 2017-03-16 17:23:06 -04:00
parent adfd955194
commit 980500c353
1 changed files with 24 additions and 0 deletions

View File

@ -53,6 +53,13 @@ class WC_Data_Store {
*/
private $current_class_name = '';
/**
* The object type this store works with.
* @var string
*/
private $object_type = '';
/**
* Tells WC_Data_Store which object (coupon, product, order, etc)
* store we want to work with.
@ -60,6 +67,7 @@ class WC_Data_Store {
* @param string $object_type Name of object.
*/
public function __construct( $object_type ) {
$this->object_type = $object_type;
$this->stores = apply_filters( 'woocommerce_data_stores', $this->stores );
// If this object type can't be found, check to see if we can load one
@ -89,6 +97,22 @@ class WC_Data_Store {
}
}
/**
* Only store the object type to avoid serializing the data store instance
*
* @return array
*/
public function __sleep() {
return [ 'object_type' ];
}
/**
* Re-run the constructor with the object type
*/
public function __wakeup() {
$this->__construct( $this->object_type );
}
/**
* Loads a data store.
*