Preventing the instance Data Store from being serialized with the containing WC_Data object
This commit is contained in:
parent
adfd955194
commit
980500c353
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue