From a3e371e0d742ac94d900b62b522b0d429fd58539 Mon Sep 17 00:00:00 2001 From: Justin Stern Date: Wed, 9 Nov 2016 06:53:39 -0500 Subject: [PATCH] Make WooCommerce core play nice with Codeception (#11845) If is_blog_installed() is false then skip some installation steps that are performed on the 'init' action and which require the database to be available --- includes/class-wc-cache-helper.php | 5 +++++ includes/class-wc-install.php | 4 ++++ includes/class-wc-post-types.php | 10 ++++++++++ woocommerce.php | 5 +++++ 4 files changed, 24 insertions(+) diff --git a/includes/class-wc-cache-helper.php b/includes/class-wc-cache-helper.php index 0eec144b8f9..150fdd22f98 100644 --- a/includes/class-wc-cache-helper.php +++ b/includes/class-wc-cache-helper.php @@ -167,6 +167,11 @@ class WC_Cache_Helper { * Prevent caching on dynamic pages. */ public static function prevent_caching() { + + if ( ! is_blog_installed() ) { + return; + } + if ( false === ( $wc_page_uris = get_transient( 'woocommerce_cache_excluded_uris' ) ) ) { $wc_page_uris = array_filter( array_merge( self::get_page_uris( 'cart' ), self::get_page_uris( 'checkout' ), self::get_page_uris( 'myaccount' ) ) ); set_transient( 'woocommerce_cache_excluded_uris', $wc_page_uris ); diff --git a/includes/class-wc-install.php b/includes/class-wc-install.php index bd1238d80e4..ebe01cd2c9d 100644 --- a/includes/class-wc-install.php +++ b/includes/class-wc-install.php @@ -137,6 +137,10 @@ class WC_Install { public static function install() { global $wpdb; + if ( ! is_blog_installed() ) { + return; + } + if ( ! defined( 'WC_INSTALLING' ) ) { define( 'WC_INSTALLING', true ); } diff --git a/includes/class-wc-post-types.php b/includes/class-wc-post-types.php index 6a457bdfbfb..10fcc7b4a69 100644 --- a/includes/class-wc-post-types.php +++ b/includes/class-wc-post-types.php @@ -36,6 +36,11 @@ class WC_Post_types { * Register core taxonomies. */ public static function register_taxonomies() { + + if ( ! is_blog_installed() ) { + return; + } + if ( taxonomy_exists( 'product_type' ) ) { return; } @@ -226,6 +231,11 @@ class WC_Post_types { * Register core post types. */ public static function register_post_types() { + + if ( ! is_blog_installed() ) { + return; + } + if ( post_type_exists( 'product' ) ) { return; } diff --git a/woocommerce.php b/woocommerce.php index 70e06e83a22..7ea132e8cfc 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -476,6 +476,11 @@ final class WooCommerce { * @since 2.2 */ private function load_webhooks() { + + if ( ! is_blog_installed() ) { + return; + } + if ( false === ( $webhooks = get_transient( 'woocommerce_webhook_ids' ) ) ) { $webhooks = get_posts( array( 'fields' => 'ids',