Merge pull request #13394 from woocommerce/feature-13393-support-custom-data-store-instances

Allow use of a specific instance of a data store
This commit is contained in:
Mike Jolley 2017-02-28 20:46:56 +00:00 committed by GitHub
commit c99f56d075
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' ) );
}