Allow use of a specific instance of a data store

fixes #13393
This commit is contained in:
Michael Pretty 2017-02-28 15:01:06 -05:00
parent 8951bef0ee
commit 63dca2393c
1 changed files with 12 additions and 4 deletions

View File

@ -71,11 +71,19 @@ class WC_Data_Store {
if ( array_key_exists( $object_type, $this->stores ) ) {
$store = apply_filters( 'woocommerce_' . $object_type . '_data_store', $this->stores[ $object_type ] );
if ( ! class_exists( $store ) ) {
throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
if ( is_object( $store ) ) {
if ( ! class_implements( $store, WC_Object_Data_Store_Interface::class ) ) {
throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
}
$this->current_class_name = get_class( $store );
$this->instance = $store;
} else {
if ( ! class_exists( $store ) ) {
throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
}
$this->current_class_name = $store;
$this->instance = new $store;
}
$this->current_class_name = $store;
$this->instance = new $store;
} else {
throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
}