From 63dca2393cc7ef760325d53c59d2eeb81901d571 Mon Sep 17 00:00:00 2001 From: Michael Pretty Date: Tue, 28 Feb 2017 15:01:06 -0500 Subject: [PATCH] Allow use of a specific instance of a data store fixes #13393 --- includes/class-wc-data-store.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-data-store.php b/includes/class-wc-data-store.php index 6583dbbff43..ad8995388c1 100644 --- a/includes/class-wc-data-store.php +++ b/includes/class-wc-data-store.php @@ -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' ) ); }